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>
Thomas Rast committed
Aug 13, 2008 at 23:41 UTC
71d9451e061841ed5acb576652e09df32c700b86
2 files changed
+18
-2
git-rebase--interactive.sh
+12
-2
@@ -145,7 +145,16 @@ pick_one () {
145
}
146
147
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
158
sha1=$(git rev-parse $sha1)
159
160
if test -f "$DOTEST"/current-commit
@@ -157,7 +166,6 @@ pick_one_preserving_merges () {
166
fi
167
168
# rewrite parents; if none were rewritten, we can fast-forward.
160
- fast_forward=t
169
preserve=t
170
new_parents=
171
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -f2-)
@@ -182,6 +190,8 @@ pick_one_preserving_merges () {
190
t)
191
output warn "Fast forward to $sha1"
192
test $preserve = f || echo $sha1 > "$REWRITTEN"/$sha1
193
+ output git reset --hard $sha1 ||
194
+ die "Cannot fast forward to $sha1"
195
;;
196
f)
197
test "a$1" = a-n && die "Refusing to squash a merge: $sha1"
t/t3404-rebase-interactive.sh
+6
@@ -202,6 +202,9 @@ test_expect_success 'retain authorship when squashing' '
202
test_expect_success '-p handles "no changes" gracefully' '
203
HEAD=$(git rev-parse HEAD) &&
204
git rebase -i -p HEAD^ &&
205
+ git update-index --refresh &&
206
+ git diff-files --quiet &&
207
+ git diff-index --quiet --cached HEAD -- &&
208
test $HEAD = $(git rev-parse HEAD)
209
'
210
@@ -235,6 +238,9 @@ test_expect_success 'preserve merges with -p' '
238
git checkout -b to-be-rebased &&
239
test_tick &&
240
git rebase -i -p --onto branch1 master &&
241
+ git update-index --refresh &&
242
+ git diff-files --quiet &&
243
+ git diff-index --quiet --cached HEAD -- &&
244
test $(git rev-parse HEAD~6) = $(git rev-parse branch1) &&
245
test $(git rev-parse HEAD~4^2) = $(git rev-parse to-be-preserved) &&
246
test $(git rev-parse HEAD^^2^) = $(git rev-parse HEAD^^^) &&