git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [BUG/PATCH] contrib/subtree: allow addition of remote branch with name not locally present
@ 2013-02-27 23:51 Paul Campbell
  2013-02-28  0:20 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Campbell @ 2013-02-27 23:51 UTC (permalink / raw
  To: git
  Cc: Adam Tkac, David Greene, Jesper Lyager Nielsen, Michael Schubert,
	Techlive Zheng

cmd_add() attempts to check for the validity of refspec for the repository
it is about to add as a subtree. It tries to do so before contacting the
repository. If the refspec happens to exist locally (say 'master') then
the test passes and the repo is fetched. If the refspec doesn't exist
locally then the test fails and the remote repo is never contacted.

Removing the tests still works as the git fetch command fails with the
perfectly accurate error:

  fatal: Couldn't find remote ref <refspec>

Signed-off-by: Paul Campbell <pcampbell@carnegiecollege.ac.uk>
---

I must confess to not understanding the comment preceding the
rev-parse test. Given that it is against the rev-parse and not the
cmd_add_repository call I'm assuming it can be removed.

 contrib/subtree/git-subtree.sh | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
index 8a23f58..9a38b18 100755
--- a/contrib/subtree/git-subtree.sh
+++ b/contrib/subtree/git-subtree.sh
@@ -503,14 +503,6 @@ cmd_add()

            "cmd_add_commit" "$@"
        elif [ $# -eq 2 ]; then
-           # Technically we could accept a refspec here but we're
-           # just going to turn around and add FETCH_HEAD under the
-           # specified directory.  Allowing a refspec might be
-           # misleading because we won't do anything with any other
-           # branches fetched via the refspec.
-           git rev-parse -q --verify "$2^{commit}" >/dev/null ||
-           die "'$2' does not refer to a commit"
-
            "cmd_add_repository" "$@"
        else
            say "error: parameters were '$@'"
--
1.8.2.rc1


-- 
Paul [W] Campbell

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [BUG/PATCH] contrib/subtree: allow addition of remote branch with name not locally present
  2013-02-27 23:51 [BUG/PATCH] contrib/subtree: allow addition of remote branch with name not locally present Paul Campbell
@ 2013-02-28  0:20 ` Junio C Hamano
  2013-02-28 21:37   ` Paul Campbell
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2013-02-28  0:20 UTC (permalink / raw
  To: Paul Campbell
  Cc: git, Adam Tkac, David Greene, Jesper Lyager Nielsen,
	Michael Schubert, Techlive Zheng

Paul Campbell <pcampbell@kemitix.net> writes:

> cmd_add() attempts to check for the validity of refspec for the repository
> it is about to add as a subtree. It tries to do so before contacting the
> repository. If the refspec happens to exist locally (say 'master') then
> the test passes and the repo is fetched. If the refspec doesn't exist
> locally then the test fails and the remote repo is never contacted.
>
> Removing the tests still works as the git fetch command fails with the
> perfectly accurate error:
>
>   fatal: Couldn't find remote ref <refspec>
>
> Signed-off-by: Paul Campbell <pcampbell@carnegiecollege.ac.uk>
> ---
>
> I must confess to not understanding the comment preceding the
> rev-parse test. Given that it is against the rev-parse and not the
> cmd_add_repository call I'm assuming it can be removed.

This is contrib/ material and I do not use the command, so anything
I say should be taken with a moderate amount of salt, but I think
the comment is talking about _not_ accepting a full storing refspec,
or worse yet wildcard, e.g.

	refs/heads/topic:refs/remotes/origin/topic
	refs/heads/*:refs/remotes/origin/*

which will not make sense given that you are only adding a single
commit via "cmd_add".  Also, if you have already fetched from the
remote, "rev-parse $2^{commit}" at this point will protect against
a typo by the end user.

As you noticed, checking if $2 is a commit using rev-parse _before_
fetching $2 from the remote repository is not a valid way to check
against such errors.  So I tend to agree that removing the "die"
will be a good idea.

Typing "tipoc" when the user meant "topic" will error out at the
"git fetch" done in cmd_add_repository, but that fetch will happily
fetch and store whatever a refspec specifies, so you might want to
replace the bogus "rev-parse before fetching" check to "reject
refspec" with something else.

>  contrib/subtree/git-subtree.sh | 8 --------
>  1 file changed, 8 deletions(-)
>
> diff --git a/contrib/subtree/git-subtree.sh b/contrib/subtree/git-subtree.sh
> index 8a23f58..9a38b18 100755
> --- a/contrib/subtree/git-subtree.sh
> +++ b/contrib/subtree/git-subtree.sh
> @@ -503,14 +503,6 @@ cmd_add()
>
>             "cmd_add_commit" "$@"
>         elif [ $# -eq 2 ]; then
> -           # Technically we could accept a refspec here but we're
> -           # just going to turn around and add FETCH_HEAD under the
> -           # specified directory.  Allowing a refspec might be
> -           # misleading because we won't do anything with any other
> -           # branches fetched via the refspec.
> -           git rev-parse -q --verify "$2^{commit}" >/dev/null ||
> -           die "'$2' does not refer to a commit"
> -
>             "cmd_add_repository" "$@"
>         else
>             say "error: parameters were '$@'"
> --
> 1.8.2.rc1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [BUG/PATCH] contrib/subtree: allow addition of remote branch with name not locally present
  2013-02-28  0:20 ` Junio C Hamano
@ 2013-02-28 21:37   ` Paul Campbell
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Campbell @ 2013-02-28 21:37 UTC (permalink / raw
  To: Junio C Hamano
  Cc: git, Adam Tkac, David Greene, Jesper Lyager Nielsen,
	Michael Schubert, Techlive Zheng

On Thu, Feb 28, 2013 at 12:20 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Paul Campbell <pcampbell@kemitix.net> writes:
>
>> cmd_add() attempts to check for the validity of refspec for the repository
>> it is about to add as a subtree. It tries to do so before contacting the
>> repository. If the refspec happens to exist locally (say 'master') then
>> the test passes and the repo is fetched. If the refspec doesn't exist
>> locally then the test fails and the remote repo is never contacted.
>>
>> Removing the tests still works as the git fetch command fails with the
>> perfectly accurate error:
>>
>>   fatal: Couldn't find remote ref <refspec>
>>
>> Signed-off-by: Paul Campbell <pcampbell@carnegiecollege.ac.uk>
>> ---
>>
>> I must confess to not understanding the comment preceding the
>> rev-parse test. Given that it is against the rev-parse and not the
>> cmd_add_repository call I'm assuming it can be removed.
>
> This is contrib/ material and I do not use the command, so anything
> I say should be taken with a moderate amount of salt, but I think
> the comment is talking about _not_ accepting a full storing refspec,
> or worse yet wildcard, e.g.
>
>         refs/heads/topic:refs/remotes/origin/topic
>         refs/heads/*:refs/remotes/origin/*
>
> which will not make sense given that you are only adding a single
> commit via "cmd_add".  Also, if you have already fetched from the
> remote, "rev-parse $2^{commit}" at this point will protect against
> a typo by the end user.
>
> As you noticed, checking if $2 is a commit using rev-parse _before_
> fetching $2 from the remote repository is not a valid way to check
> against such errors.  So I tend to agree that removing the "die"
> will be a good idea.
>
> Typing "tipoc" when the user meant "topic" will error out at the
> "git fetch" done in cmd_add_repository, but that fetch will happily
> fetch and store whatever a refspec specifies, so you might want to
> replace the bogus "rev-parse before fetching" check to "reject
> refspec" with something else.

Thanks for the feedback.

Checking for a ':' or a '*' in the refspec should stop the storage
name and wildcards getting through.

Rerolling the patch with new test.

-- 
Paul [W] Campbell

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-02-28 21:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-27 23:51 [BUG/PATCH] contrib/subtree: allow addition of remote branch with name not locally present Paul Campbell
2013-02-28  0:20 ` Junio C Hamano
2013-02-28 21:37   ` Paul Campbell

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).