Skip to content

Commit

Permalink
rebase -i -p: handle index and workdir correctly
Browse files Browse the repository at this point in the history
'git rebase -i -p' forgot to update the index and working directory
during fast forwards.  Fix this.  Makes 'GIT_EDITOR=true rebase -i -p
<ancestor>' a no-op again.

Also, it attempted to do a fast forward even if it was instructed not
to commit (via -n).  Fall back to the cherry-pick code path and let
that handle the issue for us.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Aug 13, 2008
1 parent 65f59e2 commit 71d9451
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions git-rebase--interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,16 @@ pick_one () {
}

pick_one_preserving_merges () {
case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
fast_forward=t
case "$1" in
-n)
fast_forward=f
sha1=$2
;;
*)
sha1=$1
;;
esac
sha1=$(git rev-parse $sha1)

if test -f "$DOTEST"/current-commit
Expand All @@ -157,7 +166,6 @@ pick_one_preserving_merges () {
fi

# rewrite parents; if none were rewritten, we can fast-forward.
fast_forward=t
preserve=t
new_parents=
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -f2-)
Expand All @@ -182,6 +190,8 @@ pick_one_preserving_merges () {
t)
output warn "Fast forward to $sha1"
test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
output git reset --hard $sha1 ||
die "Cannot fast forward to $sha1"
;;
f)
test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
Expand Down
6 changes: 6 additions & 0 deletions t/t3404-rebase-interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ test_expect_success 'retain authorship when squashing' '
test_expect_success '-p handles "no changes" gracefully' '
HEAD=$(git rev-parse HEAD) &&
git rebase -i -p HEAD^ &&
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD -- &&
test $HEAD = $(git rev-parse HEAD)
'

Expand Down Expand Up @@ -235,6 +238,9 @@ test_expect_success 'preserve merges with -p' '
git checkout -b to-be-rebased &&
test_tick &&
git rebase -i -p --onto branch1 master &&
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --quiet --cached HEAD -- &&
test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&
Expand Down

0 comments on commit 71d9451

Please sign in to comment.