Re: [PATCH 3/8] Better Error Handling for add
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jan 1, 2013, 21:39 UTC
- Message-ID
- <7v1ue4a8i0.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1357012655-24974-4-git-send-email-greened@obbligato.org>
"David A. Greene" <greened@obbligato.org> writes:
Show 20 quoted lines
> From: "David A. Greene" <greened@obbligato.org> > > Check refspecs for validity before passing them on to other commands. > This lets us generate more helpful error messages. > > Signed-off-by: David A. Greene <greened@obbligato.org> > --- > contrib/subtree/git-subtree.sh | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh > index 7ceb413..b8a807a 100755 > --- a/contrib/subtree/git-subtree.sh > +++ b/contrib/subtree/git-subtree.sh > @@ -509,8 +509,20 @@ cmd_add() > ensure_clean > > if [ $# -eq 1 ]; then > + ref=$(git check-ref-format --normalize "refs/heads/$1") || > + die "'$1' is not a valid refspec. Are you missing a branch?"
Is a user forbidden from passing a commit that is not at the tip of an existing branch? In other words, is
$ subtree add origin/next~4^2
forbidden?
> + rev=$(git rev-parse --verify $1) || > + die "'$1' is not a valid refspec. Are you missing a branch?" > + > "cmd_add_commit" "$@"
If you want to make sure you give a comit to add_commit, you can probably say something like this:
git rev-parse -q --verify "$1^{commit}" >/dev/null ||
die "'$1' does not refer to a commit"Show 7 quoted lines
> elif [ $# -eq 2 ]; then > + ref=$(git check-ref-format --normalize "refs/heads/$2") || > + die "'$2' is not a valid refspec." > + > + rev=$(git rev-parse --verify $2) || > + die "'$2' is not a valid refspec." > +
Likewise.
> "cmd_add_repository" "$@" > else > say "error: parameters were '$@'"