From 4b03df210f77ac84ebed324c5d031f32872aaf0b Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Sun, 16 Jun 2013 14:15:12 +0530 Subject: [PATCH 1/2] rebase: use a better reflog message Now that the "checkout" invoked internally from "rebase" 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: checkout master instead of the old rebase Signed-off-by: Ramkumar Ramachandra Signed-off-by: Junio C Hamano --- git-rebase.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/git-rebase.sh b/git-rebase.sh index 2c692c33e..79f526eb9 100755 --- a/git-rebase.sh +++ b/git-rebase.sh @@ -497,7 +497,9 @@ then if test -z "$force_rebase" then # Lazily switch to the target branch if needed... - test -z "$switch_to" || git checkout "$switch_to" -- + test -z "$switch_to" || + GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" \ + git checkout "$switch_to" -- say "$(eval_gettext "Current branch \$branch_name is up to date.")" exit 0 else @@ -522,7 +524,9 @@ test "$type" = interactive && run_specific_rebase # Detach HEAD and reset the tree say "$(gettext "First, rewinding head to replay your work on top of it...")" -git checkout -q "$onto^0" || die "could not detach HEAD" + +GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" \ + git checkout -q "$onto^0" || die "could not detach HEAD" git update-ref ORIG_HEAD $orig_head # If the $onto is a proper descendant of the tip of the branch, then From 26cd160cb15635afd1c2937a3c15cfb256758323 Mon Sep 17 00:00:00 2001 From: Ramkumar Ramachandra Date: Sun, 16 Jun 2013 14:15:13 +0530 Subject: [PATCH 2/2] 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 Signed-off-by: Junio C Hamano --- git-rebase--interactive.sh | 6 +++++- t/t3404-rebase-interactive.sh | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh index 5822b2c59..a97552935 100644 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@ -837,8 +837,11 @@ comment_for_reflog start if test ! -z "$switch_to" then + GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to" output git checkout "$switch_to" -- || - die "Could not checkout $switch_to" + die "Could not checkout $switch_to" + + comment_for_reflog start fi orig_head=$(git rev-parse --verify HEAD) || die "No HEAD?" @@ -980,6 +983,7 @@ has_action "$todo" || test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks +GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name" output git checkout $onto || die_abort "could not detach HEAD" git update-ref ORIG_HEAD $orig_head do_rest diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index a58406d12..971e21414 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -934,6 +934,21 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' ' test L = $(git cat-file commit HEAD | sed -ne \$p) ' +test_expect_success 'rebase -i produces readable reflog' ' + git reset --hard && + git branch -f branch-reflog-test H && + git rebase -i --onto I F branch-reflog-test && + cat >expect <<-\EOF && + rebase -i (start): checkout I + rebase -i (pick): G + rebase -i (pick): H + rebase -i (finish): returning to refs/heads/branch-reflog-test + EOF + tail -n 4 .git/logs/HEAD | + sed -e "s/.* //" >actual && + test_cmp expect actual +' + test_expect_success 'rebase -i respects core.commentchar' ' git reset --hard && git checkout E^0 &&