@@ -932,22 +932,18 @@ func MigrateRepository(doer, u *User, opts MigrateRepoOptions) (*Repository, err
932932 }
933933 }
934934
935- // Check if repository is empty.
936- _ , stderr , err := com .ExecCmdDir (repoPath , "git" , "log" , "-1" )
935+ gitRepo , err := git .OpenRepository (repoPath )
937936 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 )
943943 }
944944
945945 if ! repo .IsEmpty {
946946 // 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- }
951947 headBranch , err := gitRepo .GetHEADBranch ()
952948 if err != nil {
953949 return repo , fmt .Errorf ("GetHEADBranch: %v" , err )
@@ -1072,20 +1068,20 @@ func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
10721068 var stderr string
10731069 if _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
10741070 tmpPath , fmt .Sprintf ("initRepoCommit (git add): %s" , tmpPath ),
1075- " git" , "add" , "--all" ); err != nil {
1071+ git . GitExecutable , "add" , "--all" ); err != nil {
10761072 return fmt .Errorf ("git add: %s" , stderr )
10771073 }
10781074
10791075 if _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
10801076 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 ),
10821078 "-m" , "Initial commit" ); err != nil {
10831079 return fmt .Errorf ("git commit: %s" , stderr )
10841080 }
10851081
10861082 if _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
10871083 tmpPath , fmt .Sprintf ("initRepoCommit (git push): %s" , tmpPath ),
1088- " git" , "push" , "origin" , "master" ); err != nil {
1084+ git . GitExecutable , "push" , "origin" , "master" ); err != nil {
10891085 return fmt .Errorf ("git push: %s" , stderr )
10901086 }
10911087 return nil
@@ -1131,7 +1127,7 @@ func prepareRepoCommit(e Engine, repo *Repository, tmpDir, repoPath string, opts
11311127 // Clone to temporary path and do the init commit.
11321128 _ , stderr , err := process .GetManager ().Exec (
11331129 fmt .Sprintf ("initRepository(git clone): %s" , repoPath ),
1134- " git" , "clone" , repoPath , tmpDir ,
1130+ git . GitExecutable , "clone" , repoPath , tmpDir ,
11351131 )
11361132 if err != nil {
11371133 return fmt .Errorf ("git clone: %v - %s" , err , stderr )
@@ -1390,7 +1386,7 @@ func CreateRepository(doer, u *User, opts CreateRepoOptions) (_ *Repository, err
13901386
13911387 _ , stderr , err := process .GetManager ().ExecDir (- 1 ,
13921388 repoPath , fmt .Sprintf ("CreateRepository(git update-server-info): %s" , repoPath ),
1393- " git" , "update-server-info" )
1389+ git . GitExecutable , "update-server-info" )
13941390 if err != nil {
13951391 return nil , errors .New ("CreateRepository(git update-server-info): " + stderr )
13961392 }
@@ -2239,7 +2235,7 @@ func GitGcRepos() error {
22392235 _ , stderr , err := process .GetManager ().ExecDir (
22402236 time .Duration (setting .Git .Timeout .GC )* time .Second ,
22412237 RepoPath (repo .Owner .Name , repo .Name ), "Repository garbage collection" ,
2242- " git" , args ... )
2238+ git . GitExecutable , args ... )
22432239 if err != nil {
22442240 return fmt .Errorf ("%v: %v" , err , stderr )
22452241 }
@@ -2429,14 +2425,14 @@ func ForkRepository(doer, u *User, oldRepo *Repository, name, desc string) (_ *R
24292425 repoPath := RepoPath (u .Name , repo .Name )
24302426 _ , stderr , err := process .GetManager ().ExecTimeout (10 * time .Minute ,
24312427 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 )
24332429 if err != nil {
24342430 return nil , fmt .Errorf ("git clone: %v" , stderr )
24352431 }
24362432
24372433 _ , stderr , err = process .GetManager ().ExecDir (- 1 ,
24382434 repoPath , fmt .Sprintf ("ForkRepository(git update-server-info): %s" , repoPath ),
2439- " git" , "update-server-info" )
2435+ git . GitExecutable , "update-server-info" )
24402436 if err != nil {
24412437 return nil , fmt .Errorf ("git update-server-info: %v" , stderr )
24422438 }
0 commit comments