git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/1] Improve instructions around how to set git-prompt preference variables.
@ 2019-06-05 15:06 Edward D'Souza via GitGitGadget
  2019-06-05 15:06 ` [PATCH 1/1] git-prompt.sh: update shell variable instructions Edward D'Souza via GitGitGadget
  0 siblings, 1 reply; 4+ messages in thread
From: Edward D'Souza via GitGitGadget @ 2019-06-05 15:06 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano

When I first tried to use the git-prompt.sh script, I followed the
instructions at the top of the file and everything worked, except for the
"GIT_PS1_SHOWDIRTYSTATE" preference. Even though I had it set to true, I
wasn't seeing the "()" and "(+)" in my shell prompt. After a few hours of
poking around, I finally discovered what I had done wrong: I was setting the
variable *after the "source ~/.git-prompt.sh" line, and it has to be set 
before.

I moved the lines around my .bashrc script and got everything working, but I
thought the instructions could be a bit more explicit about how to set these
preference variables, especially because this is a silent failure situation;
the preference doesn't work if you get the order wrong and there are no
warnings or errors to guide you.

This patch started as a PR on the official Github project two years ago (
https://github.com/git/git/pull/425), back when I didn't know the official
process for submitting patches. Luckily, a kind user (@dscho) saw it and
pointed me in the right direction to get it submitted.

This will be my first time submitting a patch, so hopefully I've figured out
the process.

Edward D'Souza (1):
  git-prompt.sh: update shell variable instructions.

 contrib/completion/git-prompt.sh | 5 +++++
 1 file changed, 5 insertions(+)


base-commit: cb5918aa0d50f50e83787f65c2ddc3dcb10159fe
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-255%2Fghedsouza%2Fpatch-1-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-255/ghedsouza/patch-1-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/255
-- 
gitgitgadget

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/1] git-prompt.sh: update shell variable instructions.
  2019-06-05 15:06 [PATCH 0/1] Improve instructions around how to set git-prompt preference variables Edward D'Souza via GitGitGadget
@ 2019-06-05 15:06 ` Edward D'Souza via GitGitGadget
  2019-06-05 16:06   ` SZEDER Gábor
  0 siblings, 1 reply; 4+ messages in thread
From: Edward D'Souza via GitGitGadget @ 2019-06-05 15:06 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Edward D'Souza

From: Edward D'Souza <edsouza@gmail.com>

Clarify the need to set variables like GIT_PS1_SHOWDIRTYSTATE before
"source ~/.git-prompt.sh" is executed in your shell init process.

If you set these preferences too late i.e. after .git-prompt.sh executes,
they will silently fail to take effect.

Signed-off-by: Edward D'Souza <edsouza@gmail.com>
---
 contrib/completion/git-prompt.sh | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
index c6cbef38c2..ab5bcc0fec 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh
@@ -35,6 +35,11 @@
 #
 # The prompt status always includes the current branch name.
 #
+# The prompt can be customized by setting various shell variables
+# (GIT_PS1_SHOWDIRTYSTATE, GIT_PS1_SHOWSTASHSTATE, etc.), which are described
+# below. Make sure that these variables get set *before* the
+# "source ~/.git-prompt.sh" line from step 2 (above) runs.
+#
 # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
 # unstaged (*) and staged (+) changes will be shown next to the branch
 # name.  You can configure this per-repository with the
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] git-prompt.sh: update shell variable instructions.
  2019-06-05 15:06 ` [PATCH 1/1] git-prompt.sh: update shell variable instructions Edward D'Souza via GitGitGadget
@ 2019-06-05 16:06   ` SZEDER Gábor
  2019-06-05 19:26     ` Edward D'Souza
  0 siblings, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2019-06-05 16:06 UTC (permalink / raw)
  To: Edward D'Souza via GitGitGadget
  Cc: git, Junio C Hamano, Edward D'Souza

