{"thread":{"id":"58223","subject":"[PATCH] git-prompt: show 'CONFLICT' indicator at command prompt","startedAt":"2022-07-26T01:23:21Z","lastAt":"2022-08-19T18:09:14Z","messageCount":17,"participants":["Justin Donnelly via GitGitGadget","Junio C Hamano","Justin Donnelly","Johannes Schindelin","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"459951","messageId":"pull.1302.git.1658798595633.gitgitgadget@gmail.com","threadId":"58223","inReplyTo":null,"subject":"[PATCH] git-prompt: show 'CONFLICT' indicator at command prompt","fromName":"Justin Donnelly via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-07-26T01:23:15Z","receivedAt":"2022-07-26T01:23:21Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"From: Justin Donnelly <justinrdonnelly@gmail.com>\n\nWhen there are unresolved conflicts, show the word 'CONFLICT' on the\ncommand prompt. Similar to other state indicators, this provides\ninformation to the user about the current state of the repository.\n\nExample prompt: (main|CONFLICT)\n\nSigned-off-by: Justin Donnelly <justinrdonnelly@gmail.com>\n---\n    Show 'CONFLICT' indicator at command prompt\n    \n    This patch adds functionality for bash/zsh to show 'CONFLICT' on the\n    prompt in cases where there are unresolved conflicts. It includes the\n    ability for the functionality to be disabled by setting an environment\n    variable (enabled by default).\n    \n    The conflict state is determined by running git ls-files --unmerged. In\n    my testing, the performance was very good. It took around 0.01 seconds\n    to run git ls-files --unmerged regardless of the number of conflicts, or\n    their depth, even on vary large projects (Linux kernel). However, if\n    anybody has any concerns with this, I'm open to other options.\n    \n    I had to make some changes to several tests in t9903-bash-prompt.sh to\n    make them pass (adding '|CONFLICT' to expected output of __git_ps1). The\n    changes clearly make sense, since there is a conflict in those test\n    cases. But I'm curious if others think it's the best approach.\n    \n    Test options considered:\n    \n     1. Set GIT_PS1_OMITCONFLICTSTATE before the tests. This would prevent\n        the new functionality from taking effect.\n     2. Update the tests to include \"|CONFLICT\" where applicable (this is\n        what I've done so far).\n     3. Duplicate the tests that needed to be updated, and do #⁠1 for one of\n        the tests and #⁠2 for the other.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1302%2Fjustinrdonnelly%2Fconflict-indicator-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1302/justinrdonnelly/conflict-indicator-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1302\n\n contrib/completion/git-prompt.sh | 11 ++++++++++-\n t/t9903-bash-prompt.sh           |  9 +++++----\n 2 files changed, 15 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 1435548e004..2d30eb5c17e 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,9 @@\n # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n # by setting GIT_PS1_OMITSPARSESTATE.\n #\n+# When there is a conflict, the prompt will include \"|CONFLICT\". This can\n+# be omitted by setting GIT_PS1_OMITCONFLICTSTATE.\n+#\n # If you would like to see more information about the identity of\n # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n # to one of these values:\n@@ -508,6 +511,12 @@ __git_ps1 ()\n \t\tr=\"$r $step/$total\"\n \tfi\n \n+\tlocal conflict=\"\" # state indicator for unresolved conflicts\n+\tif [[ -z \"${GIT_PS1_OMITCONFLICTSTATE-}\" ]] &&\n+\t   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n+\t\tconflict=\"|CONFLICT\"\n+\tfi\n+\n \tlocal w=\"\"\n \tlocal i=\"\"\n \tlocal s=\"\"\n@@ -572,7 +581,7 @@ __git_ps1 ()\n \tfi\n \n \tlocal f=\"$h$w$i$s$u$p\"\n-\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n+\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n \n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 6a30f5719c3..9314776211c 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -183,7 +183,7 @@ test_expect_success 'prompt - interactive rebase' '\n '\n \n test_expect_success 'prompt - rebase merge' '\n-\tprintf \" (b2|REBASE 1/3)\" >expected &&\n+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n \tgit checkout b2 &&\n \ttest_when_finished \"git checkout main\" &&\n \ttest_must_fail git rebase --merge b1 b2 &&\n@@ -193,7 +193,7 @@ test_expect_success 'prompt - rebase merge' '\n '\n \n test_expect_success 'prompt - rebase am' '\n-\tprintf \" (b2|REBASE 1/3)\" >expected &&\n+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n \tgit checkout b2 &&\n \ttest_when_finished \"git checkout main\" &&\n \ttest_must_fail git rebase --apply b1 b2 &&\n@@ -203,7 +203,7 @@ test_expect_success 'prompt - rebase am' '\n '\n \n test_expect_success 'prompt - merge' '\n-\tprintf \" (b1|MERGING)\" >expected &&\n+\tprintf \" (b1|MERGING|CONFLICT)\" >expected &&\n \tgit checkout b1 &&\n \ttest_when_finished \"git checkout main\" &&\n \ttest_must_fail git merge b2 &&\n@@ -213,11 +213,12 @@ test_expect_success 'prompt - merge' '\n '\n \n test_expect_success 'prompt - cherry-pick' '\n-\tprintf \" (main|CHERRY-PICKING)\" >expected &&\n+\tprintf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\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+\tprintf \" (main|CHERRY-PICKING)\" >expected &&\n \tgit reset --merge &&\n \ttest_must_fail git rev-parse CHERRY_PICK_HEAD &&\n \t__git_ps1 >\"$actual\" &&\n\nbase-commit: 6a475b71f8c4ce708d69fdc9317aefbde3769e25\n-- \ngitgitgadget\n"},{"id":"460036","messageId":"xmqq35ems49j.fsf@gitster.g","threadId":"58223","inReplyTo":"pull.1302.git.1658798595633.gitgitgadget@gmail.com","subject":"Re: [PATCH] git-prompt: show 'CONFLICT' indicator at command prompt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-27T20:13:28Z","receivedAt":"2022-07-27T20:13:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Justin Donnelly via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 1435548e004..2d30eb5c17e 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,9 @@\n>  # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n>  # by setting GIT_PS1_OMITSPARSESTATE.\n>  #\n> +# When there is a conflict, the prompt will include \"|CONFLICT\". This can\n> +# be omitted by setting GIT_PS1_OMITCONFLICTSTATE.\n> +#\n\nIt is unusual to subject our unsuspecting users to new features in a\nway that is done by this patch.  A more usual practice, I think, is\nto tell the users that they can set GIT_PS1_INCLUDECONFLICTSTATE to\n\"yes\" if they want to opt in, and trigger the new feature only to\nthem.  Later, we may decide that the feature is useful and widely\napprlicable enough, at which time it may be turned on by default and\ntell the users to set GIT_PS1_INCLUDECONFLICTSTATE to \"no\" if they\ndo not want to see it.  But one step at a time.\n\n> @@ -508,6 +511,12 @@ __git_ps1 ()\n>  \t\tr=\"$r $step/$total\"\n>  \tfi\n>  \n> +\tlocal conflict=\"\" # state indicator for unresolved conflicts\n> +\tif [[ -z \"${GIT_PS1_OMITCONFLICTSTATE-}\" ]] &&\n\nAnd flipping the polarity and disabling it by default would be a\nsimple change, I would imagine, that can be made here.\n\n> +\t   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n> +\t\tconflict=\"|CONFLICT\"\n> +\tfi\n> +\n>  \tlocal w=\"\"\n>  \tlocal i=\"\"\n>  \tlocal s=\"\"\n> @@ -572,7 +581,7 @@ __git_ps1 ()\n>  \tfi\n>  \n>  \tlocal f=\"$h$w$i$s$u$p\"\n> -\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n> +\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n>  \n>  \tif [ $pcmode = yes ]; then\n>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> index 6a30f5719c3..9314776211c 100755\n> --- a/t/t9903-bash-prompt.sh\n> +++ b/t/t9903-bash-prompt.sh\n> @@ -183,7 +183,7 @@ test_expect_success 'prompt - interactive rebase' '\n>  '\n>  \n>  test_expect_success 'prompt - rebase merge' '\n\nOf course, this needs to be tweaked if we did so.  Running the test\nin the default state will not need this change, but then ...\n\n> -\tprintf \" (b2|REBASE 1/3)\" >expected &&\n> +\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>  \tgit checkout b2 &&\n>  \ttest_when_finished \"git checkout main\" &&\n>  \ttest_must_fail git rebase --merge b1 b2 &&\n\n... a new test that runs the same thing but with the new feature\nasked by setting the environment variable would show the new |CONFLICT\nmarker.\n\nThanks.\n"},{"id":"460064","messageId":"CAGTqyRzfeh4HLbXUCb3Zv=bWNoBmvBU5QB=N2g2d0=y+NEToag@mail.gmail.com","threadId":"58223","inReplyTo":"xmqq35ems49j.fsf@gitster.g","subject":"Re: [PATCH] git-prompt: show 'CONFLICT' indicator at command prompt","fromName":"Justin Donnelly","fromEmail":"justinrdonnelly@gmail.com","sentAt":"2022-07-28T02:17:52Z","receivedAt":"2022-07-28T02:18:37Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"Thanks for the feedback.\n\n\nOn Wed, Jul 27, 2022 at 4:13 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> \"Justin Donnelly via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n>\n> > diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> > index 1435548e004..2d30eb5c17e 100644\n> > --- a/contrib/completion/git-prompt.sh\n> > +++ b/contrib/completion/git-prompt.sh\n> > @@ -84,6 +84,9 @@\n> >  # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n> >  # by setting GIT_PS1_OMITSPARSESTATE.\n> >  #\n> > +# When there is a conflict, the prompt will include \"|CONFLICT\". This can\n> > +# be omitted by setting GIT_PS1_OMITCONFLICTSTATE.\n> > +#\n>\n> It is unusual to subject our unsuspecting users to new features in a\n> way that is done by this patch.  A more usual practice, I think, is\n> to tell the users that they can set GIT_PS1_INCLUDECONFLICTSTATE to\n> \"yes\" if they want to opt in, and trigger the new feature only to\n> them.  Later, we may decide that the feature is useful and widely\n> apprlicable enough, at which time it may be turned on by default and\n> tell the users to set GIT_PS1_INCLUDECONFLICTSTATE to \"no\" if they\n> do not want to see it.  But one step at a time.\n>\n\nI see that most of the state indicators are disabled by default, so it\nmakes sense to be consistent. Should I make a variable with 'yes'/'no'\nvalues, or set/unset? 'yes'/'no' has the benefit that if the default\nis later changed, existing setups will continue to work. Set/unset\nmakes it harder to change the default later (I guess you could just\nuse a new variable with a different name), but is more consistent with\nthe other state indicators. I'm leaning towards set/unset, but it's\nnot a strong preference. Let me know if you disagree.\n\n> > @@ -508,6 +511,12 @@ __git_ps1 ()\n> >               r=\"$r $step/$total\"\n> >       fi\n> >\n> > +     local conflict=\"\" # state indicator for unresolved conflicts\n> > +     if [[ -z \"${GIT_PS1_OMITCONFLICTSTATE-}\" ]] &&\n>\n> And flipping the polarity and disabling it by default would be a\n> simple change, I would imagine, that can be made here.\n>\n> > +        [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n> > +             conflict=\"|CONFLICT\"\n> > +     fi\n> > +\n> >       local w=\"\"\n> >       local i=\"\"\n> >       local s=\"\"\n> > @@ -572,7 +581,7 @@ __git_ps1 ()\n> >       fi\n> >\n> >       local f=\"$h$w$i$s$u$p\"\n> > -     local gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n> > +     local gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n> >\n> >       if [ $pcmode = yes ]; then\n> >               if [ \"${__git_printf_supports_v-}\" != yes ]; then\n> > diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> > index 6a30f5719c3..9314776211c 100755\n> > --- a/t/t9903-bash-prompt.sh\n> > +++ b/t/t9903-bash-prompt.sh\n> > @@ -183,7 +183,7 @@ test_expect_success 'prompt - interactive rebase' '\n> >  '\n> >\n> >  test_expect_success 'prompt - rebase merge' '\n>\n> Of course, this needs to be tweaked if we did so.  Running the test\n> in the default state will not need this change, but then ...\n>\n> > -     printf \" (b2|REBASE 1/3)\" >expected &&\n> > +     printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n> >       git checkout b2 &&\n> >       test_when_finished \"git checkout main\" &&\n> >       test_must_fail git rebase --merge b1 b2 &&\n>\n> ... a new test that runs the same thing but with the new feature\n> asked by setting the environment variable would show the new |CONFLICT\n> marker.\n\nI'll add these.\n\n>\n> Thanks.\n"},{"id":"460136","messageId":"xmqqpmhpb08p.fsf@gitster.g","threadId":"58223","inReplyTo":"CAGTqyRzfeh4HLbXUCb3Zv=bWNoBmvBU5QB=N2g2d0=y+NEToag@mail.gmail.com","subject":"Re: [PATCH] git-prompt: show 'CONFLICT' indicator at command prompt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-07-28T17:44:38Z","receivedAt":"2022-07-28T17:44:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Justin Donnelly <justinrdonnelly@gmail.com> writes:\n\n>> It is unusual to subject our unsuspecting users to new features in a\n>> way that is done by this patch.  A more usual practice, I think, is\n>> to tell the users that they can set GIT_PS1_INCLUDECONFLICTSTATE to\n>> \"yes\" if they want to opt in, and trigger the new feature only to\n>> them.  Later, we may decide that the feature is useful and widely\n>> apprlicable enough, at which time it may be turned on by default and\n>> tell the users to set GIT_PS1_INCLUDECONFLICTSTATE to \"no\" if they\n>> do not want to see it.  But one step at a time.\n>>\n>\n> I see that most of the state indicators are disabled by default, so it\n> makes sense to be consistent. Should I make a variable with 'yes'/'no'\n> values, or set/unset? 'yes'/'no' has the benefit that if the default\n> is later changed, existing setups will continue to work. Set/unset\n> makes it harder to change the default later ...\n\nAs you said, \"an environment variable that is set triggers the\nfeature\" is harder to transition.  Starting from a clear Boolean is\nprobably easy to see what is going on, and that is why I suggested\ndoing that way.  \n\nOnes that are \"if set, enabled\" can be corrected later when needed,\ne.g. GIT_PS1_FROTZ may enable the feature FROTZ when the environment\nis set, but when we introduce two or more ways to do FROTZ thing\n(e.g. in addition to always do FROTZ, which may be the original\ndesign of \"an environment that is set triggers the feature\", we may\nadd \"automatically enable FROTZ only under this and that\ncondition\"), we may say \"when set to 'auto', do the auto-FROTZ, and\nwhen set to 'yes', do FROTZ as we have always done.  When set to any\nother value, warn and then do FROTZ\").  But let's leave them outside\nthe scope of the topic.\n\n"},{"id":"460164","messageId":"CAGTqyRxTF=7PYCZm=xynQc2v55v-iim5iut9GxgT66E-Sqpiqg@mail.gmail.com","threadId":"58223","inReplyTo":"xmqqpmhpb08p.fsf@gitster.g","subject":"Re: [PATCH] git-prompt: show 'CONFLICT' indicator at command prompt","fromName":"Justin Donnelly","fromEmail":"justinrdonnelly@gmail.com","sentAt":"2022-07-28T23:33:28Z","receivedAt":"2022-07-28T23:34:46Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"On Thu, Jul 28, 2022 at 1:44 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Justin Donnelly <justinrdonnelly@gmail.com> writes:\n>\n> >> It is unusual to subject our unsuspecting users to new features in a\n> >> way that is done by this patch.  A more usual practice, I think, is\n> >> to tell the users that they can set GIT_PS1_INCLUDECONFLICTSTATE to\n> >> \"yes\" if they want to opt in, and trigger the new feature only to\n> >> them.  Later, we may decide that the feature is useful and widely\n> >> apprlicable enough, at which time it may be turned on by default and\n> >> tell the users to set GIT_PS1_INCLUDECONFLICTSTATE to \"no\" if they\n> >> do not want to see it.  But one step at a time.\n> >>\n> >\n> > I see that most of the state indicators are disabled by default, so it\n> > makes sense to be consistent. Should I make a variable with 'yes'/'no'\n> > values, or set/unset? 'yes'/'no' has the benefit that if the default\n> > is later changed, existing setups will continue to work. Set/unset\n> > makes it harder to change the default later ...\n>\n> As you said, \"an environment variable that is set triggers the\n> feature\" is harder to transition.  Starting from a clear Boolean is\n> probably easy to see what is going on, and that is why I suggested\n> doing that way.\n>\n> Ones that are \"if set, enabled\" can be corrected later when needed,\n> e.g. GIT_PS1_FROTZ may enable the feature FROTZ when the environment\n> is set, but when we introduce two or more ways to do FROTZ thing\n> (e.g. in addition to always do FROTZ, which may be the original\n> design of \"an environment that is set triggers the feature\", we may\n> add \"automatically enable FROTZ only under this and that\n> condition\"), we may say \"when set to 'auto', do the auto-FROTZ, and\n> when set to 'yes', do FROTZ as we have always done.  When set to any\n> other value, warn and then do FROTZ\").  But let's leave them outside\n> the scope of the topic.\n>\n\nThanks. I'll incorporate these suggestions into a re-roll.\n"},{"id":"460285","messageId":"pull.1302.v2.git.1659132518935.gitgitgadget@gmail.com","threadId":"58223","inReplyTo":"pull.1302.git.1658798595633.gitgitgadget@gmail.com","subject":"[PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Justin Donnelly via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-07-29T22:08:38Z","receivedAt":"2022-07-29T22:08:46Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"From: Justin Donnelly <justinrdonnelly@gmail.com>\n\nIf GIT_PS1_SHOWCONFLICTSTATE is set to \"yes\", show the word \"CONFLICT\"\non the command prompt when there are unresolved conflicts.\n\nExample prompt: (main|CONFLICT)\n\nSigned-off-by: Justin Donnelly <justinrdonnelly@gmail.com>\n---\n    Show 'CONFLICT' indicator at command prompt\n    \n    This patch adds functionality for bash/zsh to show \"CONFLICT\" on the\n    prompt in cases where there are unresolved conflicts. The feature is\n    only enabled after setting an environment variable.\n    \n    The conflict state is determined by running git ls-files --unmerged. In\n    my testing, the performance was very good. It took around 0.01 seconds\n    to run git ls-files --unmerged regardless of the number of conflicts, or\n    their depth, even on very large projects (Linux kernel). However, if\n    anybody has any concerns with this, I'm open to other options.\n    \n    Any tests that were impacted (with the conflict prompt feature enabled)\n    were duplicated. The original test was left as-is (no changes, and\n    conflict prompt feature disabled). The new version of each test enables\n    the conflict prompt feature and confirms the prompt includes\n    \"|CONFLICT\".\n    \n    ------------------------------------------------------------------------\n    \n    Changes since v1:\n    \n     * This feature is now disabled by default.\n     * Created new tests for conflict state (instead of modifying existing\n       tests).\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1302%2Fjustinrdonnelly%2Fconflict-indicator-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1302/justinrdonnelly/conflict-indicator-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1302\n\nRange-diff vs v1:\n\n 1:  e380826dcaf ! 1:  7154d695426 git-prompt: show 'CONFLICT' indicator at command prompt\n     @@ Metadata\n      Author: Justin Donnelly <justinrdonnelly@gmail.com>\n      \n       ## Commit message ##\n     -    git-prompt: show 'CONFLICT' indicator at command prompt\n     +    git-prompt: show presence of unresolved conflicts at command prompt\n      \n     -    When there are unresolved conflicts, show the word 'CONFLICT' on the\n     -    command prompt. Similar to other state indicators, this provides\n     -    information to the user about the current state of the repository.\n     +    If GIT_PS1_SHOWCONFLICTSTATE is set to \"yes\", show the word \"CONFLICT\"\n     +    on the command prompt when there are unresolved conflicts.\n      \n          Example prompt: (main|CONFLICT)\n      \n     @@ contrib/completion/git-prompt.sh\n       # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n       # by setting GIT_PS1_OMITSPARSESTATE.\n       #\n     -+# When there is a conflict, the prompt will include \"|CONFLICT\". This can\n     -+# be omitted by setting GIT_PS1_OMITCONFLICTSTATE.\n     ++# If you would like to see a notification on the prompt when there are\n     ++# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to \"yes\". The\n     ++# prompt will include \"|CONFLICT\".\n      +#\n       # If you would like to see more information about the identity of\n       # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n     @@ contrib/completion/git-prompt.sh: __git_ps1 ()\n       \tfi\n       \n      +\tlocal conflict=\"\" # state indicator for unresolved conflicts\n     -+\tif [[ -z \"${GIT_PS1_OMITCONFLICTSTATE-}\" ]] &&\n     ++\tif [[ \"${GIT_PS1_SHOWCONFLICTSTATE}\" == \"yes\" ]] &&\n      +\t   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n      +\t\tconflict=\"|CONFLICT\"\n      +\tfi\n     @@ contrib/completion/git-prompt.sh: __git_ps1 ()\n       \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n      \n       ## t/t9903-bash-prompt.sh ##\n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - interactive rebase' '\n     - '\n     - \n     - test_expect_success 'prompt - rebase merge' '\n     --\tprintf \" (b2|REBASE 1/3)\" >expected &&\n     -+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n     - \tgit checkout b2 &&\n     +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase merge' '\n       \ttest_when_finished \"git checkout main\" &&\n       \ttest_must_fail git rebase --merge b1 b2 &&\n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase merge' '\n     + \ttest_when_finished \"git rebase --abort\" &&\n     +-\t__git_ps1 >\"$actual\" &&\n     ++\t(\n     ++\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     ++\ttest_cmp expected \"$actual\"\n     ++'\n     ++\n     ++test_expect_success 'prompt - rebase merge conflict' '\n     ++\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n     ++\tgit checkout b2 &&\n     ++\ttest_when_finished \"git checkout main\" &&\n     ++\ttest_must_fail git rebase --merge b1 b2 &&\n     ++\ttest_when_finished \"git rebase --abort\" &&\n     ++\t(\n     ++\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     + \ttest_cmp expected \"$actual\"\n       '\n       \n     - test_expect_success 'prompt - rebase am' '\n     --\tprintf \" (b2|REBASE 1/3)\" >expected &&\n     -+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n     - \tgit checkout b2 &&\n     +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase am' '\n       \ttest_when_finished \"git checkout main\" &&\n       \ttest_must_fail git rebase --apply b1 b2 &&\n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase am' '\n     + \ttest_when_finished \"git rebase --abort\" &&\n     +-\t__git_ps1 >\"$actual\" &&\n     ++\t(\n     ++\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     ++\ttest_cmp expected \"$actual\"\n     ++'\n     ++\n     ++test_expect_success 'prompt - rebase am conflict' '\n     ++\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n     ++\tgit checkout b2 &&\n     ++\ttest_when_finished \"git checkout main\" &&\n     ++\ttest_must_fail git rebase --apply b1 b2 &&\n     ++\ttest_when_finished \"git rebase --abort\" &&\n     ++\t(\n     ++\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     + \ttest_cmp expected \"$actual\"\n       '\n       \n     - test_expect_success 'prompt - merge' '\n     --\tprintf \" (b1|MERGING)\" >expected &&\n     -+\tprintf \" (b1|MERGING|CONFLICT)\" >expected &&\n     - \tgit checkout b1 &&\n     +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - merge' '\n       \ttest_when_finished \"git checkout main\" &&\n       \ttest_must_fail git merge b2 &&\n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - merge' '\n     + \ttest_when_finished \"git reset --hard\" &&\n     +-\t__git_ps1 >\"$actual\" &&\n     ++\t(\n     ++\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     ++\ttest_cmp expected \"$actual\"\n     ++'\n     ++\n     ++test_expect_success 'prompt - merge conflict' '\n     ++\tprintf \" (b1|MERGING|CONFLICT)\" >expected &&\n     ++\tgit checkout b1 &&\n     ++\ttest_when_finished \"git checkout main\" &&\n     ++\ttest_must_fail git merge b2 &&\n     ++\ttest_when_finished \"git reset --hard\" &&\n     ++\t(\n     ++\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     + \ttest_cmp expected \"$actual\"\n       '\n       \n     - test_expect_success 'prompt - cherry-pick' '\n     --\tprintf \" (main|CHERRY-PICKING)\" >expected &&\n     -+\tprintf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n     +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n     + \tprintf \" (main|CHERRY-PICKING)\" >expected &&\n       \ttest_must_fail git cherry-pick b1 b1^ &&\n       \ttest_when_finished \"git cherry-pick --abort\" &&\n     - \t__git_ps1 >\"$actual\" &&\n     +-\t__git_ps1 >\"$actual\" &&\n     ++\t(\n     ++\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n       \ttest_cmp expected \"$actual\" &&\n     -+\tprintf \" (main|CHERRY-PICKING)\" >expected &&\n       \tgit reset --merge &&\n       \ttest_must_fail git rev-parse CHERRY_PICK_HEAD &&\n     - \t__git_ps1 >\"$actual\" &&\n     +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n     + \ttest_cmp expected \"$actual\"\n     + '\n     + \n     ++test_expect_success 'prompt - cherry-pick conflict' '\n     ++\tprintf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n     ++\ttest_must_fail git cherry-pick b1 b1^ &&\n     ++\ttest_when_finished \"git cherry-pick --abort\" &&\n     ++\t(\n     ++\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     ++\t\t__git_ps1 >\"$actual\"\n     ++\t) &&\n     ++\ttest_cmp expected \"$actual\"\n     ++'\n     ++\n     + test_expect_success 'prompt - revert' '\n     + \tprintf \" (main|REVERTING)\" >expected &&\n     + \ttest_must_fail git revert b1^ b1 &&\n\n\n contrib/completion/git-prompt.sh | 12 +++++-\n t/t9903-bash-prompt.sh           | 70 ++++++++++++++++++++++++++++++--\n 2 files changed, 77 insertions(+), 5 deletions(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 1435548e004..57972c2845c 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,10 @@\n # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n # by setting GIT_PS1_OMITSPARSESTATE.\n #\n+# If you would like to see a notification on the prompt when there are\n+# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to \"yes\". The\n+# prompt will include \"|CONFLICT\".\n+#\n # If you would like to see more information about the identity of\n # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n # to one of these values:\n@@ -508,6 +512,12 @@ __git_ps1 ()\n \t\tr=\"$r $step/$total\"\n \tfi\n \n+\tlocal conflict=\"\" # state indicator for unresolved conflicts\n+\tif [[ \"${GIT_PS1_SHOWCONFLICTSTATE}\" == \"yes\" ]] &&\n+\t   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n+\t\tconflict=\"|CONFLICT\"\n+\tfi\n+\n \tlocal w=\"\"\n \tlocal i=\"\"\n \tlocal s=\"\"\n@@ -572,7 +582,7 @@ __git_ps1 ()\n \tfi\n \n \tlocal f=\"$h$w$i$s$u$p\"\n-\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n+\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n \n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 6a30f5719c3..47eb98893ef 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -188,7 +188,23 @@ test_expect_success 'prompt - rebase merge' '\n \ttest_when_finished \"git checkout main\" &&\n \ttest_must_fail git rebase --merge b1 b2 &&\n \ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - rebase merge conflict' '\n+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n+\tgit checkout b2 &&\n+\ttest_when_finished \"git checkout main\" &&\n+\ttest_must_fail git rebase --merge b1 b2 &&\n+\ttest_when_finished \"git rebase --abort\" &&\n+\t(\n+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n \ttest_cmp expected \"$actual\"\n '\n \n@@ -198,7 +214,23 @@ test_expect_success 'prompt - rebase am' '\n \ttest_when_finished \"git checkout main\" &&\n \ttest_must_fail git rebase --apply b1 b2 &&\n \ttest_when_finished \"git rebase --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - rebase am conflict' '\n+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n+\tgit checkout b2 &&\n+\ttest_when_finished \"git checkout main\" &&\n+\ttest_must_fail git rebase --apply b1 b2 &&\n+\ttest_when_finished \"git rebase --abort\" &&\n+\t(\n+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n \ttest_cmp expected \"$actual\"\n '\n \n@@ -208,7 +240,23 @@ test_expect_success 'prompt - merge' '\n \ttest_when_finished \"git checkout main\" &&\n \ttest_must_fail git merge b2 &&\n \ttest_when_finished \"git reset --hard\" &&\n-\t__git_ps1 >\"$actual\" &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n+test_expect_success 'prompt - merge conflict' '\n+\tprintf \" (b1|MERGING|CONFLICT)\" >expected &&\n+\tgit checkout b1 &&\n+\ttest_when_finished \"git checkout main\" &&\n+\ttest_must_fail git merge b2 &&\n+\ttest_when_finished \"git reset --hard\" &&\n+\t(\n+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n \ttest_cmp expected \"$actual\"\n '\n \n@@ -216,7 +264,10 @@ test_expect_success 'prompt - cherry-pick' '\n \tprintf \" (main|CHERRY-PICKING)\" >expected &&\n \ttest_must_fail git cherry-pick b1 b1^ &&\n \ttest_when_finished \"git cherry-pick --abort\" &&\n-\t__git_ps1 >\"$actual\" &&\n+\t(\n+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n \ttest_cmp expected \"$actual\" &&\n \tgit reset --merge &&\n \ttest_must_fail git rev-parse CHERRY_PICK_HEAD &&\n@@ -224,6 +275,17 @@ test_expect_success 'prompt - cherry-pick' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - cherry-pick conflict' '\n+\tprintf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n+\ttest_must_fail git cherry-pick b1 b1^ &&\n+\ttest_when_finished \"git cherry-pick --abort\" &&\n+\t(\n+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_expect_success 'prompt - revert' '\n \tprintf \" (main|REVERTING)\" >expected &&\n \ttest_must_fail git revert b1^ b1 &&\n\nbase-commit: 6a475b71f8c4ce708d69fdc9317aefbde3769e25\n-- \ngitgitgadget\n"},{"id":"461200","messageId":"CAGTqyRw-SYDbQy9aktq5s3ZhoDhUOCf-pEopjH9m7v5+PH7Qqg@mail.gmail.com","threadId":"58223","inReplyTo":"pull.1302.v2.git.1659132518935.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Justin Donnelly","fromEmail":"justinrdonnelly@gmail.com","sentAt":"2022-08-14T21:06:57Z","receivedAt":"2022-08-14T21:07:39Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"On Fri, Jul 29, 2022 at 6:08 PM Justin Donnelly via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n>\n> From: Justin Donnelly <justinrdonnelly@gmail.com>\n>\n> If GIT_PS1_SHOWCONFLICTSTATE is set to \"yes\", show the word \"CONFLICT\"\n> on the command prompt when there are unresolved conflicts.\n>\n> Example prompt: (main|CONFLICT)\n>\n> Signed-off-by: Justin Donnelly <justinrdonnelly@gmail.com>\n> ---\n>     Show 'CONFLICT' indicator at command prompt\n>\n>     This patch adds functionality for bash/zsh to show \"CONFLICT\" on the\n>     prompt in cases where there are unresolved conflicts. The feature is\n>     only enabled after setting an environment variable.\n>\n>     The conflict state is determined by running git ls-files --unmerged. In\n>     my testing, the performance was very good. It took around 0.01 seconds\n>     to run git ls-files --unmerged regardless of the number of conflicts, or\n>     their depth, even on very large projects (Linux kernel). However, if\n>     anybody has any concerns with this, I'm open to other options.\n>\n>     Any tests that were impacted (with the conflict prompt feature enabled)\n>     were duplicated. The original test was left as-is (no changes, and\n>     conflict prompt feature disabled). The new version of each test enables\n>     the conflict prompt feature and confirms the prompt includes\n>     \"|CONFLICT\".\n>\n>     ------------------------------------------------------------------------\n>\n>     Changes since v1:\n>\n>      * This feature is now disabled by default.\n>      * Created new tests for conflict state (instead of modifying existing\n>        tests).\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1302%2Fjustinrdonnelly%2Fconflict-indicator-v2\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1302/justinrdonnelly/conflict-indicator-v2\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1302\n>\n> Range-diff vs v1:\n>\n>  1:  e380826dcaf ! 1:  7154d695426 git-prompt: show 'CONFLICT' indicator at command prompt\n>      @@ Metadata\n>       Author: Justin Donnelly <justinrdonnelly@gmail.com>\n>\n>        ## Commit message ##\n>      -    git-prompt: show 'CONFLICT' indicator at command prompt\n>      +    git-prompt: show presence of unresolved conflicts at command prompt\n>\n>      -    When there are unresolved conflicts, show the word 'CONFLICT' on the\n>      -    command prompt. Similar to other state indicators, this provides\n>      -    information to the user about the current state of the repository.\n>      +    If GIT_PS1_SHOWCONFLICTSTATE is set to \"yes\", show the word \"CONFLICT\"\n>      +    on the command prompt when there are unresolved conflicts.\n>\n>           Example prompt: (main|CONFLICT)\n>\n>      @@ contrib/completion/git-prompt.sh\n>        # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n>        # by setting GIT_PS1_OMITSPARSESTATE.\n>        #\n>      -+# When there is a conflict, the prompt will include \"|CONFLICT\". This can\n>      -+# be omitted by setting GIT_PS1_OMITCONFLICTSTATE.\n>      ++# If you would like to see a notification on the prompt when there are\n>      ++# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to \"yes\". The\n>      ++# prompt will include \"|CONFLICT\".\n>       +#\n>        # If you would like to see more information about the identity of\n>        # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n>      @@ contrib/completion/git-prompt.sh: __git_ps1 ()\n>         fi\n>\n>       + local conflict=\"\" # state indicator for unresolved conflicts\n>      -+ if [[ -z \"${GIT_PS1_OMITCONFLICTSTATE-}\" ]] &&\n>      ++ if [[ \"${GIT_PS1_SHOWCONFLICTSTATE}\" == \"yes\" ]] &&\n>       +    [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n>       +         conflict=\"|CONFLICT\"\n>       + fi\n>      @@ contrib/completion/git-prompt.sh: __git_ps1 ()\n>                 if [ \"${__git_printf_supports_v-}\" != yes ]; then\n>\n>        ## t/t9903-bash-prompt.sh ##\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - interactive rebase' '\n>      - '\n>      -\n>      - test_expect_success 'prompt - rebase merge' '\n>      -- printf \" (b2|REBASE 1/3)\" >expected &&\n>      -+ printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>      -  git checkout b2 &&\n>      +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase merge' '\n>         test_when_finished \"git checkout main\" &&\n>         test_must_fail git rebase --merge b1 b2 &&\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase merge' '\n>      +  test_when_finished \"git rebase --abort\" &&\n>      +- __git_ps1 >\"$actual\" &&\n>      ++ (\n>      ++         sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      ++ test_cmp expected \"$actual\"\n>      ++'\n>      ++\n>      ++test_expect_success 'prompt - rebase merge conflict' '\n>      ++ printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>      ++ git checkout b2 &&\n>      ++ test_when_finished \"git checkout main\" &&\n>      ++ test_must_fail git rebase --merge b1 b2 &&\n>      ++ test_when_finished \"git rebase --abort\" &&\n>      ++ (\n>      ++         GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      +  test_cmp expected \"$actual\"\n>        '\n>\n>      - test_expect_success 'prompt - rebase am' '\n>      -- printf \" (b2|REBASE 1/3)\" >expected &&\n>      -+ printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>      -  git checkout b2 &&\n>      +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase am' '\n>         test_when_finished \"git checkout main\" &&\n>         test_must_fail git rebase --apply b1 b2 &&\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase am' '\n>      +  test_when_finished \"git rebase --abort\" &&\n>      +- __git_ps1 >\"$actual\" &&\n>      ++ (\n>      ++         sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      ++ test_cmp expected \"$actual\"\n>      ++'\n>      ++\n>      ++test_expect_success 'prompt - rebase am conflict' '\n>      ++ printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>      ++ git checkout b2 &&\n>      ++ test_when_finished \"git checkout main\" &&\n>      ++ test_must_fail git rebase --apply b1 b2 &&\n>      ++ test_when_finished \"git rebase --abort\" &&\n>      ++ (\n>      ++         GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      +  test_cmp expected \"$actual\"\n>        '\n>\n>      - test_expect_success 'prompt - merge' '\n>      -- printf \" (b1|MERGING)\" >expected &&\n>      -+ printf \" (b1|MERGING|CONFLICT)\" >expected &&\n>      -  git checkout b1 &&\n>      +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - merge' '\n>         test_when_finished \"git checkout main\" &&\n>         test_must_fail git merge b2 &&\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - merge' '\n>      +  test_when_finished \"git reset --hard\" &&\n>      +- __git_ps1 >\"$actual\" &&\n>      ++ (\n>      ++         sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      ++ test_cmp expected \"$actual\"\n>      ++'\n>      ++\n>      ++test_expect_success 'prompt - merge conflict' '\n>      ++ printf \" (b1|MERGING|CONFLICT)\" >expected &&\n>      ++ git checkout b1 &&\n>      ++ test_when_finished \"git checkout main\" &&\n>      ++ test_must_fail git merge b2 &&\n>      ++ test_when_finished \"git reset --hard\" &&\n>      ++ (\n>      ++         GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      +  test_cmp expected \"$actual\"\n>        '\n>\n>      - test_expect_success 'prompt - cherry-pick' '\n>      -- printf \" (main|CHERRY-PICKING)\" >expected &&\n>      -+ printf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n>      +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n>      +  printf \" (main|CHERRY-PICKING)\" >expected &&\n>         test_must_fail git cherry-pick b1 b1^ &&\n>         test_when_finished \"git cherry-pick --abort\" &&\n>      -  __git_ps1 >\"$actual\" &&\n>      +- __git_ps1 >\"$actual\" &&\n>      ++ (\n>      ++         sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>         test_cmp expected \"$actual\" &&\n>      -+ printf \" (main|CHERRY-PICKING)\" >expected &&\n>         git reset --merge &&\n>         test_must_fail git rev-parse CHERRY_PICK_HEAD &&\n>      -  __git_ps1 >\"$actual\" &&\n>      +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n>      +  test_cmp expected \"$actual\"\n>      + '\n>      +\n>      ++test_expect_success 'prompt - cherry-pick conflict' '\n>      ++ printf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n>      ++ test_must_fail git cherry-pick b1 b1^ &&\n>      ++ test_when_finished \"git cherry-pick --abort\" &&\n>      ++ (\n>      ++         GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      ++         __git_ps1 >\"$actual\"\n>      ++ ) &&\n>      ++ test_cmp expected \"$actual\"\n>      ++'\n>      ++\n>      + test_expect_success 'prompt - revert' '\n>      +  printf \" (main|REVERTING)\" >expected &&\n>      +  test_must_fail git revert b1^ b1 &&\n>\n>\n>  contrib/completion/git-prompt.sh | 12 +++++-\n>  t/t9903-bash-prompt.sh           | 70 ++++++++++++++++++++++++++++++--\n>  2 files changed, 77 insertions(+), 5 deletions(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 1435548e004..57972c2845c 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,10 @@\n>  # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n>  # by setting GIT_PS1_OMITSPARSESTATE.\n>  #\n> +# If you would like to see a notification on the prompt when there are\n> +# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to \"yes\". The\n> +# prompt will include \"|CONFLICT\".\n> +#\n>  # If you would like to see more information about the identity of\n>  # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n>  # to one of these values:\n> @@ -508,6 +512,12 @@ __git_ps1 ()\n>                 r=\"$r $step/$total\"\n>         fi\n>\n> +       local conflict=\"\" # state indicator for unresolved conflicts\n> +       if [[ \"${GIT_PS1_SHOWCONFLICTSTATE}\" == \"yes\" ]] &&\n> +          [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n> +               conflict=\"|CONFLICT\"\n> +       fi\n> +\n>         local w=\"\"\n>         local i=\"\"\n>         local s=\"\"\n> @@ -572,7 +582,7 @@ __git_ps1 ()\n>         fi\n>\n>         local f=\"$h$w$i$s$u$p\"\n> -       local gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n> +       local gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n>\n>         if [ $pcmode = yes ]; then\n>                 if [ \"${__git_printf_supports_v-}\" != yes ]; then\n> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> index 6a30f5719c3..47eb98893ef 100755\n> --- a/t/t9903-bash-prompt.sh\n> +++ b/t/t9903-bash-prompt.sh\n> @@ -188,7 +188,23 @@ test_expect_success 'prompt - rebase merge' '\n>         test_when_finished \"git checkout main\" &&\n>         test_must_fail git rebase --merge b1 b2 &&\n>         test_when_finished \"git rebase --abort\" &&\n> -       __git_ps1 >\"$actual\" &&\n> +       (\n> +               sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n> +       test_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - rebase merge conflict' '\n> +       printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n> +       git checkout b2 &&\n> +       test_when_finished \"git checkout main\" &&\n> +       test_must_fail git rebase --merge b1 b2 &&\n> +       test_when_finished \"git rebase --abort\" &&\n> +       (\n> +               GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n>         test_cmp expected \"$actual\"\n>  '\n>\n> @@ -198,7 +214,23 @@ test_expect_success 'prompt - rebase am' '\n>         test_when_finished \"git checkout main\" &&\n>         test_must_fail git rebase --apply b1 b2 &&\n>         test_when_finished \"git rebase --abort\" &&\n> -       __git_ps1 >\"$actual\" &&\n> +       (\n> +               sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n> +       test_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - rebase am conflict' '\n> +       printf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n> +       git checkout b2 &&\n> +       test_when_finished \"git checkout main\" &&\n> +       test_must_fail git rebase --apply b1 b2 &&\n> +       test_when_finished \"git rebase --abort\" &&\n> +       (\n> +               GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n>         test_cmp expected \"$actual\"\n>  '\n>\n> @@ -208,7 +240,23 @@ test_expect_success 'prompt - merge' '\n>         test_when_finished \"git checkout main\" &&\n>         test_must_fail git merge b2 &&\n>         test_when_finished \"git reset --hard\" &&\n> -       __git_ps1 >\"$actual\" &&\n> +       (\n> +               sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n> +       test_cmp expected \"$actual\"\n> +'\n> +\n> +test_expect_success 'prompt - merge conflict' '\n> +       printf \" (b1|MERGING|CONFLICT)\" >expected &&\n> +       git checkout b1 &&\n> +       test_when_finished \"git checkout main\" &&\n> +       test_must_fail git merge b2 &&\n> +       test_when_finished \"git reset --hard\" &&\n> +       (\n> +               GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n>         test_cmp expected \"$actual\"\n>  '\n>\n> @@ -216,7 +264,10 @@ test_expect_success 'prompt - cherry-pick' '\n>         printf \" (main|CHERRY-PICKING)\" >expected &&\n>         test_must_fail git cherry-pick b1 b1^ &&\n>         test_when_finished \"git cherry-pick --abort\" &&\n> -       __git_ps1 >\"$actual\" &&\n> +       (\n> +               sane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n>         test_cmp expected \"$actual\" &&\n>         git reset --merge &&\n>         test_must_fail git rev-parse CHERRY_PICK_HEAD &&\n> @@ -224,6 +275,17 @@ test_expect_success 'prompt - cherry-pick' '\n>         test_cmp expected \"$actual\"\n>  '\n>\n> +test_expect_success 'prompt - cherry-pick conflict' '\n> +       printf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n> +       test_must_fail git cherry-pick b1 b1^ &&\n> +       test_when_finished \"git cherry-pick --abort\" &&\n> +       (\n> +               GIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n> +               __git_ps1 >\"$actual\"\n> +       ) &&\n> +       test_cmp expected \"$actual\"\n> +'\n> +\n>  test_expect_success 'prompt - revert' '\n>         printf \" (main|REVERTING)\" >expected &&\n>         test_must_fail git revert b1^ b1 &&\n>\n> base-commit: 6a475b71f8c4ce708d69fdc9317aefbde3769e25\n> --\n> gitgitgadget\n\n[SubmittingPatches](https://github.com/git/git/blob/master/Documentation/SubmittingPatches)\nrecommends using `git-contacts` to determine who to \"cc\" on the email.\nI used GitGitGadget, which doesn't cc anybody by default (I see now\nthat others manually add cc's to the PR description). So I've added\nthe following cc's to this email:\nÆvar Arnfjörð Bjarmason\nJunio C Hamano\nElijah Newren\nPhillip Wood\nJohannes Schindelin\n\nI hope this is against protocol/etiquette, but after some initial\nfeedback from Junio, I haven't gotten any more. I wasn't sure if\nnobody had seen the patch, or if there just wasn't any interest.\n\nThanks,\nJustin\n"},{"id":"461213","messageId":"xmqqy1vq3zm3.fsf@gitster.g","threadId":"58223","inReplyTo":"CAGTqyRw-SYDbQy9aktq5s3ZhoDhUOCf-pEopjH9m7v5+PH7Qqg@mail.gmail.com","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-15T04:22:12Z","receivedAt":"2022-08-15T04:22:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Justin Donnelly <justinrdonnelly@gmail.com> writes:\n\n> I hope this is against protocol/etiquette, but after some initial\n> feedback from Junio, I haven't gotten any more. I wasn't sure if\n> nobody had seen the patch, or if there just wasn't any interest.\n\nIt probably is a bit of both.  I personally did not see much point\nin adding the long \"conflicts\" marker to the shell prompt (I did\nworry about possible complaints by end users triggered by seeing\nthem suddenly without asking, which was why I commented on the\npatch) and I was waiting for interested folks to speak out.\n\nI do not know about other folks if they did see and did not find it\ninteresting, they are not looking at others' work, or your second\nround came on a particularly bad day (busy with other topics, or\nweekend just before the list was swamped with many new topics at the\nbeginning of a new week, or something).  Pinging on the thread like\nyou did would be the right thing to do to \"kick\" those, who did see\nand who were in favor but who kept silent, into action ;-)\n\n\n\n"},{"id":"461221","messageId":"r980s5q6-7714-8r0q-4sp1-3qs1458r17qs@tzk.qr","threadId":"58223","inReplyTo":"xmqqy1vq3zm3.fsf@gitster.g","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-08-15T12:50:29Z","receivedAt":"2022-08-15T12:50:42Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 14 Aug 2022, Junio C Hamano wrote:\n\n> Justin Donnelly <justinrdonnelly@gmail.com> writes:\n>\n> > I hope this is against protocol/etiquette, but after some initial\n> > feedback from Junio, I haven't gotten any more. I wasn't sure if\n> > nobody had seen the patch, or if there just wasn't any interest.\n>\n> It probably is a bit of both.  I personally did not see much point\n> in adding the long \"conflicts\" marker to the shell prompt (I did\n> worry about possible complaints by end users triggered by seeing\n> them suddenly without asking, which was why I commented on the\n> patch) and I was waiting for interested folks to speak out.\n\nSpeaking for myself, I was too busy elsewhere. But now that I looked over\nthe patch, I think it is fine. My only feedback is that it would be wise\nto only add a single test case because that is plenty enough (after all,\nit validates the `ls-files --unmerged` call and not the `cherry-pick`\ncode) and it is unnecessary to waste the electricity on additional tests\ncases (even if somebody else foots the bill, it would do well for all of\nus to start being more mindful about energy consumption).\n\nCiao,\nDscho\n"},{"id":"461223","messageId":"08a8e78d-7861-3da3-f6f6-bba466655071@gmail.com","threadId":"58223","inReplyTo":"xmqqy1vq3zm3.fsf@gitster.g","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2022-08-15T13:04:50Z","receivedAt":"2022-08-15T13:04:58Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi\n\nOn 15/08/2022 05:22, Junio C Hamano wrote:\n> Justin Donnelly <justinrdonnelly@gmail.com> writes:\n> \n>> I hope this is against protocol/etiquette, but after some initial\n>> feedback from Junio, I haven't gotten any more. I wasn't sure if\n>> nobody had seen the patch, or if there just wasn't any interest.\n> \n> It probably is a bit of both.  I personally did not see much point\n> in adding the long \"conflicts\" marker to the shell prompt (I did\n> worry about possible complaints by end users triggered by seeing\n> them suddenly without asking, which was why I commented on the\n> patch) and I was waiting for interested folks to speak out.\n> \n> I do not know about other folks if they did see and did not find it\n> interesting, they are not looking at others' work, or your second\n> round came on a particularly bad day (busy with other topics, or\n> weekend just before the list was swamped with many new topics at the\n> beginning of a new week, or something).  Pinging on the thread like\n> you did would be the right thing to do to \"kick\" those, who did see\n> and who were in favor but who kept silent, into action ;-)\n\nI had not commented as I don't use the prompt. I have just had a quick \nread and I wonder if it would be more efficient to use\n     git diff --cached --quiet --diff-filter=U\nrather than\n     git ls-files --unmerged 2>/dev/null\nto check if there are unmerged entries, but as we don't normally expect \nthere to be that many unmerged entries it probably does not matter.\n\nBest Wishes\n\nPhillip\n"},{"id":"461244","messageId":"xmqqilmt4huq.fsf@gitster.g","threadId":"58223","inReplyTo":"08a8e78d-7861-3da3-f6f6-bba466655071@gmail.com","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-15T16:00:29Z","receivedAt":"2022-08-15T16:01:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> I had not commented as I don't use the prompt. I have just had a quick\n> read and I wonder if it would be more efficient to use\n>     git diff --cached --quiet --diff-filter=U\n> rather than\n>     git ls-files --unmerged 2>/dev/null\n> to check if there are unmerged entries,\n\nThe former reads the on-disk index into in-core index, and reads\ntree objects (recursively for subdirectories) referenced by the\nHEAD, walks both in parallel to find differences and filters out the\nresult to unmerged (I am not sure how well diff-filter works with\nunmerged paths, though).\n\nThe latter rads the on-disk index into in-core index, scans the\nentries and finds unmerged entries.\n\nSo if we compare the overhead to run either command standalone, I am\nreasonably sure that the latter would be a lot more efficient.\n\nBut if the shell prompt code already needs to run the diff-index for\nother reasons (e.g. to show if there is any modification added to\nthe index), that may change the equation.  Instead of adding a\nseparate and extra call to \"ls-files -u\", it might be more efficient\nif you can somehow piggy-back on an existing diff-index call.  For\nexample, you may be running \"git diff --cached --quiet\" for exit code\nto show if any change has been added, but you can instead run \"git\ndiff --no-ext-diff --no-renames --cached --name-status\" and (1) if\nthere is any output, then the index is dirty, and (2) if there is a\nline that begins with \"U\", you have an unmerged path right there.\n"},{"id":"461261","messageId":"CAGTqyRyBAR1SCpKwU2mTTKz0-nOPgJ1Es6aGVBgJqrnZ9Z_P1w@mail.gmail.com","threadId":"58223","inReplyTo":"r980s5q6-7714-8r0q-4sp1-3qs1458r17qs@tzk.qr","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Justin Donnelly","fromEmail":"justinrdonnelly@gmail.com","sentAt":"2022-08-16T03:36:08Z","receivedAt":"2022-08-16T07:25:20Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"On Mon, Aug 15, 2022 at 8:50 AM Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>\n> Hi,\n>\n> On Sun, 14 Aug 2022, Junio C Hamano wrote:\n>\n> > Justin Donnelly <justinrdonnelly@gmail.com> writes:\n> >\n> > > I hope this is against protocol/etiquette, but after some initial\n> > > feedback from Junio, I haven't gotten any more. I wasn't sure if\n> > > nobody had seen the patch, or if there just wasn't any interest.\n> >\n> > It probably is a bit of both.  I personally did not see much point\n> > in adding the long \"conflicts\" marker to the shell prompt (I did\n> > worry about possible complaints by end users triggered by seeing\n> > them suddenly without asking, which was why I commented on the\n> > patch) and I was waiting for interested folks to speak out.\n>\n> Speaking for myself, I was too busy elsewhere. But now that I looked over\n> the patch, I think it is fine. My only feedback is that it would be wise\n> to only add a single test case because that is plenty enough (after all,\n> it validates the `ls-files --unmerged` call and not the `cherry-pick`\n> code) and it is unnecessary to waste the electricity on additional tests\n> cases (even if somebody else foots the bill, it would do well for all of\n> us to start being more mindful about energy consumption).\n\nThat makes sense. I'll get started on a re-roll to just have a single\ntest that focuses specifically on the conflict indicator.\n\n>\n> Ciao,\n> Dscho\n\nThanks,\nJustin\n"},{"id":"461262","messageId":"CAGTqyRyuV42-NRW_OKzy9F+LbFcZp-QZkM73LqrNkmOi60oU+w@mail.gmail.com","threadId":"58223","inReplyTo":"xmqqilmt4huq.fsf@gitster.g","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Justin Donnelly","fromEmail":"justinrdonnelly@gmail.com","sentAt":"2022-08-16T04:20:50Z","receivedAt":"2022-08-16T07:36:04Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"On Mon, Aug 15, 2022 at 12:00 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Phillip Wood <phillip.wood123@gmail.com> writes:\n>\n> > I had not commented as I don't use the prompt. I have just had a quick\n> > read and I wonder if it would be more efficient to use\n> >     git diff --cached --quiet --diff-filter=U\n> > rather than\n> >     git ls-files --unmerged 2>/dev/null\n> > to check if there are unmerged entries,\n>\n> The former reads the on-disk index into in-core index, and reads\n> tree objects (recursively for subdirectories) referenced by the\n> HEAD, walks both in parallel to find differences and filters out the\n> result to unmerged (I am not sure how well diff-filter works with\n> unmerged paths, though).\n>\n> The latter rads the on-disk index into in-core index, scans the\n> entries and finds unmerged entries.\n>\n> So if we compare the overhead to run either command standalone, I am\n> reasonably sure that the latter would be a lot more efficient.\n>\n\nHere's how I tested performance. The setup and test execution code are\nbelow. I tested each technique (`git ls-files --unmerged 2>/dev/null`\nand `git diff --cached --quiet --diff-filter=U`) 3 times and listed\nthe results. Please let me know if you see any problems with the\nmethodology.\n\nSetup:\nmkdir -p /tmp/perf/base && cd /tmp/perf/base\ngit clone https://github.com/torvalds/linux.git\n\nEach test:\ncd /tmp/perf\nrm -rf test\ncp -r base test\ncd test/linux/drivers/watchdog\ngit switch --detach v6.0-rc1 # pick some commit for consistency\nfor f in *; do echo \"/* a */\" >> $f; done # 182 files\ngit stash\nfor f in *; do echo \"/* b */\" >> $f; done\ngit commit -am \"adding to end of files in watchdog directory\"\ngit stash pop\ntime [[ $(git ls-files --unmerged 2>/dev/null) ]]\n# OR run the next one instead\n# time ! git diff --cached --quiet --diff-filter=U 2>/dev/null\n\nResults (hopefully this text lines up better for others than it does for me):\ntime [[ $(git ls-files --unmerged 2>/dev/null) ]]\n      run 1     run 2     run3\nreal  0m0.008s  0m0.009s  0m0.008s\nuser  0m0.005s  0m0.001s  0m0.004s\nsys   0m0.004s  0m0.008s  0m0.004s\n\ntime ! git diff --cached --quiet --diff-filter=U 2>/dev/null\n      run 1     run 2     run3\nreal  0m0.009s  0m0.009s  0m0.007s\nuser  0m0.004s  0m0.009s  0m0.007s\nsys   0m0.004s  0m0.000s  0m0.000s\n\nAs you can see, the results are basically the same. I'm not sure if\nreal world usage would yield different results. So for now, I'll defer\nto Junio's analysis and stick with `ls-files --unmerged`.\n\n> But if the shell prompt code already needs to run the diff-index for\n> other reasons (e.g. to show if there is any modification added to\n> the index), that may change the equation.  Instead of adding a\n> separate and extra call to \"ls-files -u\", it might be more efficient\n> if you can somehow piggy-back on an existing diff-index call.  For\n> example, you may be running \"git diff --cached --quiet\" for exit code\n> to show if any change has been added, but you can instead run \"git\n> diff --no-ext-diff --no-renames --cached --name-status\" and (1) if\n> there is any output, then the index is dirty, and (2) if there is a\n> line that begins with \"U\", you have an unmerged path right there.\n\nIt had not occurred to me to consolidate and piggy-back off of other\ncommands. I find the idea intriguing, but am not sure it makes sense\nto do it for only a single feature (especially this feature since the\ntime to determine the conflict is short). I think it would make the\ncode more complex, and it might be better to take a holistic approach\nto such an effort. Let me know if you strongly disagree.\n\nThanks,\nJustin\n"},{"id":"461316","messageId":"CAGTqyRxt-+vLQPNbRCgKv3VvUMNEQF47DUH2Ht+CsKqDxgfjpw@mail.gmail.com","threadId":"58223","inReplyTo":"CAGTqyRyuV42-NRW_OKzy9F+LbFcZp-QZkM73LqrNkmOi60oU+w@mail.gmail.com","subject":"Re: [PATCH v2] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Justin Donnelly","fromEmail":"justinrdonnelly@gmail.com","sentAt":"2022-08-16T23:32:43Z","receivedAt":"2022-08-16T23:33:26Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"On Tue, Aug 16, 2022 at 12:20 AM Justin Donnelly\n<justinrdonnelly@gmail.com> wrote:\n>\n> On Mon, Aug 15, 2022 at 12:00 PM Junio C Hamano <gitster@pobox.com> wrote:\n> >\n> > Phillip Wood <phillip.wood123@gmail.com> writes:\n> >\n> > > I had not commented as I don't use the prompt. I have just had a quick\n> > > read and I wonder if it would be more efficient to use\n> > >     git diff --cached --quiet --diff-filter=U\n> > > rather than\n> > >     git ls-files --unmerged 2>/dev/null\n> > > to check if there are unmerged entries,\n> >\n> > The former reads the on-disk index into in-core index, and reads\n> > tree objects (recursively for subdirectories) referenced by the\n> > HEAD, walks both in parallel to find differences and filters out the\n> > result to unmerged (I am not sure how well diff-filter works with\n> > unmerged paths, though).\n> >\n> > The latter rads the on-disk index into in-core index, scans the\n> > entries and finds unmerged entries.\n> >\n> > So if we compare the overhead to run either command standalone, I am\n> > reasonably sure that the latter would be a lot more efficient.\n> >\n>\n> Here's how I tested performance. The setup and test execution code are\n> below. I tested each technique (`git ls-files --unmerged 2>/dev/null`\n> and `git diff --cached --quiet --diff-filter=U`) 3 times and listed\n> the results. Please let me know if you see any problems with the\n> methodology.\n>\n> Setup:\n> mkdir -p /tmp/perf/base && cd /tmp/perf/base\n> git clone https://github.com/torvalds/linux.git\n>\n> Each test:\n> cd /tmp/perf\n> rm -rf test\n> cp -r base test\n> cd test/linux/drivers/watchdog\n> git switch --detach v6.0-rc1 # pick some commit for consistency\n> for f in *; do echo \"/* a */\" >> $f; done # 182 files\n> git stash\n> for f in *; do echo \"/* b */\" >> $f; done\n> git commit -am \"adding to end of files in watchdog directory\"\n> git stash pop\n> time [[ $(git ls-files --unmerged 2>/dev/null) ]]\n> # OR run the next one instead\n> # time ! git diff --cached --quiet --diff-filter=U 2>/dev/null\n>\n> Results (hopefully this text lines up better for others than it does for me):\n> time [[ $(git ls-files --unmerged 2>/dev/null) ]]\n>       run 1     run 2     run3\n> real  0m0.008s  0m0.009s  0m0.008s\n> user  0m0.005s  0m0.001s  0m0.004s\n> sys   0m0.004s  0m0.008s  0m0.004s\n>\n> time ! git diff --cached --quiet --diff-filter=U 2>/dev/null\n>       run 1     run 2     run3\n> real  0m0.009s  0m0.009s  0m0.007s\n> user  0m0.004s  0m0.009s  0m0.007s\n> sys   0m0.004s  0m0.000s  0m0.000s\n>\n\nActually, what's probably more important is how long the commands take\nwhen there is no conflict (that will be a far more common situation).\nI tested that today, and the numbers were about the same.\n\n> As you can see, the results are basically the same. I'm not sure if\n> real world usage would yield different results. So for now, I'll defer\n> to Junio's analysis and stick with `ls-files --unmerged`.\n>\n> > But if the shell prompt code already needs to run the diff-index for\n> > other reasons (e.g. to show if there is any modification added to\n> > the index), that may change the equation.  Instead of adding a\n> > separate and extra call to \"ls-files -u\", it might be more efficient\n> > if you can somehow piggy-back on an existing diff-index call.  For\n> > example, you may be running \"git diff --cached --quiet\" for exit code\n> > to show if any change has been added, but you can instead run \"git\n> > diff --no-ext-diff --no-renames --cached --name-status\" and (1) if\n> > there is any output, then the index is dirty, and (2) if there is a\n> > line that begins with \"U\", you have an unmerged path right there.\n>\n> It had not occurred to me to consolidate and piggy-back off of other\n> commands. I find the idea intriguing, but am not sure it makes sense\n> to do it for only a single feature (especially this feature since the\n> time to determine the conflict is short). I think it would make the\n> code more complex, and it might be better to take a holistic approach\n> to such an effort. Let me know if you strongly disagree.\n>\n> Thanks,\n> Justin\n"},{"id":"461323","messageId":"pull.1302.v3.git.1660695492382.gitgitgadget@gmail.com","threadId":"58223","inReplyTo":"pull.1302.v2.git.1659132518935.gitgitgadget@gmail.com","subject":"[PATCH v3] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Justin Donnelly via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-08-17T00:18:12Z","receivedAt":"2022-08-17T00:18:20Z","isPatch":true,"sender":{"key":"justinrdonnelly@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24846452?v=4"},"body":"From: Justin Donnelly <justinrdonnelly@gmail.com>\n\nIf GIT_PS1_SHOWCONFLICTSTATE is set to \"yes\", show the word \"CONFLICT\"\non the command prompt when there are unresolved conflicts.\n\nExample prompt: (main|CONFLICT)\n\nSigned-off-by: Justin Donnelly <justinrdonnelly@gmail.com>\n---\n    Show 'CONFLICT' indicator at command prompt\n    \n    This patch adds functionality for bash/zsh to show \"CONFLICT\" on the\n    prompt in cases where there are unresolved conflicts. The feature is\n    only enabled after setting an environment variable.\n    \n    The conflict state is determined by running git ls-files --unmerged. In\n    my testing, the performance was very good. It took around 0.01 seconds\n    to run git ls-files --unmerged regardless of the number of conflicts, or\n    their depth, even on very large projects (Linux kernel). I got similar\n    performance running git diff --cached --quiet --diff-filter=U.\n    \n    ------------------------------------------------------------------------\n    \n    Changes since v2:\n    \n     * There is now a single new test focused explicitly on this feature\n       instead of making copies of existing tests and modifying them.\n    \n    Changes since v1:\n    \n     * This feature is now disabled by default.\n     * Created new tests for conflict state (instead of modifying existing\n       tests).\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1302%2Fjustinrdonnelly%2Fconflict-indicator-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1302/justinrdonnelly/conflict-indicator-v3\nPull-Request: https://github.com/gitgitgadget/git/pull/1302\n\nRange-diff vs v2:\n\n 1:  7154d695426 ! 1:  2ea5c403924 git-prompt: show presence of unresolved conflicts at command prompt\n     @@ contrib/completion/git-prompt.sh: __git_ps1 ()\n       \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n      \n       ## t/t9903-bash-prompt.sh ##\n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase merge' '\n     - \ttest_when_finished \"git checkout main\" &&\n     - \ttest_must_fail git rebase --merge b1 b2 &&\n     - \ttest_when_finished \"git rebase --abort\" &&\n     --\t__git_ps1 >\"$actual\" &&\n     -+\t(\n     -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     -+\ttest_cmp expected \"$actual\"\n     -+'\n     -+\n     -+test_expect_success 'prompt - rebase merge conflict' '\n     -+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n     -+\tgit checkout b2 &&\n     -+\ttest_when_finished \"git checkout main\" &&\n     -+\ttest_must_fail git rebase --merge b1 b2 &&\n     -+\ttest_when_finished \"git rebase --abort\" &&\n     -+\t(\n     -+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     - \ttest_cmp expected \"$actual\"\n     - '\n     - \n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase am' '\n     - \ttest_when_finished \"git checkout main\" &&\n     - \ttest_must_fail git rebase --apply b1 b2 &&\n     - \ttest_when_finished \"git rebase --abort\" &&\n     --\t__git_ps1 >\"$actual\" &&\n     -+\t(\n     -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     -+\ttest_cmp expected \"$actual\"\n     -+'\n     -+\n     -+test_expect_success 'prompt - rebase am conflict' '\n     -+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n     -+\tgit checkout b2 &&\n     -+\ttest_when_finished \"git checkout main\" &&\n     -+\ttest_must_fail git rebase --apply b1 b2 &&\n     -+\ttest_when_finished \"git rebase --abort\" &&\n     -+\t(\n     -+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     - \ttest_cmp expected \"$actual\"\n     - '\n     - \n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - merge' '\n     - \ttest_when_finished \"git checkout main\" &&\n     - \ttest_must_fail git merge b2 &&\n     - \ttest_when_finished \"git reset --hard\" &&\n     --\t__git_ps1 >\"$actual\" &&\n     -+\t(\n     -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     -+\ttest_cmp expected \"$actual\"\n     -+'\n     -+\n     -+test_expect_success 'prompt - merge conflict' '\n     -+\tprintf \" (b1|MERGING|CONFLICT)\" >expected &&\n     -+\tgit checkout b1 &&\n     -+\ttest_when_finished \"git checkout main\" &&\n     -+\ttest_must_fail git merge b2 &&\n     -+\ttest_when_finished \"git reset --hard\" &&\n     -+\t(\n     -+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     - \ttest_cmp expected \"$actual\"\n     - '\n     - \n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n     - \tprintf \" (main|CHERRY-PICKING)\" >expected &&\n     - \ttest_must_fail git cherry-pick b1 b1^ &&\n     - \ttest_when_finished \"git cherry-pick --abort\" &&\n     --\t__git_ps1 >\"$actual\" &&\n     -+\t(\n     -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n     -+\t\t__git_ps1 >\"$actual\"\n     -+\t) &&\n     - \ttest_cmp expected \"$actual\" &&\n     - \tgit reset --merge &&\n     - \ttest_must_fail git rev-parse CHERRY_PICK_HEAD &&\n     -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n     +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '\n       \ttest_cmp expected \"$actual\"\n       '\n       \n     -+test_expect_success 'prompt - cherry-pick conflict' '\n     -+\tprintf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n     -+\ttest_must_fail git cherry-pick b1 b1^ &&\n     -+\ttest_when_finished \"git cherry-pick --abort\" &&\n     ++test_expect_success 'prompt - conflict indicator' '\n     ++\tprintf \" (main|CONFLICT)\" >expected &&\n     ++\techo \"stash\" >file &&\n     ++\tgit stash &&\n     ++\ttest_when_finished \"git stash drop\" &&\n     ++\techo \"commit\" >file &&\n     ++\tgit commit -m \"commit\" file &&\n     ++\ttest_when_finished \"git reset --hard HEAD~\" &&\n     ++\ttest_must_fail git stash apply &&\n      +\t(\n      +\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n      +\t\t__git_ps1 >\"$actual\"\n     @@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n      +\ttest_cmp expected \"$actual\"\n      +'\n      +\n     - test_expect_success 'prompt - revert' '\n     - \tprintf \" (main|REVERTING)\" >expected &&\n     - \ttest_must_fail git revert b1^ b1 &&\n     + test_done\n\n\n contrib/completion/git-prompt.sh | 12 +++++++++++-\n t/t9903-bash-prompt.sh           | 16 ++++++++++++++++\n 2 files changed, 27 insertions(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\nindex 1435548e004..57972c2845c 100644\n--- a/contrib/completion/git-prompt.sh\n+++ b/contrib/completion/git-prompt.sh\n@@ -84,6 +84,10 @@\n # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n # by setting GIT_PS1_OMITSPARSESTATE.\n #\n+# If you would like to see a notification on the prompt when there are\n+# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to \"yes\". The\n+# prompt will include \"|CONFLICT\".\n+#\n # If you would like to see more information about the identity of\n # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n # to one of these values:\n@@ -508,6 +512,12 @@ __git_ps1 ()\n \t\tr=\"$r $step/$total\"\n \tfi\n \n+\tlocal conflict=\"\" # state indicator for unresolved conflicts\n+\tif [[ \"${GIT_PS1_SHOWCONFLICTSTATE}\" == \"yes\" ]] &&\n+\t   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n+\t\tconflict=\"|CONFLICT\"\n+\tfi\n+\n \tlocal w=\"\"\n \tlocal i=\"\"\n \tlocal s=\"\"\n@@ -572,7 +582,7 @@ __git_ps1 ()\n \tfi\n \n \tlocal f=\"$h$w$i$s$u$p\"\n-\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n+\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n \n \tif [ $pcmode = yes ]; then\n \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\ndiff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\nindex 6a30f5719c3..d459fae6551 100755\n--- a/t/t9903-bash-prompt.sh\n+++ b/t/t9903-bash-prompt.sh\n@@ -759,4 +759,20 @@ test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '\n \ttest_cmp expected \"$actual\"\n '\n \n+test_expect_success 'prompt - conflict indicator' '\n+\tprintf \" (main|CONFLICT)\" >expected &&\n+\techo \"stash\" >file &&\n+\tgit stash &&\n+\ttest_when_finished \"git stash drop\" &&\n+\techo \"commit\" >file &&\n+\tgit commit -m \"commit\" file &&\n+\ttest_when_finished \"git reset --hard HEAD~\" &&\n+\ttest_must_fail git stash apply &&\n+\t(\n+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n+\t\t__git_ps1 >\"$actual\"\n+\t) &&\n+\ttest_cmp expected \"$actual\"\n+'\n+\n test_done\n\nbase-commit: 9bf691b78cf906751e65d65ba0c6ffdcd9a5a12c\n-- \ngitgitgadget\n"},{"id":"461545","messageId":"ps2p6366-7r7o-944q-o7s7-4rqp846721o9@tzk.qr","threadId":"58223","inReplyTo":"pull.1302.v3.git.1660695492382.gitgitgadget@gmail.com","subject":"Re: [PATCH v3] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-08-19T11:29:02Z","receivedAt":"2022-08-19T11:29:03Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Justin,\n\nOn Wed, 17 Aug 2022, Justin Donnelly via GitGitGadget wrote:\n\n> From: Justin Donnelly <justinrdonnelly@gmail.com>\n>\n> If GIT_PS1_SHOWCONFLICTSTATE is set to \"yes\", show the word \"CONFLICT\"\n> on the command prompt when there are unresolved conflicts.\n>\n> Example prompt: (main|CONFLICT)\n>\n> Signed-off-by: Justin Donnelly <justinrdonnelly@gmail.com>\n> ---\n>     Show 'CONFLICT' indicator at command prompt\n>\n>     This patch adds functionality for bash/zsh to show \"CONFLICT\" on the\n>     prompt in cases where there are unresolved conflicts. The feature is\n>     only enabled after setting an environment variable.\n>\n>     The conflict state is determined by running git ls-files --unmerged. In\n>     my testing, the performance was very good. It took around 0.01 seconds\n>     to run git ls-files --unmerged regardless of the number of conflicts, or\n>     their depth, even on very large projects (Linux kernel). I got similar\n>     performance running git diff --cached --quiet --diff-filter=U.\n>\n>     ------------------------------------------------------------------------\n>\n>     Changes since v2:\n>\n>      * There is now a single new test focused explicitly on this feature\n>        instead of making copies of existing tests and modifying them.\n>\n>     Changes since v1:\n>\n>      * This feature is now disabled by default.\n>      * Created new tests for conflict state (instead of modifying existing\n>        tests).\n\nThis iteration looks good to me.\n\nThanks!\nDscho\n\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1302%2Fjustinrdonnelly%2Fconflict-indicator-v3\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1302/justinrdonnelly/conflict-indicator-v3\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1302\n>\n> Range-diff vs v2:\n>\n>  1:  7154d695426 ! 1:  2ea5c403924 git-prompt: show presence of unresolved conflicts at command prompt\n>      @@ contrib/completion/git-prompt.sh: __git_ps1 ()\n>        \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n>\n>        ## t/t9903-bash-prompt.sh ##\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase merge' '\n>      - \ttest_when_finished \"git checkout main\" &&\n>      - \ttest_must_fail git rebase --merge b1 b2 &&\n>      - \ttest_when_finished \"git rebase --abort\" &&\n>      --\t__git_ps1 >\"$actual\" &&\n>      -+\t(\n>      -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      -+\ttest_cmp expected \"$actual\"\n>      -+'\n>      -+\n>      -+test_expect_success 'prompt - rebase merge conflict' '\n>      -+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>      -+\tgit checkout b2 &&\n>      -+\ttest_when_finished \"git checkout main\" &&\n>      -+\ttest_must_fail git rebase --merge b1 b2 &&\n>      -+\ttest_when_finished \"git rebase --abort\" &&\n>      -+\t(\n>      -+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      - \ttest_cmp expected \"$actual\"\n>      - '\n>      -\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - rebase am' '\n>      - \ttest_when_finished \"git checkout main\" &&\n>      - \ttest_must_fail git rebase --apply b1 b2 &&\n>      - \ttest_when_finished \"git rebase --abort\" &&\n>      --\t__git_ps1 >\"$actual\" &&\n>      -+\t(\n>      -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      -+\ttest_cmp expected \"$actual\"\n>      -+'\n>      -+\n>      -+test_expect_success 'prompt - rebase am conflict' '\n>      -+\tprintf \" (b2|REBASE 1/3|CONFLICT)\" >expected &&\n>      -+\tgit checkout b2 &&\n>      -+\ttest_when_finished \"git checkout main\" &&\n>      -+\ttest_must_fail git rebase --apply b1 b2 &&\n>      -+\ttest_when_finished \"git rebase --abort\" &&\n>      -+\t(\n>      -+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      - \ttest_cmp expected \"$actual\"\n>      - '\n>      -\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - merge' '\n>      - \ttest_when_finished \"git checkout main\" &&\n>      - \ttest_must_fail git merge b2 &&\n>      - \ttest_when_finished \"git reset --hard\" &&\n>      --\t__git_ps1 >\"$actual\" &&\n>      -+\t(\n>      -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      -+\ttest_cmp expected \"$actual\"\n>      -+'\n>      -+\n>      -+test_expect_success 'prompt - merge conflict' '\n>      -+\tprintf \" (b1|MERGING|CONFLICT)\" >expected &&\n>      -+\tgit checkout b1 &&\n>      -+\ttest_when_finished \"git checkout main\" &&\n>      -+\ttest_must_fail git merge b2 &&\n>      -+\ttest_when_finished \"git reset --hard\" &&\n>      -+\t(\n>      -+\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      - \ttest_cmp expected \"$actual\"\n>      - '\n>      -\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n>      - \tprintf \" (main|CHERRY-PICKING)\" >expected &&\n>      - \ttest_must_fail git cherry-pick b1 b1^ &&\n>      - \ttest_when_finished \"git cherry-pick --abort\" &&\n>      --\t__git_ps1 >\"$actual\" &&\n>      -+\t(\n>      -+\t\tsane_unset GIT_PS1_SHOWCONFLICTSTATE &&\n>      -+\t\t__git_ps1 >\"$actual\"\n>      -+\t) &&\n>      - \ttest_cmp expected \"$actual\" &&\n>      - \tgit reset --merge &&\n>      - \ttest_must_fail git rev-parse CHERRY_PICK_HEAD &&\n>      -@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n>      +@@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '\n>        \ttest_cmp expected \"$actual\"\n>        '\n>\n>      -+test_expect_success 'prompt - cherry-pick conflict' '\n>      -+\tprintf \" (main|CHERRY-PICKING|CONFLICT)\" >expected &&\n>      -+\ttest_must_fail git cherry-pick b1 b1^ &&\n>      -+\ttest_when_finished \"git cherry-pick --abort\" &&\n>      ++test_expect_success 'prompt - conflict indicator' '\n>      ++\tprintf \" (main|CONFLICT)\" >expected &&\n>      ++\techo \"stash\" >file &&\n>      ++\tgit stash &&\n>      ++\ttest_when_finished \"git stash drop\" &&\n>      ++\techo \"commit\" >file &&\n>      ++\tgit commit -m \"commit\" file &&\n>      ++\ttest_when_finished \"git reset --hard HEAD~\" &&\n>      ++\ttest_must_fail git stash apply &&\n>       +\t(\n>       +\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n>       +\t\t__git_ps1 >\"$actual\"\n>      @@ t/t9903-bash-prompt.sh: test_expect_success 'prompt - cherry-pick' '\n>       +\ttest_cmp expected \"$actual\"\n>       +'\n>       +\n>      - test_expect_success 'prompt - revert' '\n>      - \tprintf \" (main|REVERTING)\" >expected &&\n>      - \ttest_must_fail git revert b1^ b1 &&\n>      + test_done\n>\n>\n>  contrib/completion/git-prompt.sh | 12 +++++++++++-\n>  t/t9903-bash-prompt.sh           | 16 ++++++++++++++++\n>  2 files changed, 27 insertions(+), 1 deletion(-)\n>\n> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh\n> index 1435548e004..57972c2845c 100644\n> --- a/contrib/completion/git-prompt.sh\n> +++ b/contrib/completion/git-prompt.sh\n> @@ -84,6 +84,10 @@\n>  # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted\n>  # by setting GIT_PS1_OMITSPARSESTATE.\n>  #\n> +# If you would like to see a notification on the prompt when there are\n> +# unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to \"yes\". The\n> +# prompt will include \"|CONFLICT\".\n> +#\n>  # If you would like to see more information about the identity of\n>  # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE\n>  # to one of these values:\n> @@ -508,6 +512,12 @@ __git_ps1 ()\n>  \t\tr=\"$r $step/$total\"\n>  \tfi\n>\n> +\tlocal conflict=\"\" # state indicator for unresolved conflicts\n> +\tif [[ \"${GIT_PS1_SHOWCONFLICTSTATE}\" == \"yes\" ]] &&\n> +\t   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then\n> +\t\tconflict=\"|CONFLICT\"\n> +\tfi\n> +\n>  \tlocal w=\"\"\n>  \tlocal i=\"\"\n>  \tlocal s=\"\"\n> @@ -572,7 +582,7 @@ __git_ps1 ()\n>  \tfi\n>\n>  \tlocal f=\"$h$w$i$s$u$p\"\n> -\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}\"\n> +\tlocal gitstring=\"$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}\"\n>\n>  \tif [ $pcmode = yes ]; then\n>  \t\tif [ \"${__git_printf_supports_v-}\" != yes ]; then\n> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh\n> index 6a30f5719c3..d459fae6551 100755\n> --- a/t/t9903-bash-prompt.sh\n> +++ b/t/t9903-bash-prompt.sh\n> @@ -759,4 +759,20 @@ test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '\n>  \ttest_cmp expected \"$actual\"\n>  '\n>\n> +test_expect_success 'prompt - conflict indicator' '\n> +\tprintf \" (main|CONFLICT)\" >expected &&\n> +\techo \"stash\" >file &&\n> +\tgit stash &&\n> +\ttest_when_finished \"git stash drop\" &&\n> +\techo \"commit\" >file &&\n> +\tgit commit -m \"commit\" file &&\n> +\ttest_when_finished \"git reset --hard HEAD~\" &&\n> +\ttest_must_fail git stash apply &&\n> +\t(\n> +\t\tGIT_PS1_SHOWCONFLICTSTATE=\"yes\" &&\n> +\t\t__git_ps1 >\"$actual\"\n> +\t) &&\n> +\ttest_cmp expected \"$actual\"\n> +'\n> +\n>  test_done\n>\n> base-commit: 9bf691b78cf906751e65d65ba0c6ffdcd9a5a12c\n> --\n> gitgitgadget\n>\n"},{"id":"461592","messageId":"xmqq35dsm7zs.fsf@gitster.g","threadId":"58223","inReplyTo":"ps2p6366-7r7o-944q-o7s7-4rqp846721o9@tzk.qr","subject":"Re: [PATCH v3] git-prompt: show presence of unresolved conflicts at command prompt","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-19T17:57:27Z","receivedAt":"2022-08-19T18:09:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Hi Justin,\n>\n> On Wed, 17 Aug 2022, Justin Donnelly via GitGitGadget wrote:\n> ...\n>>     Changes since v2:\n>>\n>>      * There is now a single new test focused explicitly on this feature\n>>        instead of making copies of existing tests and modifying them.\n>>\n>>     Changes since v1:\n>>\n>>      * This feature is now disabled by default.\n>>      * Created new tests for conflict state (instead of modifying existing\n>>        tests).\n>\n> This iteration looks good to me.\n\nThanks, both.  Will queue.\n"}]}