Skip to content

Commit 6960652

Browse files
committed
feat(config): improve Git fallback configuration and display
1 parent a420e40 commit 6960652

5 files changed

Lines changed: 44 additions & 16 deletions

File tree

internal/commands/config/set.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ func (c *ConfigCommandFactory) newSetCommand(t *i18n.Translations, cfg *config.C
9898
}
9999
case "active-vcs", "active_vcs":
100100
targetCfg.ActiveVCSProvider = value
101-
case "git-name":
101+
case "git.name", "git-name":
102102
targetCfg.GitFallback.UserName = value
103-
case "git-email":
103+
case "git.email", "git-email":
104104
targetCfg.GitFallback.UserEmail = value
105105
default:
106106
return fmt.Errorf("unknown configuration key: %s", key)

internal/commands/config/show.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ func (c *ConfigCommandFactory) newShowCommand(t *i18n.Translations, cfg *config.
6161
fmt.Println(t.GetMessage("config_models.no_ai_models_configured", 0, nil))
6262
}
6363

64+
if cfg.GitFallback.UserName != "" || cfg.GitFallback.UserEmail != "" {
65+
fmt.Println()
66+
fmt.Println(t.GetMessage("config_git.fallback_header", 0, nil))
67+
if cfg.GitFallback.UserName != "" {
68+
fmt.Printf("%s\n", t.GetMessage("config_git.fallback_name", 0, struct{ Name string }{cfg.GitFallback.UserName}))
69+
}
70+
if cfg.GitFallback.UserEmail != "" {
71+
fmt.Printf("%s\n", t.GetMessage("config_git.fallback_email", 0, struct{ Email string }{cfg.GitFallback.UserEmail}))
72+
}
73+
}
74+
6475
localPath := config.GetRepoConfigPath()
6576
if localPath != "" {
6677
localCfg, err := config.LoadConfig(localPath)
@@ -71,6 +82,17 @@ func (c *ConfigCommandFactory) newShowCommand(t *i18n.Translations, cfg *config.
7182
fmt.Printf("%s\n", t.GetMessage("language_label", 0, struct{ Lang string }{localCfg.Language}))
7283
fmt.Printf("%s\n", t.GetMessage("emojis_label", 0, struct{ Emoji bool }{localCfg.UseEmoji}))
7384
fmt.Printf("%s\n", t.GetMessage("config_models.active_ai_label", 0, struct{ IA config.AI }{localCfg.AIConfig.ActiveAI}))
85+
86+
if localCfg.GitFallback.UserName != "" || localCfg.GitFallback.UserEmail != "" {
87+
fmt.Println()
88+
fmt.Println(t.GetMessage("config_git.fallback_header", 0, nil))
89+
if localCfg.GitFallback.UserName != "" {
90+
fmt.Printf("%s\n", t.GetMessage("config_git.fallback_name", 0, struct{ Name string }{localCfg.GitFallback.UserName}))
91+
}
92+
if localCfg.GitFallback.UserEmail != "" {
93+
fmt.Printf("%s\n", t.GetMessage("config_git.fallback_email", 0, struct{ Email string }{localCfg.GitFallback.UserEmail}))
94+
}
95+
}
7496
}
7597
}
7698

internal/git/git_service.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,17 @@ func (s *GitService) ValidateGitConfig(ctx context.Context) error {
447447
return errors.ErrNotInGitRepo
448448
}
449449

450-
validate := func(key string, errType *errors.AppError) error {
450+
validate := func(key string, errType *errors.AppError, fallback string) error {
451451
cmd := exec.CommandContext(ctx, "git", "config", key)
452452
cmd.Dir = repoRoot
453453
output, err := cmd.Output()
454454
val := strings.TrimSpace(string(output))
455455

456456
if err != nil || val == "" {
457+
if fallback != "" {
458+
log.Info("git config not set, using fallback", "key", key, "fallback", fallback)
459+
return nil
460+
}
457461
log.Error("git config check failed",
458462
"key", key,
459463
"error", err,
@@ -465,19 +469,11 @@ func (s *GitService) ValidateGitConfig(ctx context.Context) error {
465469
return nil
466470
}
467471

468-
if err := validate("user.name", errors.ErrGitUserNotConfigured); err != nil {
469-
if s.fallbackName != "" {
470-
log.Info("using fallback git user.name", "name", s.fallbackName)
471-
} else {
472-
return err
473-
}
472+
if err := validate("user.name", errors.ErrGitUserNotConfigured, s.fallbackName); err != nil {
473+
return err
474474
}
475-
if err := validate("user.email", errors.ErrGitEmailNotConfigured); err != nil {
476-
if s.fallbackEmail != "" {
477-
log.Info("using fallback git user.email", "email", s.fallbackEmail)
478-
} else {
479-
return err
480-
}
475+
if err := validate("user.email", errors.ErrGitEmailNotConfigured, s.fallbackEmail); err != nil {
476+
return err
481477
}
482478

483479
return nil

internal/i18n/locales/active.en.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,4 +847,9 @@ created_summary = "✅ Created {{.Count}} issue successfully"
847847
error_reading_file = "Error reading plan file: {{.Error}}"
848848
error_empty_file = "Plan file is empty"
849849
error_parsing_plan = "Error parsing plan: {{.Error}}"
850+
851+
[config_git]
852+
fallback_header = "Git Fallback Configuration:"
853+
fallback_name = " Git Name: {{.Name}}"
854+
fallback_email = " Git Email: {{.Email}}"
850855
error_creating_issue = "Error creating issue: {{.Error}}"

internal/i18n/locales/active.es.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,4 +869,9 @@ created_summary = "✅ {{.Count}} issue creado exitosamente"
869869
error_reading_file = "Error leyendo archivo de plan: {{.Error}}"
870870
error_empty_file = "El archivo de plan está vacío"
871871
error_parsing_plan = "Error parseando plan: {{.Error}}"
872-
error_creating_issue = "Error creando issue: {{.Error}}"
872+
error_creating_issue = "Error creando issue: {{.Error}}"
873+
874+
[config_git]
875+
fallback_header = "Configuración Git Fallback:"
876+
fallback_name = " Nombre Git: {{.Name}}"
877+
fallback_email = " Email Git: {{.Email}}"

0 commit comments

Comments
 (0)