Skip to content

Commit b9347eb

Browse files
committed
Merge branch 'zk/prompt-rebase-step'
* zk/prompt-rebase-step: bash-prompt.sh: show where rebase is at when stopped
2 parents 7e6a0cc + b71dc3e commit b9347eb

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

contrib/completion/git-prompt.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,21 @@ __git_ps1 ()
263263
else
264264
local r=""
265265
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
271269
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
272277
else
273278
if [ -d "$g/rebase-apply" ]; then
279+
step=$(cat "$g/rebase-apply/next")
280+
total=$(cat "$g/rebase-apply/last")
274281
if [ -f "$g/rebase-apply/rebasing" ]; then
275282
r="|REBASE"
276283
elif [ -f "$g/rebase-apply/applying" ]; then
@@ -308,6 +315,10 @@ __git_ps1 ()
308315
}
309316
fi
310317

318+
if [ -n "$step" ] && [ -n "$total" ]; then
319+
r="$r $step/$total"
320+
fi
321+
311322
local w=""
312323
local i=""
313324
local s=""

git-rebase--interactive.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ rewritten="$state_dir"/rewritten
5757

5858
dropped="$state_dir"/dropped
5959

60+
end="$state_dir"/end
61+
msgnum="$state_dir"/msgnum
62+
6063
# A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
6164
# GIT_AUTHOR_DATE that will be used for the commit that is currently
6265
# being rebased.
@@ -109,7 +112,9 @@ mark_action_done () {
109112
sed -e 1d < "$todo" >> "$todo".new
110113
mv -f "$todo".new "$todo"
111114
new_count=$(git stripspace --strip-comments <"$done" | wc -l)
115+
echo $new_count >"$msgnum"
112116
total=$(($new_count + $(git stripspace --strip-comments <"$todo" | wc -l)))
117+
echo $total >"$end"
113118
if test "$last_count" != "$new_count"
114119
then
115120
last_count=$new_count

t/t9903-bash-prompt.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ test_expect_success 'setup for prompt tests' '
2828
git checkout -b b2 master &&
2929
echo 0 > file &&
3030
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 &&
3135
git checkout master
3236
'
3337

@@ -243,10 +247,12 @@ test_expect_success 'prompt - inside bare repository' '
243247
'
244248

245249
test_expect_success 'prompt - interactive rebase' '
246-
printf " (b1|REBASE-i)" > expected
250+
printf " (b1|REBASE-i 2/3)" > expected
247251
echo "#!$SHELL_PATH" >fake_editor.sh &&
248252
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"
250256
EOF
251257
test_when_finished "rm -f fake_editor.sh" &&
252258
chmod a+x fake_editor.sh &&
@@ -260,7 +266,7 @@ EOF
260266
'
261267

262268
test_expect_success 'prompt - rebase merge' '
263-
printf " (b2|REBASE-m)" > expected &&
269+
printf " (b2|REBASE-m 1/3)" > expected &&
264270
git checkout b2 &&
265271
test_when_finished "git checkout master" &&
266272
test_must_fail git rebase --merge b1 b2 &&
@@ -270,7 +276,7 @@ test_expect_success 'prompt - rebase merge' '
270276
'
271277

272278
test_expect_success 'prompt - rebase' '
273-
printf " ((t2)|REBASE)" > expected &&
279+
printf " ((t2)|REBASE 1/3)" > expected &&
274280
git checkout b2 &&
275281
test_when_finished "git checkout master" &&
276282
test_must_fail git rebase b1 b2 &&

0 commit comments

Comments
 (0)