bash-prompt.sh: show where rebase is at when stopped
authorZoltan Klinger <zoltan.klinger@gmail.com>
Thu, 25 Apr 2013 09:28:54 +0000 (19:28 +1000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 25 Apr 2013 16:59:34 +0000 (09:59 -0700)
When a rebase stops (e.g. interrupted by a merge conflict), it could
be useful to know how far a rebase has progressed and how many
commits in total this rebase will apply. Teach the __git_ps1()
command to display the number of commits so far applied and the
total number of commits to be applied, like this:

((3ec0a6a...)|REBASE 2/5)

In the example above the rebase has stopped at the second commit due to
a merge conflict and there are a total number of five commits to be
applied by this rebase.

This information can be already obtained from the following files which are
being generated during the rebase:

GIT_DIR/.git/rebase-merge/msgnum (git-rebase--merge.sh)
GIT_DIR/.git/rebase-merge/end (git-rebase--merge.sh)
GIT_DIR/.git/rebase-apply/next (git-am.sh)
GIT_DIR/.git/rebase-apply/last (git-am.sh)

but "rebase -i" does not leave necessary clues.

Implement this feature by doing these three things:

1) Modify git-rebase--interactive.sh to also create

GIT_DIR/.git/rebase-merge/msgnum
GIT_DIR/.git/rebase-merge/end

files for the number of commits so far applied and the total
number of commits to be applied.

2) Modify git-prompt.sh to read and display info from the above
files.

3) Update test t9903-bash-prompt.sh to reflect changes introduced
by this patch.

Signed-off-by: Zoltan Klinger <zoltan.klinger@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-prompt.sh
git-rebase--interactive.sh
t/t9903-bash-prompt.sh
index 756a9514591c7664c82c93d3a6d50d91f46857d8..eea3568e925a2fce7cc8c65148e4cf771317b532 100644 (file)
@@ -263,14 +263,21 @@ __git_ps1 ()
        else
                local r=""
                local b=""
-               if [ -f "$g/rebase-merge/interactive" ]; then
-                       r="|REBASE-i"
-                       b="$(cat "$g/rebase-merge/head-name")"
-               elif [ -d "$g/rebase-merge" ]; then
-                       r="|REBASE-m"
+               local step=""
+               local total=""
+               if [ -d "$g/rebase-merge" ]; then
                        b="$(cat "$g/rebase-merge/head-name")"
+                       step=$(cat "$g/rebase-merge/msgnum")
+                       total=$(cat "$g/rebase-merge/end")
+                       if [ -f "$g/rebase-merge/interactive" ]; then
+                               r="|REBASE-i"
+                       else
+                               r="|REBASE-m"
+                       fi
                else
                        if [ -d "$g/rebase-apply" ]; then
+                               step=$(cat "$g/rebase-apply/next")
+                               total=$(cat "$g/rebase-apply/last")
                                if [ -f "$g/rebase-apply/rebasing" ]; then
                                        r="|REBASE"
                                elif [ -f "$g/rebase-apply/applying" ]; then
@@ -308,6 +315,10 @@ __git_ps1 ()
                        }
                fi
 
+               if [ -n "$step" ] && [ -n "$total" ]; then
+                       r="$r $step/$total"
+               fi
+
                local w=""
                local i=""
                local s=""
index 048a140a6f6dd565a0d0d98b3b41439298626a96..5822b2c59212fa5bd8dece9261d69e4fbc6a9719 100644 (file)
@@ -57,6 +57,9 @@ rewritten="$state_dir"/rewritten
 
 dropped="$state_dir"/dropped
 
+end="$state_dir"/end
+msgnum="$state_dir"/msgnum
+
 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
 # GIT_AUTHOR_DATE that will be used for the commit that is currently
 # being rebased.
@@ -109,7 +112,9 @@ mark_action_done () {
        sed -e 1d < "$todo" >> "$todo".new
        mv -f "$todo".new "$todo"
        new_count=$(git stripspace --strip-comments <"$done" | wc -l)
+       echo $new_count >"$msgnum"
        total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
+       echo $total >"$end"
        if test "$last_count" != "$new_count"
        then
                last_count=$new_count
index 2101d914f2d34d28b05ce17982a24c0b008809af..c67bbc6be774445f9922481a319b73219a57c01e 100755 (executable)
@@ -28,6 +28,10 @@ test_expect_success 'setup for prompt tests' '
        git checkout -b b2 master &&
        echo 0 > file &&
        git commit -m "second b2" file &&
+       echo 00 > file &&
+       git commit -m "another b2" file &&
+       echo 000 > file &&
+       git commit -m "yet another b2" file &&
        git checkout master
 '
 
@@ -243,10 +247,12 @@ test_expect_success 'prompt - inside bare repository' '
 '
 
 test_expect_success 'prompt - interactive rebase' '
-       printf " (b1|REBASE-i)" > expected
+       printf " (b1|REBASE-i 2/3)" > expected
        echo "#!$SHELL_PATH" >fake_editor.sh &&
        cat >>fake_editor.sh <<\EOF &&
-echo "edit $(git log -1 --format="%h")" > "$1"
+echo "exec echo" > "$1"
+echo "edit $(git log -1 --format="%h")" >> "$1"
+echo "exec echo" >> "$1"
 EOF
        test_when_finished "rm -f fake_editor.sh" &&
        chmod a+x fake_editor.sh &&
@@ -260,7 +266,7 @@ EOF
 '
 
 test_expect_success 'prompt - rebase merge' '
-       printf " (b2|REBASE-m)" > expected &&
+       printf " (b2|REBASE-m 1/3)" > expected &&
        git checkout b2 &&
        test_when_finished "git checkout master" &&
        test_must_fail git rebase --merge b1 b2 &&
@@ -270,7 +276,7 @@ test_expect_success 'prompt - rebase merge' '
 '
 
 test_expect_success 'prompt - rebase' '
-       printf " ((t2)|REBASE)" > expected &&
+       printf " ((t2)|REBASE 1/3)" > expected &&
        git checkout b2 &&
        test_when_finished "git checkout master" &&
        test_must_fail git rebase b1 b2 &&