Skip to content

Commit 290a124

Browse files
authored
Skip the git pull on bare repositories (#9)
A second run with -backup.bare-clone would fail as it would still try to retrieve a work tree and do a git pull. Now it will check whether a discovered repository is bare or not. And if it is, it will just skip the git pull and only do a git fetch down the line.
1 parent f5d5897 commit 290a124

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

repository.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ type Repository struct {
2121
FullName string
2222
}
2323

24+
func isBare(repo *git.Repository) (bool, error) {
25+
config, err := repo.Config()
26+
if err != nil {
27+
return false, err
28+
}
29+
30+
return config.Core.IsBare, nil
31+
}
32+
2433
func (r *Repository) CloneInto(path string, bare bool) error {
2534
var auth http.AuthMethod
2635
if r.GitURL.User != nil {
@@ -39,13 +48,17 @@ func (r *Repository) CloneInto(path string, bare bool) error {
3948
if err == git.ErrRepositoryAlreadyExists {
4049
// Pull instead of clone
4150
if gitRepo, err = git.PlainOpen(path); err == nil {
42-
if w, wErr := gitRepo.Worktree(); wErr != nil {
43-
err = wErr
44-
} else {
45-
err = w.Pull(&git.PullOptions{
46-
Auth: auth,
47-
Progress: os.Stdout,
48-
})
51+
// we need to check whether it's a bare repo or not.
52+
// if not we should pull, if it is then pull won't work
53+
if isBare, bErr := isBare(gitRepo); bErr == nil && !isBare {
54+
if w, wErr := gitRepo.Worktree(); wErr != nil {
55+
err = wErr
56+
} else {
57+
err = w.Pull(&git.PullOptions{
58+
Auth: auth,
59+
Progress: os.Stdout,
60+
})
61+
}
4962
}
5063
}
5164
}

0 commit comments

Comments
 (0)