diff --git a/bin/git-pull-request.rb b/bin/git-pull-request.rb index 10502a5e99f..9cadd0e9b9b 100755 --- a/bin/git-pull-request.rb +++ b/bin/git-pull-request.rb @@ -190,8 +190,16 @@ def merge(number) puts " into " + color(base['ref'] + ": " + base['sha'], :green) with_temporary_branch(base) do |tmp| - puts "Merging head to temporary branch" - Git.run("merge --squash #{head['sha']}") + is_fork = head['repo']['fork'] + + if is_fork: + remote = head['repo']['git_url'] + ref = head['ref'] + Git.run("pull --squash #{remote} #{ref}") + else + puts "Merging head to temporary branch" + Git.run("merge --squash #{head['sha']}") + end commit_msg = merge_commit_msg(pull_request, issue) @@ -205,9 +213,11 @@ def merge(number) puts "Pushing to origin" Git.run("push origin master") - puts "Deleting local and remote branches" - Git.run("push origin :#{head['ref']}") - Git.run("branch -D #{head['ref']}") + if !is_fork: + puts "Deleting local and remote branches" + Git.run("push origin :#{head['ref']}") + Git.run("branch -D #{head['ref']}") + end end end