git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict
@ 2013-04-23 12:35 Zoltan Klinger
  2013-04-23 15:08 ` Junio C Hamano
  2013-04-24  7:05 ` Eric Sunshine
  0 siblings, 2 replies; 4+ messages in thread
From: Zoltan Klinger @ 2013-04-23 12:35 UTC (permalink / raw)
  To: git; +Cc: felipe.contreras, Zoltan Klinger

When a rebase is 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.

Below is a sample output of the improved __git_ps1() command:
  ((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 alredy 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)

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>
---
 contrib/completion/git-prompt.sh |   21 ++++++++++++++++-----
 git-rebase--interactive.sh       |    5 +++++
 t/t9903-bash-prompt.sh           |    6 +++---
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 756a951..49f7742 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -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=""
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 048a140..f76ff8f 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -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
diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
index e147a8d..2f8f9ab 100755
--- a/t/t9903-bash-prompt.sh
+++ b/t/t9903-bash-prompt.sh
@@ -243,7 +243,7 @@ test_expect_success 'prompt - inside bare repository' '
 '
 
 test_expect_success 'prompt - interactive rebase' '
-	printf " (b1|REBASE-i)" > expected
+	printf " (b1|REBASE-i|1/1)" > expected
 	echo "#!$SHELL_PATH" >fake_editor.sh &&
 	cat >>fake_editor.sh <<\EOF &&
 echo "edit $(git log -1 --format="%h")" > "$1"
@@ -260,7 +260,7 @@ EOF
 '
 
 test_expect_success 'prompt - rebase merge' '
-	printf " (b2|REBASE-m)" > expected &&
+	printf " (b2|REBASE-m|1/1)" > expected &&
 	git checkout b2 &&
 	test_when_finished "git checkout master" &&
 	test_must_fail git rebase --merge b1 b2 &&
@@ -270,7 +270,7 @@ test_expect_success 'prompt - rebase merge' '
 '
 
 test_expect_success 'prompt - rebase' '
-	printf " ((t2)|REBASE)" > expected &&
+	printf " ((t2)|REBASE|1/1)" > expected &&
 	git checkout b2 &&
 	test_when_finished "git checkout master" &&
 	test_must_fail git rebase b1 b2 &&
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict
  2013-04-23 12:35 [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict Zoltan Klinger
@ 2013-04-23 15:08 ` Junio C Hamano
  2013-04-24  7:14   ` Felipe Contreras
  2013-04-24  7:05 ` Eric Sunshine
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2013-04-23 15:08 UTC (permalink / raw)
  To: Zoltan Klinger; +Cc: git, felipe.contreras, SZEDER Gábor

Zoltan Klinger <zoltan.klinger@gmail.com> writes:

> When a rebase is 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.
>
> Below is a sample output of the improved __git_ps1() command:
>   ((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 alredy 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)
>
> 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>
> ---

Nicely explained.  Felipe?  Szeder?  Comments?

>  contrib/completion/git-prompt.sh |   21 ++++++++++++++++-----
>  git-rebase--interactive.sh       |    5 +++++
>  t/t9903-bash-prompt.sh           |    6 +++---
>  3 files changed, 24 insertions(+), 8 deletions(-)
> ...
> -	printf " (b1|REBASE-i)" > expected
> +	printf " (b1|REBASE-i|1/1)" > expected

This makes me wonder if " (b1|REBASE-i 1/1)" may be easier on the
eyes.  Also it may not be a bad idea to add a new piece to this test
to show the state that is not "1/1" but something else.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict
  2013-04-23 12:35 [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict Zoltan Klinger
  2013-04-23 15:08 ` Junio C Hamano
@ 2013-04-24  7:05 ` Eric Sunshine
  1 sibling, 0 replies; 4+ messages in thread
From: Eric Sunshine @ 2013-04-24  7:05 UTC (permalink / raw)
  To: Zoltan Klinger; +Cc: Git List, Felipe Contreras

On Tue, Apr 23, 2013 at 8:35 AM, Zoltan Klinger
<zoltan.klinger@gmail.com> wrote:
> When a rebase is 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.
>
> Below is a sample output of the improved __git_ps1() command:
>   ((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 alredy obtained from the following files which are

s/alredy/already/

> 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)
>
> 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>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict
  2013-04-23 15:08 ` Junio C Hamano
@ 2013-04-24  7:14   ` Felipe Contreras
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Contreras @ 2013-04-24  7:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Zoltan Klinger, git, SZEDER Gábor

On Tue, Apr 23, 2013 at 10:08 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Zoltan Klinger <zoltan.klinger@gmail.com> writes:
>
>> When a rebase is 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.
>>
>> Below is a sample output of the improved __git_ps1() command:
>>   ((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 alredy 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)
>>
>> 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>
>> ---
>
> Nicely explained.  Felipe?  Szeder?  Comments?

Looks good to me.

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-04-24  7:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-23 12:35 [PATCH] git-prompt.sh: Show where rebase is at when interrupted by a merge conflict Zoltan Klinger
2013-04-23 15:08 ` Junio C Hamano
2013-04-24  7:14   ` Felipe Contreras
2013-04-24  7:05 ` Eric Sunshine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).