Skip to content

Commit ff74126

Browse files
dschospearce
authored andcommitted
rebase -i: do not fail when there is no commit to cherry-pick
In case there is no commit to apply (for example because you rebase to upstream and all your local patches have been applied there), do not fail. The non-interactive rebase already behaves that way. Do this by introducing a new command, "noop", which is substituted for an empty commit list, so that deleting the commit list can still abort as before. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent b8eecaf commit ff74126

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

git-rebase--interactive.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ do_next () {
277277
"$DOTEST"/amend || exit
278278
read command sha1 rest < "$TODO"
279279
case "$command" in
280-
'#'*|'')
280+
'#'*|''|noop)
281281
mark_action_done
282282
;;
283283
pick|p)
@@ -584,6 +584,7 @@ first and then run 'git rebase --continue' again."
584584
--abbrev=7 --reverse --left-right --cherry-pick \
585585
$UPSTREAM...$HEAD | \
586586
sed -n "s/^>/pick /p" > "$TODO"
587+
test -s "$TODO" || echo noop >> "$TODO"
587588
cat >> "$TODO" << EOF
588589
589590
# Rebase $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO

t/t3404-rebase-interactive.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,15 @@ test_expect_success 'rebase with a file named HEAD in worktree' '
419419
420420
'
421421

422+
test_expect_success 'do "noop" when there is nothing to cherry-pick' '
423+
424+
git checkout -b branch4 HEAD &&
425+
GIT_EDITOR=: git commit --amend \
426+
--author="Somebody else <[email protected]>"
427+
test $(git rev-parse branch3) != $(git rev-parse branch4) &&
428+
git rebase -i branch3 &&
429+
test $(git rev-parse branch3) = $(git rev-parse branch4)
430+
431+
'
432+
422433
test_done

0 commit comments

Comments
 (0)