fix(git): fetch all branches (#32)

This commit is contained in:
Teppei Fukuda 2020-04-06 12:57:24 +03:00 committed by GitHub
parent 9ad10fa73b
commit e308afb79a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,9 @@ func (gc Config) CloneOrPull(url, repoPath string) (map[string]struct{}, error)
return nil, err
}
if err := fetchAll(repoPath); err != nil {
return nil, err
}
err = filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
@ -115,6 +118,20 @@ func pull(url, repoPath string) ([]string, error) {
return updatedFiles, nil
}
func fetchAll(repoPath string) error {
commandArgs := generateGitArgs(repoPath)
configCmd := []string{"config", "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"}
if _, err := utils.Exec("git", append(commandArgs, configCmd...)); err != nil {
return xerrors.Errorf("error in git config: %w", err)
}
fetchCmd := []string{"fetch", "--all"}
if _, err := utils.Exec("git", append(commandArgs, fetchCmd...)); err != nil {
return xerrors.Errorf("error in git fetch: %w", err)
}
return nil
}
func (gc Config) Commit(repoPath, targetPath, message string) error {
commandArgs := generateGitArgs(repoPath)
addCmd := []string{"add", filepath.Join(repoPath, targetPath)}