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

Re: [PATCH] bash completion: Support "divergence from upstream" messages in __git_ps1

From
Thomas Rast <trast@student.ethz.ch>
Date
Jun 14, 2010, 07:42 UTC
Message-ID
<201006140942.43099.trast@student.ethz.ch>
In-Reply-To
<4C13F32B.7060106@pileofstuff.org>
Andrew Sayers wrote:
Show 5 quoted lines
> I've added a message in the "equal to upstream" case, to differentiate
> it from the "no upstream" case.  Again, this is an over-the-shoulder
> issue - when I see an "=" (or " u=") in someone's prompt, I don't have
> to patronise them about whether they've e.g. misconfigured their
> branch.

I omitted it because I thought it would be too cluttery, but then my branches seem to rarely agree with their upstream.

> +       local cfg=( $( git config --get-regexp '^bash\.showUpstream$|^svn-remote\..*\.url$' 2>/dev/null ) )

Doesn't this break if the config value contains spaces? I don't know enough about bash arrays but in my simple tests, the array elements are split between words.

And with the new design, you practically *expect* the config key to contain spaces.

Along the same lines, I think
> +                               GIT_PS1_SHOWUPSTREAM="${cfg[$((n+1))]}"
> +                               if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
can never trigger because bash will never see the empty config string.
Slightly more robust would be to use
  git config --get-regexp '^bash\.showUpstream$|^svn-remote\..*\.url$' \
    2>/dev/null |
  while read key value, do
    # stuff
  done
That still breaks in the case of values containing newlines, though.
> I like the "ref" option, but I'm not really sure when "eval" would be
> useful.  I've changed it here to "cmd" so people are encouraged to put
> their work in a script.
[...]
> +#           cmd=<command> compare HEAD to the output of <command>
[...]
> +		cmd\=*) upstream=$( "${option:4}" ) ;;

"Encourage" is a mild understatement; AFAICS the code doesn't work with more than single-word command any more.

The original intent was that the user could put a (very small) shell script directly in the configuration if the normal DWIMming doesn't fit his neds, perhaps most likely in the case of git-svn (do other remote helpers have the same problem?).

Having to wrap it in a script defeats that point, as it becomes almost as easy to edit the completion script. So I think if it can't eval, you might as well remove it.

BTW, please spell $(command) substitution without the spaces. Your current style does not match what is already in the file.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch
Previous: Andrew SayersNext: Andrew Sayers
Message 14 of 22 in “bash completion: Support "divergence from upstream" warnings in __git_ps1”
  1. 0/2 bash completion: Support "divergence from upstream" warnings in __git_ps1Thomas Rast, Jun 12, 2010
  2. 1/2 rev-list: introduce --count optionThomas Rast, Jun 12, 2010
  3. 2/2 bash completion: Support "divergence from upstream" warnings in __git_ps1Thomas Rast, Jun 12, 2010
  4. Junio C HamanoJun 14, 2010
  5. Thomas RastJun 14, 2010
  6. SZEDER GáborJun 14, 2010
  7. vger doesn't like UTF-8 from send-emailThomas Rast, Jun 12, 2010
  8. send-email: ask about and declare 8bit mailsThomas Rast, Jun 12, 2010
  9. Junio C HamanoJun 12, 2010
  10. Thomas RastJun 13, 2010
  11. Michael WittenJun 13, 2010
  12. Erik Faye-LundJun 14, 2010
  13. bash completion: Support "divergence from upstream" messages in __git_ps1Andrew Sayers, Jun 12, 2010
  14. Thomas RastJun 14, 2010
  15. [PATCHv4] bash completion: Support "divergence from upstream" messages in __git_ps1Andrew Sayers, Jun 15, 2010
  16. Junio C HamanoJun 16, 2010
  17. Thomas RastJun 16, 2010
  18. 0/2 bash completion: Support "divergence from upstream" messages in __git_ps1Andrew Sayers, Jun 17, 2010
  19. Junio C HamanoJun 18, 2010
  20. Andrew SayersJun 18, 2010
  21. 1/2 bash completion: Support "divergence from upstream" messages in __git_ps1Andrew Sayers, Jun 17, 2010
  22. 2/2 bash-completion: Fix __git_ps1 to work with "set -u"Andrew Sayers, Jun 17, 2010

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.