Skip to content

Commit 1f473af

Browse files
committed
Fix bug
1 parent 33b1ceb commit 1f473af

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

modules/git/attribute/checker.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,34 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
1818
if len(attributes) == 0 {
1919
cmd.AddArguments("--all")
2020
}
21-
if len(filenames) > 0 {
22-
cmd.AddDashesAndList(filenames...)
23-
}
2421
cancel := func() {}
25-
if git.DefaultFeatures().SupportCheckAttrOnBare && treeish != "" {
26-
cmd.AddArguments("--source")
27-
cmd.AddDynamicArguments(treeish)
28-
cmd.AddDynamicArguments(attributes...)
29-
return cmd, []string{"GIT_FLUSH=1"}, cancel, nil
30-
}
22+
envs := []string{"GIT_FLUSH=1"}
3123

32-
var envs []string
33-
if treeish != "" { // if it's empty, then we assume it's a worktree repository
34-
indexFilename, worktree, deleteTemporaryFile, err := gitRepo.ReadTreeToTemporaryIndex(treeish)
35-
if err != nil {
36-
return nil, nil, nil, err
37-
}
24+
// if there is a treeish, we asssume this is a bare repository
25+
// if it's empty, then we assume it's a worktree repository
26+
if treeish != "" {
27+
if git.DefaultFeatures().SupportCheckAttrOnBare {
28+
cmd.AddArguments("--source")
29+
cmd.AddDynamicArguments(treeish)
30+
} else {
31+
indexFilename, worktree, deleteTemporaryFile, err := gitRepo.ReadTreeToTemporaryIndex(treeish)
32+
if err != nil {
33+
return nil, nil, nil, err
34+
}
3835

39-
envs = []string{
40-
"GIT_INDEX_FILE=" + indexFilename,
41-
"GIT_WORK_TREE=" + worktree,
42-
"GIT_FLUSH=1",
36+
cmd.AddArguments("--cached")
37+
envs = append(envs,
38+
"GIT_INDEX_FILE="+indexFilename,
39+
"GIT_WORK_TREE="+worktree,
40+
)
41+
cancel = deleteTemporaryFile
4342
}
44-
cancel = deleteTemporaryFile
4543
}
46-
cmd.AddArguments("--cached")
44+
4745
cmd.AddDynamicArguments(attributes...)
46+
if len(filenames) > 0 {
47+
cmd.AddDashesAndList(filenames...)
48+
}
4849
return cmd, envs, cancel, nil
4950
}
5051

0 commit comments

Comments
 (0)