Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ type Repository struct {
FullName string
}

func isBare(repo *git.Repository) (bool, error) {
config, err := repo.Config()
if err != nil {
return false, err
}

return config.Core.IsBare, nil
}

func (r *Repository) CloneInto(path string, bare bool) error {
var auth http.AuthMethod
if r.GitURL.User != nil {
Expand All @@ -39,13 +48,17 @@ func (r *Repository) CloneInto(path string, bare bool) error {
if err == git.ErrRepositoryAlreadyExists {
// Pull instead of clone
if gitRepo, err = git.PlainOpen(path); err == nil {
if w, wErr := gitRepo.Worktree(); wErr != nil {
err = wErr
} else {
err = w.Pull(&git.PullOptions{
Auth: auth,
Progress: os.Stdout,
})
// we need to check whether it's a bare repo or not.
// if not we should pull, if it is then pull won't work
if isBare, bErr := isBare(gitRepo); bErr == nil && !isBare {
if w, wErr := gitRepo.Worktree(); wErr != nil {
err = wErr
} else {
err = w.Pull(&git.PullOptions{
Auth: auth,
Progress: os.Stdout,
})
}
}
}
}
Expand Down