Skip to content

Commit

Permalink
tg: avoid passing '--' options terminator to git cat-file
Browse files Browse the repository at this point in the history
Prior to Git version 2.5.0 the `git cat-file` options parsing contained
some special case code that checked the number of arguments provided
before doing general purpose option parsing.

This has the unfortunate side effect of causing an options terminator
option (`--`) to produce an error.

The extra `--` was added to the cat-file command via several commits
that were first released in topgit-0.19.4.  Although this was an
inadvertent change it caused no harm when using Git version 2.5.0
or later.

Strictly speaking, the `--` should have been placed before the object
the command was attempting to get the type of rather than after.

The `-` character is a perfectly valid ref name character and starting
with Git version 2.10.0 the `git cat-file -t` command does accept a
`--allow-unknown-type` option.  Having a 'refs/heads/--allow-unknown-type'
ref name would need the `--` disambiguation if it were provided without
the leading `refs/heads/` part.

Nevertheless, in these cases we will always be passing the output
of `git rev-parse --verify` which will always be a hash value and
never something that can start with a `-` so the disambiguating `--`
will never be required.

Enitrely emove the extraneous `--` from the `git cat-file -t` commands
to restore compatibility with Git versions prior to 2.5.0.

Reported-by: Jonathan Ross Rogers <[email protected]>
Signed-off-by: Kyle J. McKay <[email protected]>
  • Loading branch information
mackyle committed Apr 26, 2018
1 parent de99b7e commit 93e4622
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tg-annihilate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ if [ -n "$stash" ]; then
tg tag -q -q -m "$stashmsg" --stash $name $stashbr &&
stashhash="$(git rev-parse --quiet --verify refs/tgstash --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "requested --stash failed"
else
tg tag --anonymous $name $stashbr &&
stashhash="$(git rev-parse --quiet --verify TG_STASH --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "anonymous --stash failed"
fi

Expand Down
4 changes: 2 additions & 2 deletions tg-delete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ if [ -n "$stash" ]; then
tg tag -q -q -m "$stashmsg" --stash $name &&
stashhash="$(git rev-parse --quiet --verify refs/tgstash --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "requested --stash failed"
else
tg tag --anonymous $name &&
stashhash="$(git rev-parse --quiet --verify TG_STASH --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "anonymous --stash failed"
fi

Expand Down
8 changes: 4 additions & 4 deletions tg-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ do_base_mode()
tg tag -q -q -m "$stashmsg" --stash "$tgbranch" &&
stashhash="$(git rev-parse --quiet --verify refs/tgstash --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "requested --stash failed"
else
tg tag --anonymous "$tgbranch" &&
stashhash="$(git rev-parse --quiet --verify TG_STASH --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "anonymous --stash failed"
fi

Expand Down Expand Up @@ -433,13 +433,13 @@ stash_now_if_requested() {
tg tag -q -q -m "$msg" --stash "$@" &&
stashhash="$(git rev-parse --quiet --verify refs/tgstash --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "requested --stash failed"
else
tg tag --anonymous "$@" &&
stashhash="$(git rev-parse --quiet --verify TG_STASH --)" &&
[ -n "$stashhash" ] &&
[ "$(git cat-file -t "$stashhash" -- 2>/dev/null)" = "tag" ] ||
[ "$(git cat-file -t "$stashhash" 2>/dev/null)" = "tag" ] ||
die "anonymous --stash failed"
fi
[ -z "$next_no_auto" ] || no_auto="$next_no_auto"
Expand Down

0 comments on commit 93e4622

Please sign in to comment.