git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gittrack.sh accepts invalid branch names
@ 2005-04-20 19:48 Pavel Roskin
  2005-04-20 23:21 ` Petr Baudis
  2005-04-20 23:22 ` Paul Jackson
  0 siblings, 2 replies; 4+ messages in thread
From: Pavel Roskin @ 2005-04-20 19:48 UTC (permalink / raw)
  To: git, Petr Baudis

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


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

end of thread, other threads:[~2005-04-21  1:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-20 19:48 [PATCH] gittrack.sh accepts invalid branch names Pavel Roskin
2005-04-20 23:21 ` Petr Baudis
2005-04-21  1:28   ` Pavel Roskin
2005-04-20 23:22 ` Paul Jackson

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 NNTP newsgroup(s).