Re: [PATCH 3/8] Better Error Handling for add

2013-01-01 Thread Junio C Hamano
gree...@obbligato.org writes:

>> 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"
>
> What does $1^{commit} mean?

"$thing^{type}" tells Git to interpret the $thing as that type (and
error out if it can't).

So v1.0.0^{commit} is a less cryptic way to say v1.0.0^0 (there is
no need to say "zeroth parent of a commit is the commit itself?
Yeah, it makes sort of sense" when you learn it).

"git cat-file -t junio-gpg-pub^{blob}" will say "blob", but you will
get a failure from "git rev-parse v1.0.0^{blob}" as you can only
dereference a tag that refers to a commit down to the comit and then
to its top-level tree, but not to a single blob.

And you can ask for the tree object with v1.0.0^{tree}, for example.


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/8] Better Error Handling for add

2013-01-01 Thread greened
Junio C Hamano  writes:

>> 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?

Good point.  It probably shouldn't be.  I think rev-parse should be
enough of a check.

>> +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"

What does $1^{commit} mean?  I think your suggestion is what I want but
I don't know what it means yet.  :)

   -David
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/8] Better Error Handling for add

2013-01-01 Thread Junio C Hamano
"David A. Greene"  writes:

> From: "David A. Greene" 
>
> 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 
> ---
>  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"

>   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 '$@'"
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/8] Better Error Handling for add

2012-12-31 Thread David A. Greene
From: "David A. Greene" 

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 
---
 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?"
+
+   rev=$(git rev-parse --verify $1) ||
+die "'$1' is not a valid refspec.  Are you missing a branch?"
+
"cmd_add_commit" "$@"
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."
+
"cmd_add_repository" "$@"
else
say "error: parameters were '$@'"
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html