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 -i anotherbranch", "rebase -i --onto branch",
etc. internally checks out the new fork point.  We will write:

  rebase -i (start): checkout master

instead of the old

  rebase -i (start)

[jc: add rebase-reflog test]

Signed-off-by: Ramkumar Ramachandra <artag...@gmail.com>
Signed-off-by: Junio C Hamano <gits...@pobox.com>
---
 git-rebase--interactive.sh    | 14 ++++++++++----
 t/t3404-rebase-interactive.sh | 15 +++++++++++++++
 2 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index f953d8d..8429c87 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -95,12 +95,15 @@ commit_message () {
        git cat-file commit "$1" | sed "1,/^$/d"
 }
 
-orig_reflog_action="$GIT_REFLOG_ACTION"
+base_reflog_action="$GIT_REFLOG_ACTION"
 
 comment_for_reflog () {
-       case "$orig_reflog_action" in
+       case "$base_reflog_action" in
+       # if GIT_REFLOG_ACTION was set by caller git-rebase, overwrite
+       # it with rebase -i.
        ''|rebase*)
                GIT_REFLOG_ACTION="rebase -i ($1)"
+               base_reflog_action="$GIT_REFLOG_ACTION"
                export GIT_REFLOG_ACTION
                ;;
        esac
@@ -326,6 +329,7 @@ pick_one_preserving_merges () {
                if [ "$1" != "-n" ]
                then
                        # detach HEAD to current parent
+                       GIT_REFLOG_ACTION="$base_reflog_action: checkout 
$first_parent"
                        output git checkout $first_parent 2> /dev/null ||
                                die "Cannot move HEAD to $first_parent"
                fi
@@ -608,10 +612,10 @@ do_next () {
        newhead=$(git rev-parse HEAD) &&
        case $head_name in
        refs/*)
-               message="$GIT_REFLOG_ACTION: $head_name onto $onto" &&
+               message="$base_reflog_action: $head_name onto $onto" &&
                git update-ref -m "$message" $head_name $newhead $orig_head &&
                git symbolic-ref \
-                 -m "$GIT_REFLOG_ACTION: returning to $head_name" \
+                 -m "$base_reflog_action: returning to $head_name" \
                  HEAD $head_name
                ;;
        esac && {
@@ -838,6 +842,7 @@ comment_for_reflog start
 
 if test ! -z "$switch_to"
 then
+       GIT_REFLOG_ACTION="$base_reflog_action: checkout $switch_to"
        output git checkout "$switch_to" -- ||
                die "Could not checkout $switch_to"
 fi
@@ -981,6 +986,7 @@ has_action "$todo" ||
 
 test -d "$rewritten" || test -n "$force_rebase" || skip_unnecessary_picks
 
+GIT_REFLOG_ACTION="$base_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 79e8d3c..f7d0147 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 branch1 H &&
+       git rebase -i --onto I F branch1 &&
+       cat >expect <<-\EOF &&
+       rebase -i (start): checkout I
+       rebase -i (pick): G
+       rebase -i (pick): H
+       rebase -i (finish): returning to refs/heads/branch1
+       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 &&
-- 
1.8.3.1.455.g5932b31

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to