All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bash: teach __git_ps1 about REVERT_HEAD
@ 2013-03-31  0:30 Robin Rosenberg
  2013-04-01  2:51 ` Junio C Hamano
  2013-04-02 14:20 ` [PATCH 1/2] status: show 'revert' state and status hint Matthieu Moy
  0 siblings, 2 replies; 6+ messages in thread
From: Robin Rosenberg @ 2013-03-31  0:30 UTC (permalink / raw)
  To: git; +Cc: gitster, Robin Rosenberg

Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---
 contrib/completion/git-prompt.sh | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 341422a..756a951 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -282,6 +282,8 @@ __git_ps1 ()
 				r="|MERGING"
 			elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
 				r="|CHERRY-PICKING"
+			elif [ -f "$g/REVERT_HEAD" ]; then
+				r="|REVERTING"
 			elif [ -f "$g/BISECT_LOG" ]; then
 				r="|BISECTING"
 			fi
-- 
1.8.1.337.gf3f86a8

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

* Re: [PATCH] bash: teach __git_ps1 about REVERT_HEAD
  2013-03-31  0:30 [PATCH] bash: teach __git_ps1 about REVERT_HEAD Robin Rosenberg
@ 2013-04-01  2:51 ` Junio C Hamano
  2013-04-02 14:20 ` [PATCH 1/2] status: show 'revert' state and status hint Matthieu Moy
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2013-04-01  2:51 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git

Robin Rosenberg <robin.rosenberg@dewire.com> writes:

> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
> ---
>  contrib/completion/git-prompt.sh | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 341422a..756a951 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -282,6 +282,8 @@ __git_ps1 ()
>  				r="|MERGING"
>  			elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
>  				r="|CHERRY-PICKING"
> +			elif [ -f "$g/REVERT_HEAD" ]; then
> +				r="|REVERTING"

Obviously a good thing to do; thanks.

>  			elif [ -f "$g/BISECT_LOG" ]; then
>  				r="|BISECTING"
>  			fi

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

* [PATCH 1/2] status: show 'revert' state and status hint
  2013-03-31  0:30 [PATCH] bash: teach __git_ps1 about REVERT_HEAD Robin Rosenberg
  2013-04-01  2:51 ` Junio C Hamano
@ 2013-04-02 14:20 ` Matthieu Moy
  2013-04-02 14:20   ` [PATCH 2/2] status: show commit sha1 in "You are currently reverting" message Matthieu Moy
  2013-04-02 20:19   ` [PATCH 1/2] status: show 'revert' state and status hint Junio C Hamano
  1 sibling, 2 replies; 6+ messages in thread
From: Matthieu Moy @ 2013-04-02 14:20 UTC (permalink / raw)
  To: git, gitster; +Cc: Robin Rosenberg, Matthieu Moy

This is the logical equivalent for "git status" of 3ee4452 (bash: teach
__git_ps1 about REVERT_HEAD).

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -282,6 +282,8 @@ __git_ps1 ()
>  				r="|MERGING"
>  			elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
>  				r="|CHERRY-PICKING"
> +			elif [ -f "$g/REVERT_HEAD" ]; then
> +				r="|REVERTING"

Good.

It makes sense to also teach "git status" about REVERT_HEAD.

 t/t7512-status-help.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++
 wt-status.c            | 24 +++++++++++++++++++++
 wt-status.h            |  1 +
 3 files changed, 82 insertions(+)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index 06749a6..d745cf4 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -678,4 +678,61 @@ test_expect_success 'status showing detached from a tag' '
 	test_i18ncmp expected actual
 '
 
+test_expect_success 'status while reverting commit (conflicts)' '
+	git checkout master &&
+	echo before >to-revert.txt &&
+	test_commit before to-revert.txt &&
+	echo old >to-revert.txt &&
+	test_commit old to-revert.txt &&
+	echo new >to-revert.txt &&
+	test_commit new to-revert.txt &&
+	test_must_fail git revert HEAD^ &&
+	cat >expected <<-EOF
+	# On branch master
+	# You are currently reverting a commit.
+	#   (fix conflicts and run "git revert --continue")
+	#   (use "git revert --abort" to cancel the revert operation)
+	#
+	# Unmerged paths:
+	#   (use "git reset HEAD <file>..." to unstage)
+	#   (use "git add <file>..." to mark resolution)
+	#
+	#	both modified:      to-revert.txt
+	#
+	no changes added to commit (use "git add" and/or "git commit -a")
+	EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
+test_expect_success 'status while reverting commit (conflicts resolved)' '
+	echo reverted >to-revert.txt &&
+	git add to-revert.txt &&
+	cat >expected <<-EOF
+	# On branch master
+	# You are currently reverting a commit.
+	#   (all conflicts fixed: run "git revert --continue")
+	#   (use "git revert --abort" to cancel the revert operation)
+	#
+	# Changes to be committed:
+	#   (use "git reset HEAD <file>..." to unstage)
+	#
+	#	modified:   to-revert.txt
+	#
+	# Untracked files not listed (use -u option to show untracked files)
+	EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
+test_expect_success 'status after reverting commit' '
+	git revert --continue &&
+	cat >expected <<-\EOF
+	# On branch master
+	nothing to commit (use -u to show untracked files)
+	EOF
+	git status --untracked-files=no >actual &&
+	test_i18ncmp expected actual
+'
+
 test_done
