@@ -9,20 +9,33 @@ import (
9
9
"errors"
10
10
"fmt"
11
11
"os"
12
+ "strconv"
12
13
13
14
"code.gitea.io/gitea/modules/git"
14
15
)
15
16
16
17
func 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
+
17
34
cmd := git .NewCommand ("check-attr" , "-z" )
18
35
if len (attributes ) == 0 {
19
36
cmd .AddArguments ("--all" )
20
37
}
21
- cancel := func () {}
22
- envs := []string {"GIT_FLUSH=1" }
23
38
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
39
if treeish != "" {
27
40
if git .DefaultFeatures ().SupportCheckAttrOnBare {
28
41
cmd .AddArguments ("--source" )
0 commit comments