All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Roskin <proski@gnu.org>
To: git <git@vger.kernel.org>, Petr Baudis <pasky@ucw.cz>
Subject: [PATCH] gittrack.sh accepts invalid branch names
Date: Wed, 20 Apr 2005 15:48:30 -0400	[thread overview]
Message-ID: <1114026510.15186.15.camel@dv> (raw)

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


             reply	other threads:[~2005-04-20 19:44 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-20 19:48 Pavel Roskin [this message]
2005-04-20 23:21 ` [PATCH] gittrack.sh accepts invalid branch names Petr Baudis
2005-04-21  1:28   ` Pavel Roskin
2005-04-20 23:22 ` Paul Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1114026510.15186.15.camel@dv \
    --to=proski@gnu.org \
    --cc=git@vger.kernel.org \
    --cc=pasky@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.