Skip to content

Commit e6f0c39

Browse files
committed
feat(config): add support for per-repository configuration overrides
1 parent 980468d commit e6f0c39

4 files changed

Lines changed: 38 additions & 9 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,19 @@ Requirements:
116116
### 2. Prompt Configuration (`~/.config/.lazycommit.prompts.yaml`)
117117
Contains prompt templates and message configurations. **Safe to share in dotfiles and Git.**
118118

119-
This file is automatically created on first run with sensible defaults:
119+
### Per-Repository Configuration
120+
121+
You can override the prompt configuration on a per-repository basis by creating a `.lazycommit.prompts.yaml` file in the root of your git repository. This is useful for projects that require different languages or commit message formats.
122+
123+
Example `.lazycommit.prompts.yaml` for a Korean project:
124+
```yaml
125+
language: ko
126+
commit_message_template: "Based on the following git diff, generate 5 conventional commit messages in Korean:\n\n%s"
127+
```
128+
129+
**Note:** It is recommended to use only `.lazycommit.prompts.yaml` for repository-specific overrides. Avoid using a local `.lazycommit.yaml` (provider config) to prevent accidentally committing sensitive information like API keys.
130+
131+
This file is automatically created on first run in the global config directory with sensible defaults:
120132

121133
```yaml
122134
system_message: "You are a helpful assistant that generates git commit messages, and pull request titles."

internal/config/config.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func InitConfig() {
3232
viper.SetConfigName(".lazycommit")
3333
viper.SetConfigType("yaml")
3434
viper.AddConfigPath(getConfigDir())
35+
3536
viper.SetConfigFile(filepath.Join(getConfigDir(), ".lazycommit.yaml"))
3637

3738
if token, err := LoadGitHubToken(); err == nil && token != "" {
@@ -43,11 +44,8 @@ func InitConfig() {
4344
viper.SetDefault("providers.openai.model", "openai/gpt-5-mini")
4445
}
4546

46-
// Set defaults for anthropic provider
4747
viper.SetDefault("providers.anthropic.model", "claude-haiku-4-5")
4848
viper.SetDefault("providers.anthropic.num_suggestions", 10)
49-
50-
// Set default language
5149
viper.SetDefault("language", "en")
5250

5351
viper.AutomaticEnv()
@@ -73,7 +71,6 @@ func InitConfig() {
7371
os.Exit(1)
7472
}
7573

76-
// Initialize prompt configuration
7774
InitPromptConfig()
7875
}
7976

internal/config/prompts.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/m7medvision/lazycommit/internal/git"
89
"gopkg.in/yaml.v3"
910
)
1011

1112
type PromptConfig struct {
1213
SystemMessage string `yaml:"system_message"`
1314
CommitMessageTemplate string `yaml:"commit_message_template"`
1415
PRTitleTemplate string `yaml:"pr_title_template"`
16+
Language string `yaml:"language,omitempty"`
1517
}
1618

1719
var promptsCfg *PromptConfig
@@ -24,7 +26,13 @@ func InitPromptConfig() {
2426

2527
promptsFile := filepath.Join(getConfigDir(), ".lazycommit.prompts.yaml")
2628

27-
// Check if prompts file exists
29+
if repoRoot, err := git.GetRepoRoot(); err == nil {
30+
localPromptsFile := filepath.Join(repoRoot, ".lazycommit.prompts.yaml")
31+
if _, err := os.Stat(localPromptsFile); err == nil {
32+
promptsFile = localPromptsFile
33+
}
34+
}
35+
2836
if _, err := os.Stat(promptsFile); os.IsNotExist(err) {
2937
// Create default prompts file
3038
defaultConfig := getDefaultPromptConfig()
@@ -111,7 +119,11 @@ func GetCommitMessagePromptFromConfig(diff string) string {
111119
}
112120

113121
// Add language instruction based on configuration
114-
language := GetLanguage()
122+
language := config.Language
123+
if language == "" {
124+
language = GetLanguage()
125+
}
126+
115127
if language == "es" {
116128
basePrompt += "\n\nIMPORTANT: Generate all commit messages in Spanish."
117129
} else if language == "en" {

internal/git/git.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ package git
33
import (
44
"bytes"
55
"fmt"
6-
76
"os/exec"
7+
"strings"
88
)
99

10-
// GetStagedDiff returns the diff of the staged files.
10+
func GetRepoRoot() (string, error) {
11+
cmd := exec.Command("git", "rev-parse", "--show-toplevel")
12+
out, err := cmd.Output()
13+
if err != nil {
14+
return "", fmt.Errorf("error running git rev-parse --show-toplevel: %w", err)
15+
}
16+
return strings.TrimSpace(string(out)), nil
17+
}
18+
1119
func GetStagedDiff() (string, error) {
1220
cmd := exec.Command("git", "diff", "--cached")
1321
var out bytes.Buffer

0 commit comments

Comments
 (0)