fix: set allow keyless when no public keys provided

Ayman Bagabas created

Change summary

internal/config/config.go   | 8 +++++++-
internal/config/defaults.go | 2 +-
internal/git/git.go         | 1 -
3 files changed, 8 insertions(+), 3 deletions(-)

Detailed changes

internal/config/config.go 🔗

@@ -97,7 +97,12 @@ func NewConfig(cfg *config.Config) (*Config, error) {
 	} else {
 		displayHost = host
 	}
-	yamlConfig := fmt.Sprintf(defaultConfig, displayHost, port, anonAccess)
+	yamlConfig := fmt.Sprintf(defaultConfig,
+		displayHost,
+		port,
+		anonAccess,
+		len(pks) == 0,
+	)
 	if len(pks) == 0 {
 		yamlUsers = defaultUserConfig
 	} else {
@@ -186,6 +191,7 @@ func (cfg *Config) createDefaultConfigRepo(yaml string) error {
 	rs := cfg.Source
 	err := rs.LoadRepo(cn)
 	if os.IsNotExist(err) {
+		log.Printf("creating default config repo %s", cn)
 		repo, err := ggit.PlainInit(rp, true)
 		if err != nil {
 			return err

internal/config/defaults.go 🔗

@@ -17,7 +17,7 @@ anon-access: %s
 
 # You can grant read-only access to users without private keys. Any password
 # will be accepted.
-allow-keyless: false
+allow-keyless: %t
 
 # Customize repo display in the menu.
 repos:

internal/git/git.go 🔗

@@ -201,7 +201,6 @@ func (rs *RepoSource) LoadRepo(name string) error {
 	rp := filepath.Join(rs.Path, name)
 	r, err := rs.open(rp)
 	if err != nil {
-		log.Printf("error opening repository %s: %s", name, err)
 		return err
 	}
 	rs.repos[name] = r