On Wed, Jun 05, 2019 at 08:06:07AM -0700, Edward D'Souza via GitGitGadget wrote:
> From: Edward D'Souza <edsouza@gmail.com>
> 
> Clarify the need to set variables like GIT_PS1_SHOWDIRTYSTATE before
> "source ~/.git-prompt.sh" is executed in your shell init process.
> 
> If you set these preferences too late i.e. after .git-prompt.sh executes,
> they will silently fail to take effect.

I can't reproduce this.  It doesn't matter when these variables are
set, because __git_ps1() checks them each time it is invoked, it
always has.

  $ echo $GIT_PS1_SHOWSTASHSTATE $GIT_PS1_SHOWDIRTYSTATE $GIT_PS1_SHOWUNTRACKEDFILES
  
  /tmp/repo$ git init
  Initialized empty Git repository in /tmp/repo/.git/
  /tmp/repo (master)$ echo 1 >file
  /tmp/repo (master)$ git add file
  /tmp/repo (master)$ git commit -q -m initial
  /tmp/repo (master)$ echo 2 >file
  /tmp/repo (master)$ git stash 
  Saved working directory and index state WIP on master: 5ae0413 initial
  /tmp/repo (master)$ echo 3 >file
  /tmp/repo (master)$ git add file
  /tmp/repo (master)$ echo 4 >file
  /tmp/repo (master)$ >untracked
  /tmp/repo (master)$ GIT_PS1_SHOWSTASHSTATE=y
  /tmp/repo (master $)$ GIT_PS1_SHOWDIRTYSTATE=y
  /tmp/repo (master *+$)$ GIT_PS1_SHOWUNTRACKEDFILES=y
  /tmp/repo (master *+$%)$ unset GIT_PS1_SHOWSTASHSTATE GIT_PS1_SHOWDIRTYSTATE GIT_PS1_SHOWUNTRACKEDFILES
  /tmp/repo (master)$ 

Note that some of these status indicators are controlled not only by
environment variables but by corresponding 'bash.<indicator>' config
variables as well.  Even if the env var is set to enable the status
indicator globally, the config setting can still override that to
allow disabling potentially expensive indicators on a per-repo basis.
Is it possible that you had e.g. 'bash.showDirtyState = false' in your
config somewhere?

Anyway, even if the issue were real, this patch goes in the wrong
direction: instead of requiring a workaround from users, we should
rather fix the issue.

> Signed-off-by: Edward D'Souza <edsouza@gmail.com>
> ---
>  contrib/completion/git-prompt.sh | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> index c6cbef38c2..ab5bcc0fec 100644
> --- a/contrib/completion/git-prompt.sh
> +++ b/contrib/completion/git-prompt.sh
> @@ -35,6 +35,11 @@
>  #
>  # The prompt status always includes the current branch name.
>  #
> +# The prompt can be customized by setting various shell variables
> +# (GIT_PS1_SHOWDIRTYSTATE, GIT_PS1_SHOWSTASHSTATE, etc.), which are described
> +# below. Make sure that these variables get set *before* the
> +# "source ~/.git-prompt.sh" line from step 2 (above) runs.
> +#
>  # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
>  # unstaged (*) and staged (+) changes will be shown next to the branch
>  # name.  You can configure this per-repository with the
> -- 
> gitgitgadget


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] git-prompt.sh: update shell variable instructions.
  2019-06-05 16:06   ` SZEDER Gábor
@ 2019-06-05 19:26     ` Edward D'Souza
  0 siblings, 0 replies; 4+ messages in thread
From: Edward D'Souza @ 2019-06-05 19:26 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Edward D'Souza via GitGitGadget, git, Junio C Hamano

Confirming that I can't reproduce this either. Should have done that
first before continuing with a PR from two years ago!

