@@ -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 ) (* git.Command , []string , func (), error ) {
16+ func checkAttrCommand (gitRepo * git.Repository , treeish string , filenames , attributes []string , cached bool ) (* git.Command , []string , func (), error ) {
1717 cancel := func () {}
1818 envs := []string {"GIT_FLUSH=1" }
1919 cmd := git .NewCommand ("check-attr" , "-z" )
@@ -39,6 +39,8 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
3939 )
4040 cancel = deleteTemporaryFile
4141 }
42+ } else if cached {
43+ cmd .AddArguments ("--cached" )
4244 } // else: no treeish, assume it is a not a bare repo, read from working directory
4345
4446 cmd .AddDynamicArguments (attributes ... )
@@ -51,12 +53,13 @@ func checkAttrCommand(gitRepo *git.Repository, treeish string, filenames, attrib
5153type CheckAttributeOpts struct {
5254 Filenames []string
5355 Attributes []string
56+ Cached bool
5457}
5558
5659// CheckAttributes return the attributes of the given filenames and attributes in the given treeish.
5760// If treeish is empty, then it will use current working directory, otherwise it will use the provided treeish on the bare repo
5861func CheckAttributes (ctx context.Context , gitRepo * git.Repository , treeish string , opts CheckAttributeOpts ) (map [string ]* Attributes , error ) {
59- cmd , envs , cancel , err := checkAttrCommand (gitRepo , treeish , opts .Filenames , opts .Attributes )
62+ cmd , envs , cancel , err := checkAttrCommand (gitRepo , treeish , opts .Filenames , opts .Attributes , opts . Cached )
6063 if err != nil {
6164 return nil , err
6265 }
0 commit comments