Skip to content

Commit

Permalink
Adding fully qualified names to the fetch commands. (#112)
Browse files Browse the repository at this point in the history
If branch is given we fetch only the branch even if we have commit hash.

[ACT-483][ACT-471]
  • Loading branch information
Mate Herber authored Aug 28, 2020
1 parent 2339699 commit 58bb71f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func isPrivate(repoURL string) bool {
// where x is the pull request id.
func fetchArg(mergeBranch string) string {
arg := strings.TrimSuffix(mergeBranch, "/merge")
return strings.Replace(mergeBranch, "merge", "head", 1) + ":" + arg
return strings.Replace("refs/"+mergeBranch, "merge", "head", 1) + ":" + arg
}

func mergeArg(mergeBranch string) string {
Expand All @@ -180,7 +180,7 @@ func autoMerge(gitCmd git.Git, mergeBranch, branchDest, buildURL, apiToken strin
if depth != 0 {
opts = append(opts, "--depth="+strconv.Itoa(depth))
}
opts = append(opts, "origin", branchDest)
opts = append(opts, "origin", "refs/heads/"+branchDest)
return gitCmd.Fetch(opts...)
}); err != nil {
return fmt.Errorf("Fetch failed, error: %v", err)
Expand Down Expand Up @@ -227,7 +227,7 @@ func autoMerge(gitCmd git.Git, mergeBranch, branchDest, buildURL, apiToken strin
}

func manualMerge(gitCmd git.Git, repoURL, prRepoURL, branch, commit, branchDest string) error {
if err := runWithRetry(func() *command.Model { return gitCmd.Fetch("origin", branchDest) }); err != nil {
if err := runWithRetry(func() *command.Model { return gitCmd.Fetch("origin", "refs/heads/"+branchDest) }); err != nil {
return fmt.Errorf("fetch failed, error: %v", err)
}
if err := pull(gitCmd, branchDest); err != nil {
Expand All @@ -243,14 +243,14 @@ func manualMerge(gitCmd git.Git, repoURL, prRepoURL, branch, commit, branchDest
if err := run(gitCmd.RemoteAdd("fork", prRepoURL)); err != nil {
return fmt.Errorf("couldn't add remote (%s), error: %v", prRepoURL, err)
}
if err := runWithRetry(func() *command.Model { return gitCmd.Fetch("fork", branch) }); err != nil {
if err := runWithRetry(func() *command.Model { return gitCmd.Fetch("fork", "refs/heads/"+branch) }); err != nil {
return fmt.Errorf("fetch Pull Request branch failed (%s), error: %v", branch, err)
}
if err := run(gitCmd.Merge("fork/" + branch)); err != nil {
return fmt.Errorf("merge failed (fork/%s), error: %v", branch, err)
}
} else {
if err := run(gitCmd.Fetch("origin", branch)); err != nil {
if err := run(gitCmd.Fetch("origin", "refs/heads/"+branch)); err != nil {
return fmt.Errorf("fetch failed, error: %v", err)
}
if err := run(gitCmd.Merge(commit)); err != nil {
Expand Down

0 comments on commit 58bb71f

Please sign in to comment.