Skip to content
This repository has been archived by the owner on Sep 23, 2019. It is now read-only.

Commit

Permalink
rebase: Merge --ff-only if the PR is a merge
Browse files Browse the repository at this point in the history
If the HEAD of the PR is a merge commit (has more than 1 parent), ask
the user if they would like to do a `merge --ff-only` instead, as
normally rebasing a merge commit results in horrors and nightmares.

This feature should be considered experimental, in the future this might
be done by default without asking or an option might be added to force
this behaviour beforehand to avoid annoying interactive questions.

Fixes sociomantic-tsunami#183.
  • Loading branch information
leandro-lucarella-sociomantic committed Sep 6, 2016
1 parent cde81eb commit 8aa88b8
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions git-hub
Original file line number Diff line number Diff line change
Expand Up @@ -1851,11 +1851,24 @@ class RebaseCmd (PullUtil):
starting = args.action is None
try:
if starting:
a = []
if config.forcerebase:
a.append('--force')
a.append('FETCH_HEAD')
git_quiet(1, 'rebase', *a)
parents = git('show --quiet --format="%P" FETCH_HEAD').split()
# Last commit is a merge commit, so ask the user to merge
# --ff-only instead
if len(parents) > 1:
answer = ask("The last commit in the pull request is a "
"merge commit, do a merge --ff-only instead of a "
"rebase?", default="yes")
if answer == 'no':
sys.exit(0)
assert answer == 'yes'
git_quiet(1, 'merge --ff-only FETCH_HEAD')
return
else:
a = []
if config.forcerebase:
a.append('--force')
a.append('FETCH_HEAD')
git_quiet(1, 'rebase', *a)
else:
git('rebase', args.action)
except subprocess.CalledProcessError as e:
Expand Down

0 comments on commit 8aa88b8

Please sign in to comment.