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

[PATCH v2 2/2] git-prompt: include sparsity state as well

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 18, 2020, 20:49 UTC
Message-ID
<17254b30a5bcbbe3e14dd47272dfcb4c867030dd.1592513398.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.808.v2.git.git.1592513398.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
The current git prompt includes a lot of possible state information from
cherry-picks, merges, bisects, and various flavors of rebases.  Add
sparsity as another state flavor (though one which can be present
simultaneously with any of rebase/cherry-pick/merge/bisect).  This extra
state is shown with an extra
    |SPARSE
substring before the other states, providing a prompt that looks like:
    (branchname|SPARSE|REBASE 6/10)

The reason for showing the "|SPARSE" substring before other states is to emphasize those other states. Sparsity is probably not going to change much within a repository, while temporary operations will. So we want the state changes related to temporary operations to be listed last, to make them appear closer to where the user types and make them more likely to be noticed.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 contrib/completion/git-prompt.sh | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index 014cd7c3cfc..3e7344a4014 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -421,6 +421,11 @@ __git_ps1 ()
 		return $exit
 	fi
 
+	local sparse=""
+	if [ "$(git config --bool core.sparseCheckout)" == "true" ]; then
+	    sparse="|SPARSE"
+	fi
+
 	local r=""
 	local b=""
 	local step=""
@@ -543,7 +548,7 @@ __git_ps1 ()
 	fi
 
 	local f="$w$i$s$u"
-	local gitstring="$c$b${f:+$z$f}$r$p"
+	local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
 
 	if [ $pcmode = yes ]; then
 		if [ "${__git_printf_supports_v-}" != yes ]; then
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: SZEDER Gábor
Message 8 of 19 in “Sparse checkout status”
  1. 0/2 Sparse checkout statusElijah Newren via GitGitGadget, Jun 16, 2020
  2. 1/2 [RFC] wt-status: show sparse checkout status as wellElijah Newren via GitGitGadget, Jun 16, 2020
  3. Derrick StoleeJun 17, 2020
  4. Elijah NewrenJun 17, 2020
  5. 2/2 [RFC] git-prompt: include sparsity state as wellElijah Newren via GitGitGadget, Jun 16, 2020
  6. 0/2 Sparse checkout statusElijah Newren via GitGitGadget, Jun 18, 2020
  7. 1/2 wt-status: show sparse checkout status as wellElijah Newren via GitGitGadget, Jun 18, 2020
  8. 2/2 git-prompt: include sparsity state as wellElijah Newren via GitGitGadget, Jun 18, 2020
  9. SZEDER GáborJun 19, 2020
  10. Junio C HamanoJun 19, 2020
  11. Junio C HamanoJun 19, 2020
  12. Junio C HamanoJun 18, 2020
  13. Elijah NewrenJun 18, 2020
  14. Elijah NewrenJun 21, 2020
  15. 0/3 Sparse checkout statusElijah Newren via GitGitGadget, Jun 21, 2020
  16. 1/3 wt-status: show sparse checkout status as wellElijah Newren via GitGitGadget, Jun 21, 2020
  17. 3/3 git-prompt: include sparsity state as wellElijah Newren via GitGitGadget, Jun 21, 2020
  18. Junio C HamanoJun 22, 2020
  19. 2/3 git-prompt: document how in-progress operations affect the promptElijah Newren via GitGitGadget, Jun 21, 2020

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.