Skip to content

Commit 1a6c8ed

Browse files
jdeveraclaude
andcommitted
fix(identity): drop --global from config reads to support [include]
Using --global prevented git from resolving [include] directives in the global config file, so identities stored in included files were invisible. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 565c1ff commit 1a6c8ed

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

internal/identity/identity_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,41 @@ func TestProfileWithTestRepo(t *testing.T) {
296296
// primarily works with global config, but this demonstrates the
297297
// git config mechanics work correctly.
298298
}
299+
300+
func TestIncludedConfigFile(t *testing.T) {
301+
tmpDir := t.TempDir()
302+
setEnv(t, "HOME", tmpDir)
303+
304+
// Write identity config to a separate file
305+
identitiesFile := filepath.Join(tmpDir, ".git-identities")
306+
identitiesContent := `[identity "included"]
307+
email = included@example.com
308+
sshkey = ~/.ssh/id_included
309+
user = Included User
310+
ghuser = includeduser
311+
`
312+
require.NoError(t, os.WriteFile(identitiesFile, []byte(identitiesContent), 0o600))
313+
314+
// Main gitconfig includes the separate file
315+
gitconfig := filepath.Join(tmpDir, ".gitconfig")
316+
gitconfigContent := "[include]\n\tpath = " + identitiesFile + "\n"
317+
require.NoError(t, os.WriteFile(gitconfig, []byte(gitconfigContent), 0o600))
318+
319+
// List should find the included profile
320+
names, err := List()
321+
require.NoError(t, err)
322+
assert.Contains(t, names, "included")
323+
324+
// Get should read all fields
325+
p, err := Get("included")
326+
require.NoError(t, err)
327+
assert.Equal(t, "included@example.com", p.Email)
328+
assert.Equal(t, "~/.ssh/id_included", p.SSHKey)
329+
assert.Equal(t, "Included User", p.User)
330+
assert.Equal(t, "includeduser", p.GHUser)
331+
332+
// GetSourceFile should point to the included file
333+
source, err := GetSourceFile("included")
334+
require.NoError(t, err)
335+
assert.Equal(t, identitiesFile, source)
336+
}

internal/identity/profile.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var profileKeys = []string{"sshkey", "email", "user", "ghuser"}
2424

2525
// List returns all profile names from git config.
2626
func List() ([]string, error) {
27-
cmd := exec.Command("git", "config", "--global", "--get-regexp", `^identity\.`)
27+
cmd := exec.Command("git", "config", "--get-regexp", `^identity\.`)
2828
out, err := cmd.Output()
2929
if err != nil {
3030
// No matches is not an error - just empty
@@ -90,7 +90,7 @@ func Get(name string) (*Profile, error) {
9090
// getConfigValue reads a single config value.
9191
func getConfigValue(profile, key string) (string, error) {
9292
configKey := fmt.Sprintf("identity.%s.%s", profile, key)
93-
cmd := exec.Command("git", "config", "--global", "--get", configKey)
93+
cmd := exec.Command("git", "config", "--get", configKey)
9494
out, err := cmd.Output()
9595
if err != nil {
9696
return "", err
@@ -103,7 +103,7 @@ func GetSourceFile(name string) (string, error) {
103103
// Try to find any key for this profile
104104
for _, key := range profileKeys {
105105
configKey := fmt.Sprintf("identity.%s.%s", name, key)
106-
cmd := exec.Command("git", "config", "--global", "--show-origin", "--get", configKey)
106+
cmd := exec.Command("git", "config", "--show-origin", "--get", configKey)
107107
out, err := cmd.Output()
108108
if err != nil {
109109
continue
@@ -127,7 +127,7 @@ func GetAllSourceFiles(name string) ([]string, error) {
127127

128128
for _, key := range profileKeys {
129129
configKey := fmt.Sprintf("identity.%s.%s", name, key)
130-
cmd := exec.Command("git", "config", "--global", "--show-origin", "--get-all", configKey)
130+
cmd := exec.Command("git", "config", "--show-origin", "--get-all", configKey)
131131
out, err := cmd.Output()
132132
if err != nil {
133133
continue

0 commit comments

Comments
 (0)