{"thread":{"id":"51412","subject":"[PATCH 0/1] git-prompt: improve cherry-pick/revert detection","startedAt":"2019-07-01T14:21:09Z","lastAt":"2019-07-01T14:21:11Z","messageCount":2,"participants":["Phillip Wood via GitGitGadget"],"isPatch":true,"patchVersion":1,"patchTotal":1},"messages":[{"id":"378388","messageId":"pull.281.git.gitgitgadget@gmail.com","threadId":"51412","inReplyTo":null,"subject":"[PATCH 0/1] git-prompt: improve cherry-pick/revert detection","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-07-01T14:21:06Z","receivedAt":"2019-07-01T14:21:09Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Fix the detection of in-progress cherry-picks and reverts when the user\ncommits or resets a conflict resolution in the middle of a sequence of\npicks/reverts.\n\nPhillip Wood (1):\n  git-prompt: improve cherry-pick/revert detection\n\n contrib/completion/git-prompt.sh | 37 ++++++++++++++++++++++++++++----\n t/t9903-bash-prompt.sh           | 20 +++++++++++++++--\n 2 files changed, 51 insertions(+), 6 deletions(-)\n\n\nbase-commit: 8dca754b1e874719a732bc9ab7b0e14b21b1bc10\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-281%2Fphillipwood%2Fwip%2Fprompt-status-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-281/phillipwood/wip/prompt-status-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/281\n-- \ngitgitgadget\n"},{"id":"378389","messageId":"0f04fa2930d5cc7dfd2a5c5185573f7ecefa6055.1561990865.git.gitgitgadget@gmail.com","threadId":"51412","inReplyTo":"pull.281.git.gitgitgadget@gmail.com","subject":"[PATCH 1/1] git-prompt: improve cherry-pick/revert detection","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-07-01T14:21:06Z","receivedAt":"2019-07-01T14:21:11Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"From: Phillip Wood <phillip.wood@dunelm.org.uk>\n\nIf the user commits or resets a conflict resolution in the middle of a\nsequence of cherry-picks or reverts then CHERRY_PICK_HEAD/REVERT_HEAD\nwill be removed and so in the absence of those files we need to check\n.git/sequencer/todo to see if there is a cherry-pick or revert in\nprogress.\n\nSigned-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n---\n contrib/completion/git-prompt.sh | 37 ++++++++++++++++++++++++++++----\n t/t9903-bash-prompt.sh           | 20 +++++++++++++++--\n 2 files changed, 51 insertions(+), 6 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 983e419d2b..1d510cd47b 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -286,6 +286,37 @@ __git_eread ()\n \ttest -r \"$1\" && IFS=$'\\r\\n' read \"$2\" <\"$1\"\n }\n \n+# see if a cherry-pick or revert is in progress, if the user has committed a\n+# conflict resolution with 'git commit' in the middle of a sequence of picks or\n+# reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read\n+# the todo file.\n+__git_sequencer_status ()\n+{\n+\tlocal todo\n+\tif test -f \"$g/CHERRY_PICK_HEAD\"\n+\tthen\n+\t\tr=\"|CHERRY-PICKING\"\n+\t\treturn 0;\n+\telif test -f \"$g/REVERT_HEAD\"\n+\tthen\n+\t\tr=\"|REVERTING\"\n+\t\treturn 0;\n+\telif __git_eread \"$g/sequencer/todo\" todo\n+\tthen\n+\t\tcase \"$todo\" in\n+\t\tp[\\ \\\t]|pick[\\ \\\t]*)\n+\t\t\tr=\"|CHERRY-PICKING\"\n+\t\t\treturn 0\n+\t\t;;\n+\t\trevert[\\ \\\t]*)\n+\t\t\tr=\"|REVERTING\"\n+\t\t\treturn 0\n+\t\t;;\n+\t\tesac\n+\tfi\n+\treturn 1\n+}\n+\n # __git_ps1 accepts 0 or 1 arguments (i.e., format string)\n # when called from PS1 using command substitution\n # in this mode it prints text to add to bash PS1 prompt (includes branch name)\n@@ -417,10 +448,8 @@ __git_ps1 ()\n \t\t\tfi\n \t\telif [ -f \"$g/MERGE_HEAD\" ]; then\n \t\t\tr=\"|MERGING\"\n-\t\telif [ -f \"$g/CHERRY_PICK_HEAD\" ]; then\n-\t\t\tr=\"|CHERRY-PICKING\"\n-\t\telif [ -f \"$g/REVERT_HEAD\" ]; then\n-\t\t\tr=\"|REVERTING\"\n+\t\telif __git_sequencer_status; then\n+\t\t\t:\n \t\telif [ -f \"$g/BISECT_LOG\" ]; then\n \t\t\tr=\"|BISECTING\"\n \t\tfi\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 5cadedb2a9..88bc733ad6 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -211,8 +211,24 @@ test_expect_success 'prompt - merge' '\n \n test_expect_success 'prompt - cherry-pick' '\n \tprintf \" (master|CHERRY-PICKING)\" >expected &&\n-\ttest_must_fail git cherry-pick b1 &&\n-\ttest_when_finished \"git reset --hard\" &&\n+\ttest_must_fail git cherry-pick b1 b1^ &&\n+\ttest_when_finished \"git cherry-pick --abort\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\" &&\n+\tgit reset --merge &&\n+\ttest_must_fail git rev-parse CHERRY_PICK_HEAD &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - revert' '\n+\tprintf \" (master|REVERTING)\" >expected &&\n+\ttest_must_fail git revert b1^ b1 &&\n+\ttest_when_finished \"git revert --abort\" &&\n+\t__git_ps1 >\"$actual\" &&\n+\ttest_cmp expected \"$actual\" &&\n+\tgit reset --merge &&\n+\ttest_must_fail git rev-parse REVERT_HEAD &&\n \t__git_ps1 >\"$actual\" &&\n \ttest_cmp expected \"$actual\"\n '\n-- \ngitgitgadget\n"}]}