git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-prompt: show 'CONFLICT' indicator at command prompt

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 27, 2022, 20:13 UTC
Message-ID
<xmqq35ems49j.fsf@gitster.g>
In-Reply-To
<pull.1302.git.1658798595633.gitgitgadget@gmail.com>
"Justin Donnelly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index 1435548e004..2d30eb5c17e 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -84,6 +84,9 @@
>  # single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
>  # by setting GIT_PS1_OMITSPARSESTATE.
>  #
> +# When there is a conflict, the prompt will include "|CONFLICT". This can
> +# be omitted by setting GIT_PS1_OMITCONFLICTSTATE.
> +#

It is unusual to subject our unsuspecting users to new features in a way that is done by this patch. A more usual practice, I think, is to tell the users that they can set GIT_PS1_INCLUDECONFLICTSTATE to "yes" if they want to opt in, and trigger the new feature only to them. Later, we may decide that the feature is useful and widely apprlicable enough, at which time it may be turned on by default and tell the users to set GIT_PS1_INCLUDECONFLICTSTATE to "no" if they do not want to see it. But one step at a time.

Show 6 quoted lines
> @@ -508,6 +511,12 @@ __git_ps1 ()
>  		r="$r $step/$total"
>  	fi
>  
> +	local conflict="" # state indicator for unresolved conflicts
> +	if [[ -z "${GIT_PS1_OMITCONFLICTSTATE-}" ]] &&

And flipping the polarity and disabling it by default would be a simple change, I would imagine, that can be made here.

Show 24 quoted lines
> +	   [[ $(git ls-files --unmerged 2>/dev/null) ]]; then
> +		conflict="|CONFLICT"
> +	fi
> +
>  	local w=""
>  	local i=""
>  	local s=""
> @@ -572,7 +581,7 @@ __git_ps1 ()
>  	fi
>  
>  	local f="$h$w$i$s$u$p"
> -	local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}"
> +	local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}${conflict}"
>  
>  	if [ $pcmode = yes ]; then
>  		if [ "${__git_printf_supports_v-}" != yes ]; then
> diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh
> index 6a30f5719c3..9314776211c 100755
> --- a/t/t9903-bash-prompt.sh
> +++ b/t/t9903-bash-prompt.sh
> @@ -183,7 +183,7 @@ test_expect_success 'prompt - interactive rebase' '
>  '
>  
>  test_expect_success 'prompt - rebase merge' '

Of course, this needs to be tweaked if we did so. Running the test in the default state will not need this change, but then ...

Show 5 quoted lines
> -	printf " (b2|REBASE 1/3)" >expected &&
> +	printf " (b2|REBASE 1/3|CONFLICT)" >expected &&
>  	git checkout b2 &&
>  	test_when_finished "git checkout main" &&
>  	test_must_fail git rebase --merge b1 b2 &&

... a new test that runs the same thing but with the new feature asked by setting the environment variable would show the new |CONFLICT marker.

Thanks.
Previous: Justin Donnelly via GitGitGadgetNext: Justin Donnelly
Message 2 of 17 in “git-prompt: show 'CONFLICT' indicator at command prompt”
  1. git-prompt: show 'CONFLICT' indicator at command promptJustin Donnelly via GitGitGadget, Jul 26, 2022
  2. Junio C HamanoJul 27, 2022
  3. Justin DonnellyJul 28, 2022
  4. Junio C HamanoJul 28, 2022
  5. Justin DonnellyJul 28, 2022
  6. git-prompt: show presence of unresolved conflicts at command promptJustin Donnelly via GitGitGadget, Jul 29, 2022
  7. Justin DonnellyAug 14, 2022
  8. Junio C HamanoAug 15, 2022
  9. Johannes SchindelinAug 15, 2022
  10. Justin DonnellyAug 16, 2022
  11. Phillip WoodAug 15, 2022
  12. Junio C HamanoAug 15, 2022
  13. Justin DonnellyAug 16, 2022
  14. Justin DonnellyAug 16, 2022
  15. git-prompt: show presence of unresolved conflicts at command promptJustin Donnelly via GitGitGadget, Aug 17, 2022
  16. Johannes SchindelinAug 19, 2022
  17. Junio C HamanoAug 19, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.