@@ -9,20 +9,33 @@ import (
99 "errors"
1010 "fmt"
1111 "os"
12+ "strconv"
1213
1314 "code.gitea.io/gitea/modules/git"
1415)
1516
1617func checkAttrCommand (gitRepo * git.Repository , treeish string , filenames , attributes []string ) (* git.Command , []string , func (), error ) {
18+ cancel := func () {}
19+ envs := []string {"GIT_FLUSH=1" }
20+
21+ // Check if the repository is bare
22+ res , _ , err := git .NewCommand ("rev-parse" , "--is-bare-repository" ).RunStdString (gitRepo .Ctx , & git.RunOpts {
23+ Dir : gitRepo .Path ,
24+ })
25+ if err != nil {
26+ return nil , nil , nil , fmt .Errorf ("failed to run rev-parse: %w" , err )
27+ }
28+ isBare , _ := strconv .ParseBool (res )
29+ // bare repository must have a treeish
30+ if isBare && treeish == "" {
31+ return nil , nil , nil , fmt .Errorf ("bare repository must have a treeish" )
32+ }
33+
1734 cmd := git .NewCommand ("check-attr" , "-z" )
1835 if len (attributes ) == 0 {
1936 cmd .AddArguments ("--all" )
2037 }
21- cancel := func () {}
22- envs := []string {"GIT_FLUSH=1" }
2338
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
2639 if treeish != "" {
2740 if git .DefaultFeatures ().SupportCheckAttrOnBare {
2841 cmd .AddArguments ("--source" )
0 commit comments