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

bash completion for git branch/checkout/etc doesn't escape metacharacters

From
KSKevin Stenerson <kevin@reflexionhealth.com>
Date
Jan 20, 2015, 19:15 UTC
Message-ID
<CAPcx8dzgnChWpTn6po1NF65Mr_hPadUbbNCKHJqght7OG6ksFw@mail.gmail.com>

The bash completion provided with git doesn't escape or quote parens in tag or branch names. Alternatively, it doesn't reject branch or tag names with parenthesis as an invalid name (as it does for names with spaces or tabs) Bash treats parentheses in unquoted words as a word separator.

When encountering this problem I was using git version 2.2.2 and bash version 4.3.11

Steps to reproduce with bash:
    mkdir foo
    cd foo
    git init foo
    touch bar
    git add bar
    git commit -m "Went to a bar"
Then for tags
    git tag 'v1.0.0(215)'
Or branches
    git branch 'mybranch(myuser)'
And the actual bash completion
    git checkout   # Use completion here -- it won't escape the parenthesis
    git checkout master
    git branch -d   # Use completion here -- it won't escape the parenthesis

Similarily, when typing a name with an escape character such as "mytag\(", it won't complete the name from that point.

This appears to be true for other bash meta characters as well such as '<', '>', '|', ';', '&'

----------- Kevin Stenerson kevin@reflexionhealth.com

Message 1 of 1 in “bash completion for git branch/checkout/etc doesn't escape metacharacters”
  1. Kevin StenersonJan 20, 2015

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.