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

[PATCH] gittrack.sh accepts invalid branch names

From
PRPavel Roskin <proski@gnu.org>
Date
Apr 20, 2005, 19:48 UTC
Message-ID
<1114026510.15186.15.camel@dv>
Hello, Petr and everybody!

gittrack.sh allows abbreviated branch names, e.g. it's possible to run "git track lin" when there is a branch called "linus".

I believe it's a bug, not a feature. Please look at this line from gittrack.sh:

grep -q $(echo -e "^$name\t" | sed 's/\./\\./g') .git/remotes

The result of command expansion is subjected to word splitting, which means the trailing tab is removed as a space. So grep doesn't see the tab.

The way to avoid word splitting would be to quote "$()", but it would make the shell code too hairy. I'm not even sure all shells would interpret "$("$name")" correctly.

So I decided to use tab directly in the sed expression. I cannot think of any portable way to avoid grep completely ("q" is a GNU sed extension, and we want to support BSD, I think), so it's still there, looking for any output from sed.

Signed-off-by: Pavel Roskin <proski@gnu.org>
--- a/gittrack.sh
+++ b/gittrack.sh
@@ -35,7 +35,7 @@ die () {
 mkdir -p .git/heads
 
 if [ "$name" ]; then
-	grep -q $(echo -e "^$name\t" | sed 's/\./\\./g') .git/remotes || \
+	sed -ne "/^$name\t/p" .git/remotes | grep -q . || \
 		[ -s ".git/heads/$name" ] || \
 		die "unknown branch \"$name\""
 
-- 
Regards,
Pavel Roskin
Next: Petr Baudis
Message 1 of 4 in “gittrack.sh accepts invalid branch names”
  1. gittrack.sh accepts invalid branch namesPavel Roskin, Apr 20, 2005
  2. Petr BaudisApr 20, 2005
  3. Pavel RoskinApr 21, 2005
  4. Paul JacksonApr 20, 2005

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.