diff --git a/wt-status.c b/wt-status.c
index cea8e55..5123c71 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -965,6 +965,25 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
 	wt_status_print_trailer(s);
 }
 
+static void show_revert_in_progress(struct wt_status *s,
+					struct wt_status_state *state,
+					const char *color)
+{
+	status_printf_ln(s, color, _("You are currently reverting a commit."));
+	if (advice_status_hints) {
+		if (has_unmerged(s))
+			status_printf_ln(s, color,
+				_("  (fix conflicts and run \"git revert --continue\")"));
+		else
+			status_printf_ln(s, color,
+				_("  (all conflicts fixed: run \"git revert --continue\")"));
+	}
+	if (advice_status_hints)
+		status_printf_ln(s, color,
+			_("  (use \"git revert --abort\" to cancel the revert operation)"));
+	wt_status_print_trailer(s);
+}
+
 static void show_bisect_in_progress(struct wt_status *s,
 				struct wt_status_state *state,
 				const char *color)
@@ -1113,6 +1132,9 @@ void wt_status_get_state(struct wt_status_state *state,
 		state->bisect_in_progress = 1;
 		state->branch = read_and_strip_branch("BISECT_START");
 	}
+	if (!stat(git_path("REVERT_HEAD"), &st)) {
+		state->revert_in_progress = 1;
+	}
 
 	if (get_detached_from)
 		wt_status_get_detached_from(state);
@@ -1130,6 +1152,8 @@ static void wt_status_print_state(struct wt_status *s,
 		show_rebase_in_progress(s, state, state_color);
 	else if (state->cherry_pick_in_progress)
 		show_cherry_pick_in_progress(s, state, state_color);
+	else if (state->revert_in_progress)
+		show_revert_in_progress(s, state, state_color);
 	if (state->bisect_in_progress)
 		show_bisect_in_progress(s, state, state_color);
 }
