Message ID | 17254b30a5bcbbe3e14dd47272dfcb4c867030dd.1592513398.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Sparse checkout status | expand |
On Thu, Jun 18, 2020 at 08:49:58PM +0000, Elijah Newren via GitGitGadget wrote: > 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. I understand why some users prefer to be reminded when they are in a repository that uses sparse checkout. However, perhaps not all users want to be reminded, and I'm sure that not all users want to increase the width of their prompt by 7 characters (e.g. in standard-width terminals). > 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" Nit: indentation. > + 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
SZEDER Gábor <szeder.dev@gmail.com> writes: >> + local sparse="" >> + if [ "$(git config --bool core.sparseCheckout)" == "true" ]; then >> + sparse="|SPARSE" > > Nit: indentation. Also, do we want "==" there? I thought [ ... ] (unlike [[ ... ]]) was a mere synonym for "test", to which "==" is a bug.
Junio C Hamano <gitster@pobox.com> writes: > SZEDER Gábor <szeder.dev@gmail.com> writes: > >>> + local sparse="" >>> + if [ "$(git config --bool core.sparseCheckout)" == "true" ]; then >>> + sparse="|SPARSE" >> >> Nit: indentation. > > Also, do we want "==" there? I thought [ ... ] (unlike [[ ... ]]) > was a mere synonym for "test", to which "==" is a bug. Ah, OK, this script is very bash specific so POSIX portability rules do not matter. == is just fine as = there. Sorry for the noise.
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