bash-prompt.sh: show where rebase is at when stopped

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>

Zoltan Klinger committed Apr 25, 2013 at 19:28 UTC b71dc3e1a04666fae4a4e282973d9b5a122a997c
3 files changed +31 -9
contrib/completion/git-prompt.sh
+16 -5
@@ -263,14 +263,21 @@ __git_ps1 ()
263 else
264 local r=""
265 local b=""
266 - if [ -f "$g/rebase-merge/interactive" ]; then
267 - r="|REBASE-i"
268 - b="$(cat "$g/rebase-merge/head-name")"
269 - elif [ -d "$g/rebase-merge" ]; then
270 - r="|REBASE-m"
266 + local step=""
267 + local total=""
268 + if [ -d "$g/rebase-merge" ]; then
269 b="$(cat "$g/rebase-merge/head-name")"
270 + step=$(cat "$g/rebase-merge/msgnum")
271 + total=$(cat "$g/rebase-merge/end")
272 + if [ -f "$g/rebase-merge/interactive" ]; then
273 + r="|REBASE-i"
274 + else
275 + r="|REBASE-m"
276 + fi
277 else
278 if [ -d "$g/rebase-apply" ]; then
279 + step=$(cat "$g/rebase-apply/next")
280 + total=$(cat "$g/rebase-apply/last")
281 if [ -f "$g/rebase-apply/rebasing" ]; then
282 r="|REBASE"
283 elif [ -f "$g/rebase-apply/applying" ]; then
@@ -308,6 +315,10 @@ __git_ps1 ()
315 }
316 fi
317
318 + if [ -n "$step" ] && [ -n "$total" ]; then
319 + r="$r $step/$total"
320 + fi
321 +
322 local w=""
323 local i=""
324 local s=""
git-rebase--interactive.sh
+5
@@ -57,6 +57,9 @@ rewritten="$state_dir"/rewritten
57
58 dropped="$state_dir"/dropped
59
60 +end="$state_dir"/end
61 +msgnum="$state_dir"/msgnum
62 +
63 # A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
64 # GIT_AUTHOR_DATE that will be used for the commit that is currently
65 # being rebased.
@@ -109,7 +112,9 @@ mark_action_done () {
112 sed -e 1d < "$todo" >> "$todo".new
113 mv -f "$todo".new "$todo"
114 new_count=$(git stripspace --strip-comments <"$done" | wc -l)
115 + echo $new_count >"$msgnum"
116 total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
117 + echo $total >"$end"
118 if test "$last_count" != "$new_count"
119 then
120 last_count=$new_count
t/t9903-bash-prompt.sh
+10 -4
@@ -28,6 +28,10 @@ test_expect_success 'setup for prompt tests' '
28 git checkout -b b2 master &&
29 echo 0 > file &&
30 git commit -m "second b2" file &&
31 + echo 00 > file &&
32 + git commit -m "another b2" file &&
33 + echo 000 > file &&
34 + git commit -m "yet another b2" file &&
35 git checkout master
36 '
37
@@ -243,10 +247,12 @@ test_expect_success 'prompt - inside bare repository' '
247 '
248
249 test_expect_success 'prompt - interactive rebase' '
246 - printf " (b1|REBASE-i)" > expected
250 + printf " (b1|REBASE-i 2/3)" > expected
251 echo "#!$SHELL_PATH" >fake_editor.sh &&
252 cat >>fake_editor.sh <<\EOF &&
249 -echo "edit $(git log -1 --format="%h")" > "$1"
253 +echo "exec echo" > "$1"
254 +echo "edit $(git log -1 --format="%h")" >> "$1"
255 +echo "exec echo" >> "$1"
256 EOF
257 test_when_finished "rm -f fake_editor.sh" &&
258 chmod a+x fake_editor.sh &&
@@ -260,7 +266,7 @@ EOF
266 '
267
268 test_expect_success 'prompt - rebase merge' '
263 - printf " (b2|REBASE-m)" > expected &&
269 + printf " (b2|REBASE-m 1/3)" > expected &&
270 git checkout b2 &&
271 test_when_finished "git checkout master" &&
272 test_must_fail git rebase --merge b1 b2 &&
@@ -270,7 +276,7 @@ test_expect_success 'prompt - rebase merge' '
276 '
277
278 test_expect_success 'prompt - rebase' '
273 - printf " ((t2)|REBASE)" > expected &&
279 + printf " ((t2)|REBASE 1/3)" > expected &&
280 git checkout b2 &&
281 test_when_finished "git checkout master" &&
282 test_must_fail git rebase b1 b2 &&