@@ -932,22 +932,18 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
932
932
}
933
933
}
934
934
935
- // Check if repository is empty.
936
- _ , stderr , err := com .ExecCmdDir (repoPath , "git" , "log" , "-1" )
935
+ gitRepo , err := git .OpenRepository (repoPath )
937
936
if err != nil {
938
- if strings .Contains (stderr , "fatal: bad default revision 'HEAD'" ) {
939
- repo .IsEmpty = true
940
- } else {
941
- return repo , fmt .Errorf ("check empty: %v - %s" , err , stderr )
942
- }
937
+ return repo , fmt .Errorf ("OpenRepository: %v" , err )
938
+ }
939
+
940
+ repo .IsEmpty , err = gitRepo .IsEmpty ()
941
+ if err != nil {
942
+ return repo , fmt .Errorf ("git.IsEmpty: %v" , err )
943
943
}
944
944
945
945
if ! repo .IsEmpty {
946
946
// Try to get HEAD branch and set it as default branch.
947
- gitRepo , err := git .OpenRepository (repoPath )
948
- if err != nil {
949
- return repo , fmt .Errorf ("OpenRepository: %v" , err )
950
- }
951
947
headBranch , err := gitRepo .GetHEADBranch ()
952
948
if err != nil {
953
949
return repo , fmt .Errorf ("GetHEADBranch: %v" , err )
@@ -1072,20 +1068,20 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
1072
1068
var stderr string
1073
1069
if _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
1074
1070
tmpPath , fmt .Sprintf ("initRepoCommit (git add): %s" , tmpPath ),
1075
- " git" , "add" , "--all" ); err != nil {
1071
+ git . GitExecutable , "add" , "--all" ); err != nil {
1076
1072
return fmt .Errorf ("git add: %s" , stderr )
1077
1073
}
1078
1074
1079
1075
if _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
1080
1076
tmpPath , fmt .Sprintf ("initRepoCommit (git commit): %s" , tmpPath ),
1081
- " git" , "commit" , fmt .Sprintf ("--author='%s <%s>'" , sig .Name , sig .Email ),
1077
+ git . GitExecutable , "commit" , fmt .Sprintf ("--author='%s <%s>'" , sig .Name , sig .Email ),
1082
1078
"-m" , "Initial commit" ); err != nil {
1083
1079
return fmt .Errorf ("git commit: %s" , stderr )
1084
1080
}
1085
1081
1086
1082
if _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
1087
1083
tmpPath , fmt .Sprintf ("initRepoCommit (git push): %s" , tmpPath ),
1088
- " git" , "push" , "origin" , "master" ); err != nil {
1084
+ git . GitExecutable , "push" , "origin" , "master" ); err != nil {
1089
1085
return fmt .Errorf ("git push: %s" , stderr )
1090
1086
}
1091
1087
return nil
@@ -1131,7 +1127,7 @@ func prepareRepoCommit(e Engine, repo *Repository, tmpDir, repoPath string, opts
1131
1127
// Clone to temporary path and do the init commit.
1132
1128
_ , stderr , err := process .GetManager ().Exec (
1133
1129
fmt .Sprintf ("initRepository(git clone): %s" , repoPath ),
1134
- " git" , "clone" , repoPath , tmpDir ,
1130
+ git . GitExecutable , "clone" , repoPath , tmpDir ,
1135
1131
)
1136
1132
if err != nil {
1137
1133
return fmt .Errorf ("git clone: %v - %s" , err , stderr )
@@ -1390,7 +1386,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
1390
1386
1391
1387
_ , stderr , err := process .GetManager ().ExecDir (- 1 ,
1392
1388
repoPath , fmt .Sprintf ("CreateRepository(git update-server-info): %s" , repoPath ),
1393
- " git" , "update-server-info" )
1389
+ git . GitExecutable , "update-server-info" )
1394
1390
if err != nil {
1395
1391
return nil , errors .New ("CreateRepository(git update-server-info): " + stderr )
1396
1392
}
@@ -2239,7 +2235,7 @@ func GitGcRepos() error {
2239
2235
_ , stderr , err := process .GetManager ().ExecDir (
2240
2236
time .Duration (setting .Git .Timeout .GC )* time .Second ,
2241
2237
RepoPath (repo .Owner .Name , repo .Name ), "Repository garbage collection" ,
2242
- " git" , args ... )
2238
+ git . GitExecutable , args ... )
2243
2239
if err != nil {
2244
2240
return fmt .Errorf ("%v: %v" , err , stderr )
2245
2241
}
@@ -2429,14 +2425,14 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R
2429
2425
repoPath := RepoPath (u .Name , repo .Name )
2430
2426
_ , stderr , err := process .GetManager ().ExecTimeout (10 * time .Minute ,
2431
2427
fmt .Sprintf ("ForkRepository(git clone): %s/%s" , u .Name , repo .Name ),
2432
- " git" , "clone" , "--bare" , oldRepo .repoPath (sess ), repoPath )
2428
+ git . GitExecutable , "clone" , "--bare" , oldRepo .repoPath (sess ), repoPath )
2433
2429
if err != nil {
2434
2430
return nil , fmt .Errorf ("git clone: %v" , stderr )
2435
2431
}
2436
2432
2437
2433
_ , stderr , err = process .GetManager ().ExecDir (- 1 ,
2438
2434
repoPath , fmt .Sprintf ("ForkRepository(git update-server-info): %s" , repoPath ),
2439
- " git" , "update-server-info" )
2435
+ git . GitExecutable , "update-server-info" )
2440
2436
if err != nil {
2441
2437
return nil , fmt .Errorf ("git update-server-info: %v" , stderr )
2442
2438
}
0 commit comments