Skip to content

Commit 26cd160

Browse files
artagnongitster
authored andcommitted
rebase -i: use a better reflog message
Now that the "checkout" invoked internally from "rebase -i" knows to honor GIT_REFLOG_ACTION, we can start to use it to write a better reflog message when "rebase anotherbranch", "rebase --onto branch", etc. internally checks out the new fork point. We will write: rebase -i: checkout master instead of the old rebase -i As all the calls git-rebase--interactive make to underlying git commands that leave reflog messages are preceded by the internal comment_for_reflog helper function, which uses the original value of the GIT_REFLOG_ACTION variable it saw when it first started, the new assignments to GIT_REFLOG_ACTION actively contaminate the value of the variable, knowing that it will be reset to a sane value before it is used again. This does not generally hold true but it should suffice for now. Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4b03df2 commit 26cd160

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

git-rebase--interactive.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,11 @@ comment_for_reflog start
837837

838838
if test ! -z "$switch_to"
839839
then
840+
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
840841
output git checkout "$switch_to" -- ||
841-
die "Could not checkout $switch_to"
842+
die "Could not checkout $switch_to"
843+
844+
comment_for_reflog start
842845
fi
843846

844847
orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?"
@@ -980,6 +983,7 @@ has_action "$todo" ||
980983

981984
test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
982985

986+
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
983987
output git checkout $onto || die_abort "could not detach HEAD"
984988
git update-ref ORIG_HEAD $orig_head
985989
do_rest

t/t3404-rebase-interactive.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,21 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' '
934934
test L = $(git cat-file commit HEAD | sed -ne \$p)
935935
'
936936

937+
test_expect_success 'rebase -i produces readable reflog' '
938+
git reset --hard &&
939+
git branch -f branch-reflog-test H &&
940+
git rebase -i --onto I F branch-reflog-test &&
941+
cat >expect <<-\EOF &&
942+
rebase -i (start): checkout I
943+
rebase -i (pick): G
944+
rebase -i (pick): H
945+
rebase -i (finish): returning to refs/heads/branch-reflog-test
946+
EOF
947+
tail -n 4 .git/logs/HEAD |
948+
sed -e "s/.* //" >actual &&
949+
test_cmp expect actual
950+
'
951+
937952
test_expect_success 'rebase -i respects core.commentchar' '
938953
git reset --hard &&
939954
git checkout E^0 &&

0 commit comments

Comments
 (0)