@@ -13,7 +13,7 @@ import (
1313 "code.gitea.io/gitea/modules/git"
1414)
1515
16- func checkAttrCommand (gitRepo * git.Repository , treeish string , filenames , attributes []string , cached bool ) (* git.Command , []string , func (), error ) {
16+ func checkAttrCommand (gitRepo * git.Repository , treeish string , filenames , attributes []string ) (* git.Command , []string , func (), error ) {
1717 cancel := func () {}
1818 envs := []string {"GIT_FLUSH=1" }
1919 cmd := git .NewCommand ("check-attr" , "-z" )
@@ -39,11 +39,12 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
3939 )
4040 cancel = deleteTemporaryFile
4141 }
42- } else if cached {
43- // read from existing index instead of work tree, in cases where the repo is bare and has an index or the work tree
44- // contains unstaged changes that shouldn't affect the attribute check
42+ } else {
43+ // Read from existing index, in cases where the repo is bare and has an index,
44+ // or the work tree contains unstaged changes that shouldn't affect the attribute check.
45+ // It is caller's responsibility to add changed ".gitattributes" into the index if they want to respect the new changes.
4546 cmd .AddArguments ("--cached" )
46- } // else: no treeish, assume it is a not a bare repo, read from working directory
47+ }
4748
4849 cmd .AddDynamicArguments (attributes ... )
4950 if len (filenames ) > 0 {
@@ -55,13 +56,12 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
5556type CheckAttributeOpts struct {
5657 Filenames []string
5758 Attributes []string
58- Cached bool
5959}
6060
6161// CheckAttributes return the attributes of the given filenames and attributes in the given treeish.
6262// If treeish is empty, then it will use current working directory, otherwise it will use the provided treeish on the bare repo
6363func CheckAttributes (ctx context.Context , gitRepo * git.Repository , treeish string , opts CheckAttributeOpts ) (map [string ]* Attributes , error ) {
64- cmd , envs , cancel , err := checkAttrCommand (gitRepo , treeish , opts .Filenames , opts .Attributes , opts . Cached )
64+ cmd , envs , cancel , err := checkAttrCommand (gitRepo , treeish , opts .Filenames , opts .Attributes )
6565 if err != nil {
6666 return nil , err
6767 }
0 commit comments