On Wed, Jun 5, 2019 at 12:07 PM SZEDER Gábor <szeder.dev@gmail.com> wrote:
>
> On Wed, Jun 05, 2019 at 08:06:07AM -0700, Edward D'Souza via GitGitGadget wrote:
> > From: Edward D'Souza <edsouza@gmail.com>
> >
> > Clarify the need to set variables like GIT_PS1_SHOWDIRTYSTATE before
> > "source ~/.git-prompt.sh" is executed in your shell init process.
> >
> > If you set these preferences too late i.e. after .git-prompt.sh executes,
> > they will silently fail to take effect.
>
> I can't reproduce this.  It doesn't matter when these variables are
> set, because __git_ps1() checks them each time it is invoked, it
> always has.
>
>   $ echo $GIT_PS1_SHOWSTASHSTATE $GIT_PS1_SHOWDIRTYSTATE $GIT_PS1_SHOWUNTRACKEDFILES
>
>   /tmp/repo$ git init
>   Initialized empty Git repository in /tmp/repo/.git/
>   /tmp/repo (master)$ echo 1 >file
>   /tmp/repo (master)$ git add file
>   /tmp/repo (master)$ git commit -q -m initial
>   /tmp/repo (master)$ echo 2 >file
>   /tmp/repo (master)$ git stash
>   Saved working directory and index state WIP on master: 5ae0413 initial
>   /tmp/repo (master)$ echo 3 >file
>   /tmp/repo (master)$ git add file
>   /tmp/repo (master)$ echo 4 >file
>   /tmp/repo (master)$ >untracked
>   /tmp/repo (master)$ GIT_PS1_SHOWSTASHSTATE=y
>   /tmp/repo (master $)$ GIT_PS1_SHOWDIRTYSTATE=y
>   /tmp/repo (master *+$)$ GIT_PS1_SHOWUNTRACKEDFILES=y
>   /tmp/repo (master *+$%)$ unset GIT_PS1_SHOWSTASHSTATE GIT_PS1_SHOWDIRTYSTATE GIT_PS1_SHOWUNTRACKEDFILES
>   /tmp/repo (master)$
>
> Note that some of these status indicators are controlled not only by
> environment variables but by corresponding 'bash.<indicator>' config
> variables as well.  Even if the env var is set to enable the status
> indicator globally, the config setting can still override that to
> allow disabling potentially expensive indicators on a per-repo basis.
> Is it possible that you had e.g. 'bash.showDirtyState = false' in your
> config somewhere?
>
> Anyway, even if the issue were real, this patch goes in the wrong
> direction: instead of requiring a workaround from users, we should
> rather fix the issue.
>
> > Signed-off-by: Edward D'Souza <edsouza@gmail.com>
> > ---
> >  contrib/completion/git-prompt.sh | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh
> > index c6cbef38c2..ab5bcc0fec 100644
> > --- a/contrib/completion/git-prompt.sh
> > +++ b/contrib/completion/git-prompt.sh
> > @@ -35,6 +35,11 @@
> >  #
> >  # The prompt status always includes the current branch name.
> >  #
> > +# The prompt can be customized by setting various shell variables
> > +# (GIT_PS1_SHOWDIRTYSTATE, GIT_PS1_SHOWSTASHSTATE, etc.), which are described
> > +# below. Make sure that these variables get set *before* the
> > +# "source ~/.git-prompt.sh" line from step 2 (above) runs.
> > +#
> >  # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
> >  # unstaged (*) and staged (+) changes will be shown next to the branch
> >  # name.  You can configure this per-repository with the
> > --
> > gitgitgadget
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-06-05 19:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 15:06 [PATCH 0/1] Improve instructions around how to set git-prompt preference variables Edward D'Souza via GitGitGadget
2019-06-05 15:06 ` [PATCH 1/1] git-prompt.sh: update shell variable instructions Edward D'Souza via GitGitGadget
2019-06-05 16:06   ` SZEDER Gábor
2019-06-05 19:26     ` Edward D'Souza

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).