@@ -18,33 +18,34 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
18
18
if len (attributes ) == 0 {
19
19
cmd .AddArguments ("--all" )
20
20
}
21
- if len (filenames ) > 0 {
22
- cmd .AddDashesAndList (filenames ... )
23
- }
24
21
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" }
31
23
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
+ }
38
35
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
43
42
}
44
- cancel = deleteTemporaryFile
45
43
}
46
- cmd . AddArguments ( "--cached" )
44
+
47
45
cmd .AddDynamicArguments (attributes ... )
46
+ if len (filenames ) > 0 {
47
+ cmd .AddDashesAndList (filenames ... )
48
+ }
48
49
return cmd , envs , cancel , nil
49
50
}
50
51
0 commit comments