Skip to content

Commit 71d9451

Browse files
trastgitster
authored andcommitted
rebase -i -p: handle index and workdir correctly
'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>
1 parent 65f59e2 commit 71d9451

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

git-rebase--interactive.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,16 @@ pick_one () {
145145
}
146146

147147
pick_one_preserving_merges () {
148-
case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
148+
fast_forward=t
149+
case "$1" in
150+
-n)
151+
fast_forward=f
152+
sha1=$2
153+
;;
154+
*)
155+
sha1=$1
156+
;;
157+
esac
149158
sha1=$(git rev-parse $sha1)
150159

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

159168
# rewrite parents; if none were rewritten, we can fast-forward.
160-
fast_forward=t
161169
preserve=t
162170
new_parents=
163171
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -f2-)
@@ -182,6 +190,8 @@ pick_one_preserving_merges () {
182190
t)
183191
output warn "Fast forward to $sha1"
184192
test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
193+
output git reset --hard $sha1 ||
194+
die "Cannot fast forward to $sha1"
185195
;;
186196
f)
187197
test "a$1" = a-n && die "Refusing to squash a merge: $sha1"

t/t3404-rebase-interactive.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ test_expect_success 'retain authorship when squashing' '
202202
test_expect_success '-p handles "no changes" gracefully' '
203203
HEAD=$(git rev-parse HEAD) &&
204204
git rebase -i -p HEAD^ &&
205+
git update-index --refresh &&
206+
git diff-files --quiet &&
207+
git diff-index --quiet --cached HEAD -- &&
205208
test $HEAD = $(git rev-parse HEAD)
206209
'
207210

@@ -235,6 +238,9 @@ test_expect_success 'preserve merges with -p' '
235238
git checkout -b to-be-rebased &&
236239
test_tick &&
237240
git rebase -i -p --onto branch1 master &&
241+
git update-index --refresh &&
242+
git diff-files --quiet &&
243+
git diff-index --quiet --cached HEAD -- &&
238244
test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
239245
test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
240246
test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&

0 commit comments

Comments
 (0)