{"thread":{"id":"33337","subject":"[PATCH] bash: teach __git_ps1 about REVERT_HEAD","startedAt":"2013-03-31T00:30:48Z","lastAt":"2013-04-02T20:36:20Z","messageCount":6,"participants":["Robin Rosenberg","Junio C Hamano","Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"212712","messageId":"1364689848-52647-1-git-send-email-robin.rosenberg@dewire.com","threadId":"33337","inReplyTo":null,"subject":"[PATCH] bash: teach __git_ps1 about REVERT_HEAD","fromName":"Robin Rosenberg","fromEmail":"robin.rosenberg@dewire.com","sentAt":"2013-03-31T00:30:48Z","receivedAt":"2013-03-31T00:30:48Z","isPatch":true,"sender":{"key":"robin.rosenberg@dewire.com","avatar":"https://avatars.githubusercontent.com/u/46357?v=4"},"body":"Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n---\n contrib/completion/git-prompt.sh | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 341422a..756a951 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -282,6 +282,8 @@ __git_ps1 ()\n \t\t\t\tr=\"|MERGING\"\n \t\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n \t\t\t\tr=\"|CHERRY-PICKING\"\n+\t\t\telif [ -f \"$g/REVERT_HEAD\" ]; then\n+\t\t\t\tr=\"|REVERTING\"\n \t\t\telif [ -f \"$g/BISECT_LOG\" ]; then\n \t\t\t\tr=\"|BISECTING\"\n \t\t\tfi\n-- \n1.8.1.337.gf3f86a8\n"},{"id":"212773","messageId":"7vk3onm08z.fsf@alter.siamese.dyndns.org","threadId":"33337","inReplyTo":"1364689848-52647-1-git-send-email-robin.rosenberg@dewire.com","subject":"Re: [PATCH] bash: teach __git_ps1 about REVERT_HEAD","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-01T02:51:40Z","receivedAt":"2013-04-01T02:51:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Robin Rosenberg <robin.rosenberg@dewire.com> writes:\n\n> Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>\n> ---\n>  contrib/completion/git-prompt.sh | 2 ++\n>  1 file changed, 2 insertions(+)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 341422a..756a951 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -282,6 +282,8 @@ __git_ps1 ()\n>  \t\t\t\tr=\"|MERGING\"\n>  \t\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n>  \t\t\t\tr=\"|CHERRY-PICKING\"\n> +\t\t\telif [ -f \"$g/REVERT_HEAD\" ]; then\n> +\t\t\t\tr=\"|REVERTING\"\n\nObviously a good thing to do; thanks.\n\n>  \t\t\telif [ -f \"$g/BISECT_LOG\" ]; then\n>  \t\t\t\tr=\"|BISECTING\"\n>  \t\t\tfi\n"},{"id":"212880","messageId":"1364912422-29536-1-git-send-email-Matthieu.Moy@imag.fr","threadId":"33337","inReplyTo":"1364689848-52647-1-git-send-email-robin.rosenberg@dewire.com","subject":"[PATCH 1/2] status: show 'revert' state and status hint","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2013-04-02T14:20:21Z","receivedAt":"2013-04-02T14:20:21Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"This is the logical equivalent for \"git status\" of 3ee4452 (bash: teach\n__git_ps1 about REVERT_HEAD).\n\nSigned-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -282,6 +282,8 @@ __git_ps1 ()\n>  \t\t\t\tr=\"|MERGING\"\n>  \t\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n>  \t\t\t\tr=\"|CHERRY-PICKING\"\n> +\t\t\telif [ -f \"$g/REVERT_HEAD\" ]; then\n> +\t\t\t\tr=\"|REVERTING\"\n\nGood.\n\nIt makes sense to also teach \"git status\" about REVERT_HEAD.\n\n t/t7512-status-help.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++\n wt-status.c            | 24 +++++++++++++++++++++\n wt-status.h            |  1 +\n 3 files changed, 82 insertions(+)\n\ndiff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh\nindex 06749a6..d745cf4 100755\n--- a/t/t7512-status-help.sh\n+++ b/t/t7512-status-help.sh\n@@ -678,4 +678,61 @@ test_expect_success 'status showing detached from a tag' '\n \ttest_i18ncmp expected actual\n '\n \n+test_expect_success 'status while reverting commit (conflicts)' '\n+\tgit checkout master &&\n+\techo before >to-revert.txt &&\n+\ttest_commit before to-revert.txt &&\n+\techo old >to-revert.txt &&\n+\ttest_commit old to-revert.txt &&\n+\techo new >to-revert.txt &&\n+\ttest_commit new to-revert.txt &&\n+\ttest_must_fail git revert HEAD^ &&\n+\tcat >expected <<-EOF\n+\t# On branch master\n+\t# You are currently reverting a commit.\n+\t#   (fix conflicts and run \"git revert --continue\")\n+\t#   (use \"git revert --abort\" to cancel the revert operation)\n+\t#\n+\t# Unmerged paths:\n+\t#   (use \"git reset HEAD <file>...\" to unstage)\n+\t#   (use \"git add <file>...\" to mark resolution)\n+\t#\n+\t#\tboth modified:      to-revert.txt\n+\t#\n+\tno changes added to commit (use \"git add\" and/or \"git commit -a\")\n+\tEOF\n+\tgit status --untracked-files=no >actual &&\n+\ttest_i18ncmp expected actual\n+'\n+\n+test_expect_success 'status while reverting commit (conflicts resolved)' '\n+\techo reverted >to-revert.txt &&\n+\tgit add to-revert.txt &&\n+\tcat >expected <<-EOF\n+\t# On branch master\n+\t# You are currently reverting a commit.\n+\t#   (all conflicts fixed: run \"git revert --continue\")\n+\t#   (use \"git revert --abort\" to cancel the revert operation)\n+\t#\n+\t# Changes to be committed:\n+\t#   (use \"git reset HEAD <file>...\" to unstage)\n+\t#\n+\t#\tmodified:   to-revert.txt\n+\t#\n+\t# Untracked files not listed (use -u option to show untracked files)\n+\tEOF\n+\tgit status --untracked-files=no >actual &&\n+\ttest_i18ncmp expected actual\n+'\n+\n+test_expect_success 'status after reverting commit' '\n+\tgit revert --continue &&\n+\tcat >expected <<-\\EOF\n+\t# On branch master\n+\tnothing to commit (use -u to show untracked files)\n+\tEOF\n+\tgit status --untracked-files=no >actual &&\n+\ttest_i18ncmp expected actual\n+'\n+\n test_done\ndiff --git a/wt-status.c b/wt-status.c\nindex cea8e55..5123c71 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -965,6 +965,25 @@ static void show_cherry_pick_in_progress(struct wt_status *s,\n \twt_status_print_trailer(s);\n }\n \n+static void show_revert_in_progress(struct wt_status *s,\n+\t\t\t\t\tstruct wt_status_state *state,\n+\t\t\t\t\tconst char *color)\n+{\n+\tstatus_printf_ln(s, color, _(\"You are currently reverting a commit.\"));\n+\tif (advice_status_hints) {\n+\t\tif (has_unmerged(s))\n+\t\t\tstatus_printf_ln(s, color,\n+\t\t\t\t_(\"  (fix conflicts and run \\\"git revert --continue\\\")\"));\n+\t\telse\n+\t\t\tstatus_printf_ln(s, color,\n+\t\t\t\t_(\"  (all conflicts fixed: run \\\"git revert --continue\\\")\"));\n+\t}\n+\tif (advice_status_hints)\n+\t\tstatus_printf_ln(s, color,\n+\t\t\t_(\"  (use \\\"git revert --abort\\\" to cancel the revert operation)\"));\n+\twt_status_print_trailer(s);\n+}\n+\n static void show_bisect_in_progress(struct wt_status *s,\n \t\t\t\tstruct wt_status_state *state,\n \t\t\t\tconst char *color)\n@@ -1113,6 +1132,9 @@ void wt_status_get_state(struct wt_status_state *state,\n \t\tstate->bisect_in_progress = 1;\n \t\tstate->branch = read_and_strip_branch(\"BISECT_START\");\n \t}\n+\tif (!stat(git_path(\"REVERT_HEAD\"), &st)) {\n+\t\tstate->revert_in_progress = 1;\n+\t}\n \n \tif (get_detached_from)\n \t\twt_status_get_detached_from(state);\n@@ -1130,6 +1152,8 @@ static void wt_status_print_state(struct wt_status *s,\n \t\tshow_rebase_in_progress(s, state, state_color);\n \telse if (state->cherry_pick_in_progress)\n \t\tshow_cherry_pick_in_progress(s, state, state_color);\n+\telse if (state->revert_in_progress)\n+\t\tshow_revert_in_progress(s, state, state_color);\n \tif (state->bisect_in_progress)\n \t\tshow_bisect_in_progress(s, state, state_color);\n }\ndiff --git a/wt-status.h b/wt-status.h\nindex be7a016..35cd6cb 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -80,6 +80,7 @@ struct wt_status_state {\n \tint rebase_interactive_in_progress;\n \tint cherry_pick_in_progress;\n \tint bisect_in_progress;\n+\tint revert_in_progress;\n \tchar *branch;\n \tchar *onto;\n \tchar *detached_from;\n-- \n1.8.2.359.g6e2e2c6.dirty\n"},{"id":"212878","messageId":"1364912422-29536-2-git-send-email-Matthieu.Moy@imag.fr","threadId":"33337","inReplyTo":"1364912422-29536-1-git-send-email-Matthieu.Moy@imag.fr","subject":"[PATCH 2/2] status: show commit sha1 in \"You are currently reverting\" message","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2013-04-02T14:20:22Z","receivedAt":"2013-04-02T14:20:22Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>\n---\n t/t7512-status-help.sh | 7 ++++---\n wt-status.c            | 8 ++++++--\n wt-status.h            | 1 +\n 3 files changed, 11 insertions(+), 5 deletions(-)\n\ndiff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh\nindex d745cf4..bf08d4e 100755\n--- a/t/t7512-status-help.sh\n+++ b/t/t7512-status-help.sh\n@@ -686,10 +686,11 @@ test_expect_success 'status while reverting commit (conflicts)' '\n \ttest_commit old to-revert.txt &&\n \techo new >to-revert.txt &&\n \ttest_commit new to-revert.txt &&\n-\ttest_must_fail git revert HEAD^ &&\n+\tTO_REVERT=$(git rev-parse --short HEAD^) &&\n+\ttest_must_fail git revert $TO_REVERT &&\n \tcat >expected <<-EOF\n \t# On branch master\n-\t# You are currently reverting a commit.\n+\t# You are currently reverting commit $TO_REVERT.\n \t#   (fix conflicts and run \"git revert --continue\")\n \t#   (use \"git revert --abort\" to cancel the revert operation)\n \t#\n@@ -710,7 +711,7 @@ test_expect_success 'status while reverting commit (conflicts resolved)' '\n \tgit add to-revert.txt &&\n \tcat >expected <<-EOF\n \t# On branch master\n-\t# You are currently reverting a commit.\n+\t# You are currently reverting commit $TO_REVERT.\n \t#   (all conflicts fixed: run \"git revert --continue\")\n \t#   (use \"git revert --abort\" to cancel the revert operation)\n \t#\ndiff --git a/wt-status.c b/wt-status.c\nindex 5123c71..e956910 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -969,7 +969,8 @@ static void show_revert_in_progress(struct wt_status *s,\n \t\t\t\t\tstruct wt_status_state *state,\n \t\t\t\t\tconst char *color)\n {\n-\tstatus_printf_ln(s, color, _(\"You are currently reverting a commit.\"));\n+\tstatus_printf_ln(s, color, _(\"You are currently reverting commit %s.\"),\n+\t\t\t find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));\n \tif (advice_status_hints) {\n \t\tif (has_unmerged(s))\n \t\t\tstatus_printf_ln(s, color,\n@@ -1105,6 +1106,7 @@ void wt_status_get_state(struct wt_status_state *state,\n \t\t\t int get_detached_from)\n {\n \tstruct stat st;\n+\tunsigned char sha1[20];\n \n \tif (!stat(git_path(\"MERGE_HEAD\"), &st)) {\n \t\tstate->merge_in_progress = 1;\n@@ -1132,8 +1134,10 @@ void wt_status_get_state(struct wt_status_state *state,\n \t\tstate->bisect_in_progress = 1;\n \t\tstate->branch = read_and_strip_branch(\"BISECT_START\");\n \t}\n-\tif (!stat(git_path(\"REVERT_HEAD\"), &st)) {\n+\tif (!stat(git_path(\"REVERT_HEAD\"), &st) &&\n+\t    !get_sha1(\"REVERT_HEAD\", sha1)) {\n \t\tstate->revert_in_progress = 1;\n+\t\thashcpy(state->revert_head_sha1, sha1);\n \t}\n \n \tif (get_detached_from)\ndiff --git a/wt-status.h b/wt-status.h\nindex 35cd6cb..4121bc2 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -85,6 +85,7 @@ struct wt_status_state {\n \tchar *onto;\n \tchar *detached_from;\n \tunsigned char detached_sha1[20];\n+\tunsigned char revert_head_sha1[20];\n };\n \n void wt_status_prepare(struct wt_status *s);\n-- \n1.8.2.359.g6e2e2c6.dirty\n"},{"id":"212984","messageId":"7vobdwbs86.fsf@alter.siamese.dyndns.org","threadId":"33337","inReplyTo":"1364912422-29536-1-git-send-email-Matthieu.Moy@imag.fr","subject":"Re: [PATCH 1/2] status: show 'revert' state and status hint","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-02T20:19:37Z","receivedAt":"2013-04-02T20:19:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Matthieu Moy <Matthieu.Moy@imag.fr> writes:\n\n> +static void show_revert_in_progress(struct wt_status *s,\n> +\t\t\t\t\tstruct wt_status_state *state,\n> +\t\t\t\t\tconst char *color)\n> +{\n> +\tstatus_printf_ln(s, color, _(\"You are currently reverting a commit.\"));\n> +\tif (advice_status_hints) {\n> +\t\tif (has_unmerged(s))\n> +\t\t\tstatus_printf_ln(s, color,\n> +\t\t\t\t_(\"  (fix conflicts and run \\\"git revert --continue\\\")\"));\n> +\t\telse\n> +\t\t\tstatus_printf_ln(s, color,\n> +\t\t\t\t_(\"  (all conflicts fixed: run \\\"git revert --continue\\\")\"));\n> +\t}\n> +\tif (advice_status_hints)\n> +\t\tstatus_printf_ln(s, color,\n> +\t\t\t_(\"  (use \\\"git revert --abort\\\" to cancel the revert operation)\"));\n\nWhy not a single conditional? i.e.\n\n\tif (advice_status_hints) {\n\t\tif unmerged\n\t\t\tfix and continue\n\t\telse\n\t\t\tsay continue\n\t\tyou can also say abort\n\t}\n\nWill queue on 'pu', with an straight-forward \"SQUASH???\" on top.\n\nThanks.\n"},{"id":"212988","messageId":"vpqr4isd60r.fsf@grenoble-inp.fr","threadId":"33337","inReplyTo":"7vobdwbs86.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 1/2] status: show 'revert' state and status hint","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@grenoble-inp.fr","sentAt":"2013-04-02T20:36:20Z","receivedAt":"2013-04-02T20:36:20Z","isPatch":true,"sender":{"key":"matthieu.moy@grenoble-inp.fr","avatar":"https://gravatar.com/avatar/72c8a2705971a25dfaff23cece15130d405685845d911aedd5667ace277f3fc5?d=mp&s=160"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>> +\tif (advice_status_hints) {\n>> +\t}\n>> +\tif (advice_status_hints)\n>> +\t\tstatus_printf_ln(s, color,\n>> +\t\t\t_(\"  (use \\\"git revert --abort\\\" to cancel the revert operation)\"));\n>\n> Why not a single conditional? i.e.\n>\n> \tif (advice_status_hints) {\n> \t\tif unmerged\n> \t\t\tfix and continue\n> \t\telse\n> \t\t\tsay continue\n> \t\tyou can also say abort\n> \t}\n\nOops, you're right. I wrote the code mostly with cut-and-past + edit\nfrom other functions, and didn't notice the obvious refactoring\nopportunity.\n\n-- \nMatthieu Moy\nhttp://www-verimag.imag.fr/~moy/\n"}]}