diff --git a/wt-status.h b/wt-status.h
index be7a016..35cd6cb 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -80,6 +80,7 @@ struct wt_status_state {
 	int rebase_interactive_in_progress;
 	int cherry_pick_in_progress;
 	int bisect_in_progress;
+	int revert_in_progress;
 	char *branch;
 	char *onto;
 	char *detached_from;
-- 
1.8.2.359.g6e2e2c6.dirty

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

* [PATCH 2/2] status: show commit sha1 in "You are currently reverting" message
  2013-04-02 14:20 ` [PATCH 1/2] status: show 'revert' state and status hint Matthieu Moy
@ 2013-04-02 14:20   ` Matthieu Moy
  2013-04-02 20:19   ` [PATCH 1/2] status: show 'revert' state and status hint Junio C Hamano
  1 sibling, 0 replies; 6+ messages in thread
From: Matthieu Moy @ 2013-04-02 14:20 UTC (permalink / raw)
  To: git, gitster; +Cc: Robin Rosenberg, Matthieu Moy

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
---
 t/t7512-status-help.sh | 7 ++++---
 wt-status.c            | 8 ++++++--
 wt-status.h            | 1 +
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh
index d745cf4..bf08d4e 100755
--- a/t/t7512-status-help.sh
+++ b/t/t7512-status-help.sh
@@ -686,10 +686,11 @@ test_expect_success 'status while reverting commit (conflicts)' '
 	test_commit old to-revert.txt &&
 	echo new >to-revert.txt &&
 	test_commit new to-revert.txt &&
-	test_must_fail git revert HEAD^ &&
+	TO_REVERT=$(git rev-parse --short HEAD^) &&
+	test_must_fail git revert $TO_REVERT &&
 	cat >expected <<-EOF
 	# On branch master
-	# You are currently reverting a commit.
+	# You are currently reverting commit $TO_REVERT.
 	#   (fix conflicts and run "git revert --continue")
 	#   (use "git revert --abort" to cancel the revert operation)
 	#
@@ -710,7 +711,7 @@ test_expect_success 'status while reverting commit (conflicts resolved)' '
 	git add to-revert.txt &&
 	cat >expected <<-EOF
 	# On branch master
-	# You are currently reverting a commit.
+	# You are currently reverting commit $TO_REVERT.
 	#   (all conflicts fixed: run "git revert --continue")
 	#   (use "git revert --abort" to cancel the revert operation)
 	#
diff --git a/wt-status.c b/wt-status.c
index 5123c71..e956910 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -969,7 +969,8 @@ static void show_revert_in_progress(struct wt_status *s,
 					struct wt_status_state *state,
 					const char *color)
 {
-	status_printf_ln(s, color, _("You are currently reverting a commit."));
+	status_printf_ln(s, color, _("You are currently reverting commit %s."),
+			 find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
 	if (advice_status_hints) {
 		if (has_unmerged(s))
 			status_printf_ln(s, color,
@@ -1105,6 +1106,7 @@ void wt_status_get_state(struct wt_status_state *state,
 			 int get_detached_from)
 {
 	struct stat st;
+	unsigned char sha1[20];
 
 	if (!stat(git_path("MERGE_HEAD"), &st)) {
 		state->merge_in_progress = 1;
@@ -1132,8 +1134,10 @@ void wt_status_get_state(struct wt_status_state *state,
 		state->bisect_in_progress = 1;
 		state->branch = read_and_strip_branch("BISECT_START");
 	}
-	if (!stat(git_path("REVERT_HEAD"), &st)) {
+	if (!stat(git_path("REVERT_HEAD"), &st) &&
+	    !get_sha1("REVERT_HEAD", sha1)) {
 		state->revert_in_progress = 1;
+		hashcpy(state->revert_head_sha1, sha1);
 	}
 
 	if (get_detached_from)
diff --git a/wt-status.h b/wt-status.h
index 35cd6cb..4121bc2 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -85,6 +85,7 @@ struct wt_status_state {
 	char *onto;
 	char *detached_from;
 	unsigned char detached_sha1[20];
+	unsigned char revert_head_sha1[20];
 };
 
 void wt_status_prepare(struct wt_status *s);
-- 
1.8.2.359.g6e2e2c6.dirty

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

* Re: [PATCH 1/2] status: show 'revert' state and status hint
  2013-04-02 14:20 ` [PATCH 1/2] status: show 'revert' state and status hint Matthieu Moy
  2013-04-02 14:20   ` [PATCH 2/2] status: show commit sha1 in "You are currently reverting" message Matthieu Moy
@ 2013-04-02 20:19   ` Junio C Hamano
  2013-04-02 20:36     ` Matthieu Moy
  1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2013-04-02 20:19 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: git, Robin Rosenberg

Matthieu Moy <Matthieu.Moy@imag.fr> writes:

> +static void show_revert_in_progress(struct wt_status *s,
> +					struct wt_status_state *state,
> +					const char *color)
> +{
> +	status_printf_ln(s, color, _("You are currently reverting a commit."));
> +	if (advice_status_hints) {
> +		if (has_unmerged(s))
> +			status_printf_ln(s, color,
> +				_("  (fix conflicts and run \"git revert --continue\")"));
> +		else
> +			status_printf_ln(s, color,
> +				_("  (all conflicts fixed: run \"git revert --continue\")"));
> +	}
> +	if (advice_status_hints)
> +		status_printf_ln(s, color,
> +			_("  (use \"git revert --abort\" to cancel the revert operation)"));

Why not a single conditional? i.e.

	if (advice_status_hints) {
		if unmerged
			fix and continue
		else
			say continue
		you can also say abort
	}

Will queue on 'pu', with an straight-forward "SQUASH???" on top.

Thanks.

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

* Re: [PATCH 1/2] status: show 'revert' state and status hint
  2013-04-02 20:19   ` [PATCH 1/2] status: show 'revert' state and status hint Junio C Hamano
@ 2013-04-02 20:36     ` Matthieu Moy
  0 siblings, 0 replies; 6+ messages in thread
From: Matthieu Moy @ 2013-04-02 20:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Robin Rosenberg

Junio C Hamano <gitster@pobox.com> writes:

>> +	if (advice_status_hints) {
>> +	}
>> +	if (advice_status_hints)
>> +		status_printf_ln(s, color,
>> +			_("  (use \"git revert --abort\" to cancel the revert operation)"));
>
> Why not a single conditional? i.e.
>
> 	if (advice_status_hints) {
> 		if unmerged
> 			fix and continue
> 		else
> 			say continue
> 		you can also say abort
> 	}

Oops, you're right. I wrote the code mostly with cut-and-past + edit
from other functions, and didn't notice the obvious refactoring
opportunity.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/

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

end of thread, other threads:[~2013-04-02 20:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-31  0:30 [PATCH] bash: teach __git_ps1 about REVERT_HEAD Robin Rosenberg
2013-04-01  2:51 ` Junio C Hamano
2013-04-02 14:20 ` [PATCH 1/2] status: show 'revert' state and status hint Matthieu Moy
2013-04-02 14:20   ` [PATCH 2/2] status: show commit sha1 in "You are currently reverting" message Matthieu Moy
2013-04-02 20:19   ` [PATCH 1/2] status: show 'revert' state and status hint Junio C Hamano
2013-04-02 20:36     ` Matthieu Moy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.