Skip to content

Commit da0611a

Browse files
committed
Fetch all branches
1 parent 65c6d14 commit da0611a

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

github.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,45 @@ func (c *GithubConfig) getStarredRepos(page int) ([]*github.Repository, *github.
101101

102102
func (c *GithubConfig) CloneInto(repo *github.Repository, path string) error {
103103
auth := &http.BasicAuth{
104-
Username: "git",
105-
Password: c.AccessToken,
104+
Username: "git",
105+
Password: c.AccessToken,
106106
}
107-
_, err := git.PlainClone(path, false, &git.CloneOptions{
108-
URL: *repo.CloneURL,
109-
Auth: auth,
110-
Progress: os.Stdout,
107+
gitRepo, err := git.PlainClone(path, false, &git.CloneOptions{
108+
URL: *repo.CloneURL,
109+
Auth: auth,
110+
Progress: os.Stdout,
111111
})
112+
switch err {
113+
case transport.ErrEmptyRemoteRepository:
114+
return nil
115+
default:
116+
return err
117+
case git.ErrRepositoryAlreadyExists:
118+
fallthrough
119+
case nil:
120+
}
112121
if err == git.ErrRepositoryAlreadyExists {
113-
if r, pullErr := git.PlainOpen(path); pullErr != nil {
114-
err = pullErr
115-
} else if w, pullErr := r.Worktree(); pullErr != nil {
116-
err = pullErr
117-
} else if pullErr := w.Pull(&git.PullOptions{
118-
Auth: auth,
119-
Progress: os.Stdout,
120-
}); pullErr != nil {
121-
err = pullErr
122+
if gitRepo, err = git.PlainOpen(path); err != nil {
123+
return err
124+
} else if w, err := gitRepo.Worktree(); err != nil {
125+
return err
126+
} else if err := w.Pull(&git.PullOptions{
127+
Auth: auth,
128+
Progress: os.Stdout,
129+
}); err == git.NoErrAlreadyUpToDate {
130+
return nil
131+
} else if err != nil {
132+
return err
122133
}
123134
}
124-
135+
err = gitRepo.Fetch(&git.FetchOptions{
136+
Auth: auth,
137+
Progress: os.Stdout,
138+
Tags: git.AllTags,
139+
Force: true,
140+
})
125141
switch err {
126142
case git.NoErrAlreadyUpToDate:
127-
fallthrough
128-
case transport.ErrEmptyRemoteRepository:
129143
return nil
130144
default:
131145
return err

0 commit comments

Comments
 (0)