diff options
author | Philippe Blain <levraiphilippeblain@gmail.com> | 2022-10-21 17:13:32 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-10-21 22:51:05 +0200 |
commit | a50fcc13dda245b39e63a2052107456e0b7e85f7 (patch) | |
tree | b7506fb906dda805acb1f9da0a842c16901bf097 /contrib/subtree | |
parent | test-lib-functions: mark 'test_commit' variables as 'local' (diff) | |
download | git-a50fcc13dda245b39e63a2052107456e0b7e85f7.tar.xz git-a50fcc13dda245b39e63a2052107456e0b7e85f7.zip |
subtree: use 'git rev-parse --verify [--quiet]' for better error messages
There are three occurences of 'git rev-parse <rev>' in 'git-subtree.sh'
where the command expects a revision and the script dies or exits if the
revision can't be found. In that case, the error message from 'git
rev-parse' is:
$ git rev-parse <bad rev>
<bad rev>
fatal: ambiguous argument '<bad rev>': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
This is a little confusing to the user, since this error message is
outputed by 'git subtree'.
At these points in the script, we know that we are looking for a single
revision, so be explicit by using '--verify', resulting in a little
better error message:
$ git rev-parse --verify <bad rev>
fatal: Needed a single revision
In the two occurences where we 'die' if 'git rev-parse' fails, 'git
subtree' outputs "could not rev-parse split hash $b from commit $sq", so
we actually do not need the supplementary error message from 'git
rev-parse'; add '--quiet' to silence it.
In the third occurence, we 'exit', so keep the error message from 'git
rev-parse'. Note that this messsage is still suboptimal since it can be
understood to mean that 'git rev-parse' did not receive a single
revision as argument, which is not the case here: the command did
receive a single revision, but the revision is not resolvable to an
available object.
The alternative would be to use '--' after the revision, as suggested by
the first error message, resulting in a clearer error message:
$ git rev-parse <bad rev> --
fatal: bad revision '<bad rev>'
Unfortunately we can't use that syntax because in the more common case
of the revision resolving to a known object, the command outputs the
object's hash, a newline, and the dashdash, which breaks the 'git
subtree' script.
Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/subtree')
-rwxr-xr-x | contrib/subtree/git-subtree.sh | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh index 7562a395c2..49ef493ef9 100755 --- a/contrib/subtree/git-subtree.sh +++ b/contrib/subtree/git-subtree.sh @@ -387,7 +387,7 @@ find_latest_squash () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^{commit}")" || + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || die "could not rev-parse split hash $b from commit $sq" ;; END) @@ -439,7 +439,7 @@ find_existing_splits () { main="$b" ;; git-subtree-split:) - sub="$(git rev-parse "$b^{commit}")" || + sub="$(git rev-parse --verify --quiet "$b^{commit}")" || die "could not rev-parse split hash $b from commit $sq" ;; END) @@ -843,7 +843,7 @@ cmd_add_commit () { git checkout -- "$dir" || exit $? tree=$(git write-tree) || exit $? - headrev=$(git rev-parse HEAD) || exit $? + headrev=$(git rev-parse --verify HEAD) || exit $? if test -n "$headrev" && test "$headrev" != "$rev" then headp="-p $headrev" |