Skip to content

Commit c54b781

Browse files
dschogitster
authored andcommitted
rebase -i: several cleanups
Support "--verbose" in addition to "-v", show short names in the list comment, clean up if there is nothing to do, and add several "test_ticks" in the test script. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad562a8 commit c54b781

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

git-rebase--interactive.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ die_with_patch () {
6060
die "$2"
6161
}
6262

63+
die_abort () {
64+
rm -rf "$DOTEST"
65+
die "$1"
66+
}
67+
6368
pick_one () {
6469
case "$1" in -n) sha1=$2 ;; *) sha1=$1 ;; esac
6570
git rev-parse --verify $sha1 || die "Invalid commit name: $sha1"
@@ -212,7 +217,7 @@ do
212217
-C*)
213218
die "Interactive rebase uses merge, so $1 does not make sense"
214219
;;
215-
-v)
220+
-v|--verbose)
216221
VERBOSE=t
217222
;;
218223
-i|--interactive)
@@ -264,8 +269,11 @@ do
264269
echo $ONTO > "$DOTEST"/onto
265270
test t = "$VERBOSE" && : > "$DOTEST"/verbose
266271

272+
SHORTUPSTREAM=$(git rev-parse --short $UPSTREAM)
273+
SHORTHEAD=$(git rev-parse --short $HEAD)
274+
SHORTONTO=$(git rev-parse --short $ONTO)
267275
cat > "$TODO" << EOF
268-
# Rebasing $UPSTREAM..$HEAD onto $ONTO
276+
# Rebasing $SHORTUPSTREAM..$SHORTHEAD onto $SHORTONTO
269277
#
270278
# Commands:
271279
# pick = use commit
@@ -277,13 +285,16 @@ EOF
277285
sed "s/^/pick /" >> "$TODO"
278286

279287
test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
280-
die "Nothing to do"
288+
die_abort "Nothing to do"
281289

282290
cp "$TODO" "$TODO".backup
283291
${VISUAL:-${EDITOR:-vi}} "$TODO" ||
284292
die "Could not execute editor"
285293

286-
git reset --hard $ONTO && do_rest
294+
test -z "$(grep -ve '^$' -e '^#' < $TODO)" &&
295+
die_abort "Nothing to do"
296+
297+
git checkout $ONTO && do_rest
287298
esac
288299
shift
289300
done

t/t3404-rebase-interactive.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ test_expect_success 'abort' '
140140
test_expect_success 'retain authorship' '
141141
echo A > file7 &&
142142
git add file7 &&
143+
test_tick &&
143144
GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
144145
git tag twerp &&
145146
git rebase -i --onto master HEAD^ &&
@@ -149,6 +150,7 @@ test_expect_success 'retain authorship' '
149150
test_expect_success 'squash' '
150151
git reset --hard twerp &&
151152
echo B > file7 &&
153+
test_tick &&
152154
GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 &&
153155
echo "******************************" &&
154156
FAKE_LINES="1 squash 2" git rebase -i --onto master HEAD~2 &&

0 commit comments

Comments
 (0)