* git clone NonExistentLocation @ 2011-02-17 9:01 Stefan Naewe 2011-02-17 12:39 ` Michael J Gruber 0 siblings, 1 reply; 10+ messages in thread From: Stefan Naewe @ 2011-02-17 9:01 UTC (permalink / raw) To: git@vger.kernel.org Hi. If I do: $ uname -a Linux as100897 2.6.26-2-686 #1 SMP Thu Nov 25 01:53:57 UTC 2010 i686 GNU/Linux $ git version git version 1.7.4.1 $ ls -l NonExistentLocation ls: cannot access NonExistentLocation: No such file or directory $ git clone NonExistentLocation Cloning into NonExistentLocation... warning: You appear to have cloned an empty repository. $ I get a new (empty) git repository in 'NonExistentLocation': $ tree -a NonExistentLocation NonExistentLocation `-- .git |-- HEAD |-- branches |-- config |-- description |-- hooks | |-- applypatch-msg.sample | |-- commit-msg.sample | |-- post-commit.sample | |-- post-receive.sample | |-- post-update.sample | |-- pre-applypatch.sample | |-- pre-commit.sample | |-- pre-rebase.sample | |-- prepare-commit-msg.sample | `-- update.sample |-- info | `-- exclude |-- objects | |-- info | `-- pack `-- refs |-- heads `-- tags 10 directories, 14 files Is this the intended behaviour ? Thanks, Stefan -- ---------------------------------------------------------------- /dev/random says: An ounce of application is worth a ton of abstraction. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-17 9:01 git clone NonExistentLocation Stefan Naewe @ 2011-02-17 12:39 ` Michael J Gruber 2011-02-17 12:52 ` Stefan Naewe 0 siblings, 1 reply; 10+ messages in thread From: Michael J Gruber @ 2011-02-17 12:39 UTC (permalink / raw) To: Stefan Naewe; +Cc: git@vger.kernel.org Stefan Naewe venit, vidit, dixit 17.02.2011 10:01: > Hi. > > If I do: > > $ uname -a > Linux as100897 2.6.26-2-686 #1 SMP Thu Nov 25 01:53:57 UTC 2010 i686 GNU/Linux > $ git version > git version 1.7.4.1 > $ ls -l NonExistentLocation > ls: cannot access NonExistentLocation: No such file or directory > $ git clone NonExistentLocation > Cloning into NonExistentLocation... > warning: You appear to have cloned an empty repository. > $ > > I get a new (empty) git repository in 'NonExistentLocation': > > $ tree -a NonExistentLocation > NonExistentLocation > `-- .git > |-- HEAD > |-- branches > |-- config > |-- description > |-- hooks > | |-- applypatch-msg.sample > | |-- commit-msg.sample > | |-- post-commit.sample > | |-- post-receive.sample > | |-- post-update.sample > | |-- pre-applypatch.sample > | |-- pre-commit.sample > | |-- pre-rebase.sample > | |-- prepare-commit-msg.sample > | `-- update.sample > |-- info > | `-- exclude > |-- objects > | |-- info > | `-- pack > `-- refs > |-- heads > `-- tags > > 10 directories, 14 files > > Is this the intended behaviour ? > > Thanks, > Stefan It is useful, and it even gives you a warning that it still might not be what you intended. Would be funny if it were accidental. Indeed, a git "log -S" on that warning reveals that it was introduced intentionally in 86ac751 (Allow cloning an empty repository, 2009-01-23) Michael ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-17 12:39 ` Michael J Gruber @ 2011-02-17 12:52 ` Stefan Naewe 2011-02-17 12:59 ` Michael J Gruber 0 siblings, 1 reply; 10+ messages in thread From: Stefan Naewe @ 2011-02-17 12:52 UTC (permalink / raw) To: Michael J Gruber; +Cc: git@vger.kernel.org On 2/17/2011 1:39 PM, Michael J Gruber wrote: > > It is useful, and it even gives you a warning that it still might not be > what you intended. Would be funny if it were accidental. Indeed, a git > "log -S" on that warning reveals that it was introduced intentionally in > > 86ac751 (Allow cloning an empty repository, 2009-01-23) OK. But that's about 'cloning an empty repository'. 'NonExistentLocation' is not empty initially - it simply does not exist. Contrast that to 'git clone http://url.does.not.exist'. You don't get an empty repository in 'url.does.not.exist' after running that. Regards, Stefan -- ---------------------------------------------------------------- /dev/random says: ==/==/==/==Police tagline==/==/==Do not cross ==/==/==/== ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-17 12:52 ` Stefan Naewe @ 2011-02-17 12:59 ` Michael J Gruber 2011-02-17 14:03 ` Sverre Rabbelier 0 siblings, 1 reply; 10+ messages in thread From: Michael J Gruber @ 2011-02-17 12:59 UTC (permalink / raw) To: Stefan Naewe; +Cc: git@vger.kernel.org, Sverre Rabbelier Stefan Naewe venit, vidit, dixit 17.02.2011 13:52: > On 2/17/2011 1:39 PM, Michael J Gruber wrote: >> >> It is useful, and it even gives you a warning that it still might not be >> what you intended. Would be funny if it were accidental. Indeed, a git >> "log -S" on that warning reveals that it was introduced intentionally in >> >> 86ac751 (Allow cloning an empty repository, 2009-01-23) > > OK. But that's about 'cloning an empty repository'. > 'NonExistentLocation' is not empty initially - it simply does > not exist. > > Contrast that to 'git clone http://url.does.not.exist'. You don't > get an empty repository in 'url.does.not.exist' after running that. OK, the transport layer errors out in that case. Rereading Sverre's commit message, I'm still not sure whether this case was intended or not. The test case covers existing empty repos only. So I'm cc'ing him and holding back by documentation patch. Sverre, with your 86ac751, the following two are equivalent (modulo a warning) on a nonexisting dir: git clone dir git init dir Is that intentional? Michael ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-17 12:59 ` Michael J Gruber @ 2011-02-17 14:03 ` Sverre Rabbelier 2011-02-17 16:53 ` Michael J Gruber 0 siblings, 1 reply; 10+ messages in thread From: Sverre Rabbelier @ 2011-02-17 14:03 UTC (permalink / raw) To: Michael J Gruber; +Cc: Stefan Naewe, git@vger.kernel.org Heya, [Thanks for summarizing.] On Thu, Feb 17, 2011 at 12:59, Michael J Gruber <git@drmicha.warpmail.net> wrote: > Sverre, with your 86ac751, the following two are equivalent (modulo a > warning) on a nonexisting dir: > > git clone dir > git init dir > > Is that intentional? No, that was not intentional. The former should still be an error if 'dir' is an empy directory. -- Cheers, Sverre Rabbelier ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-17 14:03 ` Sverre Rabbelier @ 2011-02-17 16:53 ` Michael J Gruber 2011-02-18 4:01 ` Jeff King 0 siblings, 1 reply; 10+ messages in thread From: Michael J Gruber @ 2011-02-17 16:53 UTC (permalink / raw) To: Sverre Rabbelier; +Cc: Stefan Naewe, git@vger.kernel.org Sverre Rabbelier venit, vidit, dixit 17.02.2011 15:03: > Heya, > > [Thanks for summarizing.] > > On Thu, Feb 17, 2011 at 12:59, Michael J Gruber > <git@drmicha.warpmail.net> wrote: >> Sverre, with your 86ac751, the following two are equivalent (modulo a >> warning) on a nonexisting dir: >> >> git clone dir >> git init dir >> >> Is that intentional? > > No, that was not intentional. The former should still be an error if > 'dir' is an empy directory. > Digging a little further: since a nonexisting directory is neither a dir nor a file, clone thinks it is not local (is_local=is_bundle=0). None of the transport_* commands error out since the relevant one is guarded by 86ac751... Reverting that or forcing is_local=1 both help, but how to detect "local nonexisting" reliably? In fact, I don't have a problem with the current state if we document it :) Michael ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-17 16:53 ` Michael J Gruber @ 2011-02-18 4:01 ` Jeff King 2011-02-18 6:02 ` Junio C Hamano 0 siblings, 1 reply; 10+ messages in thread From: Jeff King @ 2011-02-18 4:01 UTC (permalink / raw) To: Michael J Gruber Cc: Junio C Hamano, Sverre Rabbelier, Stefan Naewe, git@vger.kernel.org On Thu, Feb 17, 2011 at 05:53:09PM +0100, Michael J Gruber wrote: > Digging a little further: since a nonexisting directory is neither a dir > nor a file, clone thinks it is not local (is_local=is_bundle=0). None of > the transport_* commands error out since the relevant one is guarded by > 86ac751... > > Reverting that or forcing is_local=1 both help, but how to detect "local > nonexisting" reliably? > > In fact, I don't have a problem with the current state if we document it :) Hmm, the current behavior is even weirder. This clones an empty repository: git clone does-not-exist but this causes an error: git clone does-not-exist new-dir Regardless, I think we should catch this error, as it is likely not what the user intended. Yes, there's a warning, but I just don't see in what circumstance this behavior would be useful, and the downside is that you may have failed to actually create a copy of your data, which could lead to data loss. I think the patch below is the right fix. -- >8 -- Subject: [PATCH] clone: die when trying to clone missing local path Since 86ac751 (Allow cloning an empty repository, 2009-01-23), doing: git clone does-not-exist has created does-not-exist as an empty repository. This was an unintentional side effect of 86ac751. Even weirder, doing: git clone does-not-exist new-dir _does_ fail, making this "feature" (if you want to consider it such) broken. Let's detect this situation and explicitly die. It's almost certainly not what the user intended. This patch also adds two tests. One for the missing path case, and one to confirm that a similar case, cloning a non-repository directory, fails. Signed-off-by: Jeff King <peff@peff.net> --- builtin/clone.c | 5 ++++- t/t5701-clone-local.sh | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 60d9a64..55785d0 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -412,8 +412,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix) path = get_repo_path(repo_name, &is_bundle); if (path) repo = xstrdup(make_nonrelative_path(repo_name)); - else if (!strchr(repo_name, ':')) + else if (!strchr(repo_name, ':')) { + if (!file_exists(repo_name)) + die("repository '%s' does not exist", repo_name); repo = xstrdup(make_absolute_path(repo_name)); + } else repo = repo_name; is_local = path && !is_bundle; diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh index 0f4d487..6972258 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -144,4 +144,17 @@ test_expect_success 'clone empty repository, and then push should not segfault.' test_must_fail git push) ' +test_expect_success 'cloning non-existent directory fails' ' + cd "$D" && + rm -rf does-not-exist && + test_must_fail git clone does-not-exist +' + +test_expect_success 'cloning non-git directory fails' ' + cd "$D" && + rm -rf not-a-git-repo not-a-git-repo-clone && + mkdir not-a-git-repo && + test_must_fail git clone not-a-git-repo not-a-git-repo-clone +' + test_done -- 1.7.4.1.3.g720b9 ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-18 4:01 ` Jeff King @ 2011-02-18 6:02 ` Junio C Hamano 2011-02-18 6:11 ` Jeff King 2011-02-18 10:16 ` Sverre Rabbelier 0 siblings, 2 replies; 10+ messages in thread From: Junio C Hamano @ 2011-02-18 6:02 UTC (permalink / raw) To: Jeff King Cc: Michael J Gruber, Sverre Rabbelier, Stefan Naewe, git@vger.kernel.org Jeff King <peff@peff.net> writes: > I think the patch below is the right fix. > ... > Signed-off-by: Jeff King <peff@peff.net> > --- > builtin/clone.c | 5 ++++- > t/t5701-clone-local.sh | 13 +++++++++++++ > 2 files changed, 17 insertions(+), 1 deletions(-) > > diff --git a/builtin/clone.c b/builtin/clone.c > index 60d9a64..55785d0 100644 > --- a/builtin/clone.c > +++ b/builtin/clone.c > @@ -412,8 +412,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix) > path = get_repo_path(repo_name, &is_bundle); > if (path) > repo = xstrdup(make_nonrelative_path(repo_name)); > - else if (!strchr(repo_name, ':')) > + else if (!strchr(repo_name, ':')) { > + if (!file_exists(repo_name)) > + die("repository '%s' does not exist", repo_name); > repo = xstrdup(make_absolute_path(repo_name)); > + } > else > repo = repo_name; > is_local = path && !is_bundle; Thanks, but I am confused. The stuff goes through make_absolute_path() so we must be certain that this has to be a local filesystem entity _if_ it is a repository. But when will we see a file at repo_name in this new codepath? In what situation would get_repo_path(repo_name, &is_bundle) return NULL but the added file_exists(repo_name) would yield true to bypess your die()? If repo_name is a directory, or a regular file, get_repo_path() would give us a relative path to it, no? IOW, wouldn't the fix be more like this? Your new test script seems to pass with this. diff --git a/builtin/clone.c b/builtin/clone.c index 60d9a64..2ee1fa9 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -413,7 +413,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (path) repo = xstrdup(make_nonrelative_path(repo_name)); else if (!strchr(repo_name, ':')) - repo = xstrdup(make_absolute_path(repo_name)); + die("repository '%s' does not exist", repo_name); else repo = repo_name; is_local = path && !is_bundle; ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-18 6:02 ` Junio C Hamano @ 2011-02-18 6:11 ` Jeff King 2011-02-18 10:16 ` Sverre Rabbelier 1 sibling, 0 replies; 10+ messages in thread From: Jeff King @ 2011-02-18 6:11 UTC (permalink / raw) To: Junio C Hamano Cc: Michael J Gruber, Sverre Rabbelier, Stefan Naewe, git@vger.kernel.org On Thu, Feb 17, 2011 at 10:02:10PM -0800, Junio C Hamano wrote: > Jeff King <peff@peff.net> writes: > > > I think the patch below is the right fix. > > ... > > Signed-off-by: Jeff King <peff@peff.net> > > --- > > builtin/clone.c | 5 ++++- > > t/t5701-clone-local.sh | 13 +++++++++++++ > > 2 files changed, 17 insertions(+), 1 deletions(-) > > > > diff --git a/builtin/clone.c b/builtin/clone.c > > index 60d9a64..55785d0 100644 > > --- a/builtin/clone.c > > +++ b/builtin/clone.c > > @@ -412,8 +412,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix) > > path = get_repo_path(repo_name, &is_bundle); > > if (path) > > repo = xstrdup(make_nonrelative_path(repo_name)); > > - else if (!strchr(repo_name, ':')) > > + else if (!strchr(repo_name, ':')) { > > + if (!file_exists(repo_name)) > > + die("repository '%s' does not exist", repo_name); > > repo = xstrdup(make_absolute_path(repo_name)); > > + } > > else > > repo = repo_name; > > is_local = path && !is_bundle; > > Thanks, but I am confused. > > The stuff goes through make_absolute_path() so we must be certain that > this has to be a local filesystem entity _if_ it is a repository. > > But when will we see a file at repo_name in this new codepath? In what > situation would get_repo_path(repo_name, &is_bundle) return NULL but the > added file_exists(repo_name) would yield true to bypess your die()? Hmm, good point. I didn't look carefully enough into get_repo_path. It is not really about finding a repo, but rather about finding a directory or filename. Plus, my file_exists() isn't quite right, anyway. We really want to make sure $repo_name.git, $repo_name.bundle, etc don't exist. But get_repo_path has already done that for us, so we should just trust its output. > diff --git a/builtin/clone.c b/builtin/clone.c > index 60d9a64..2ee1fa9 100644 > --- a/builtin/clone.c > +++ b/builtin/clone.c > @@ -413,7 +413,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) > if (path) > repo = xstrdup(make_nonrelative_path(repo_name)); > else if (!strchr(repo_name, ':')) > - repo = xstrdup(make_absolute_path(repo_name)); > + die("repository '%s' does not exist", repo_name); > else > repo = repo_name; > is_local = path && !is_bundle; Yeah, I think that is a better fix. -Peff ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: git clone NonExistentLocation 2011-02-18 6:02 ` Junio C Hamano 2011-02-18 6:11 ` Jeff King @ 2011-02-18 10:16 ` Sverre Rabbelier 1 sibling, 0 replies; 10+ messages in thread From: Sverre Rabbelier @ 2011-02-18 10:16 UTC (permalink / raw) To: Junio C Hamano Cc: Jeff King, Michael J Gruber, Stefan Naewe, git@vger.kernel.org Heya, On Fri, Feb 18, 2011 at 07:02, Junio C Hamano <gitster@pobox.com> wrote: > IOW, wouldn't the fix be more like this? Your new test script seems to > pass with this. Thanks for fixing both. -- Cheers, Sverre Rabbelier ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2011-02-18 10:17 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-02-17 9:01 git clone NonExistentLocation Stefan Naewe 2011-02-17 12:39 ` Michael J Gruber 2011-02-17 12:52 ` Stefan Naewe 2011-02-17 12:59 ` Michael J Gruber 2011-02-17 14:03 ` Sverre Rabbelier 2011-02-17 16:53 ` Michael J Gruber 2011-02-18 4:01 ` Jeff King 2011-02-18 6:02 ` Junio C Hamano 2011-02-18 6:11 ` Jeff King 2011-02-18 10:16 ` Sverre Rabbelier
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 NNTP newsgroup(s).