git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: "Robert P. J. Day" <rpjday@crashcourse.ca>
Cc: Stephan Janssen <sjanssen@you-get.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: Git removes existing folder when cancelling clone
Date: Tue, 2 Jan 2018 15:04:43 -0500	[thread overview]
Message-ID: <20180102200443.GA1703@sigill.intra.peff.net> (raw)
In-Reply-To: <alpine.LFD.2.21.1801020610400.14363@localhost.localdomain>

On Tue, Jan 02, 2018 at 06:12:35AM -0500, Robert P. J. Day wrote:

> > I just noticed the following behaviour on macOS 10.13.2 running Git v2.15.0:
> >
> > 1. `mkdir new-folder`
> > 2. `ls` - shows new-folder
> > 3. `git clone [repo] new-folder`
> > 4. Git asks for password
> > 5. I cancel by pressing ctrl+c
> >
> > Result:
> > `ls` no longer shows new-folder.
> >
> > Expected result:
> > `ls` shows new-folder
> >
> > I’m not sure whether this might be a case of ‘works as intended’,
> > but it’s not what I’d expect.
> 
>   i'm *pretty* sure that the optional directory name you supply is
> meant to represent a directory you want git to *create* for you, not
> one that already exists. that means the behaviour you see makes sense
> -- if git assumes it was supposed to create the directory, and you
> cancel the clone, it reasonably assumes it should get rid of it.

Correct. In the early days we required that the "new-folder" directory
not exist, and the initial "git clone" would have bailed in that case.
Any directory we removed would have been one we created.

That changed in 55892d2398 (Allow cloning to an existing empty
directory, 2009-01-11), and we continue to allow only empty directories.

So I don't think there's an urgent data-loss bug here; we will only ever
destroy an empty directory. However, the original intent was to leave
the filesystem as we found it on a failed or aborted clone, and we
obviously don't do that in this case. So it might be nice if we could
restore it to an empty directory.

Restoring the original contents in the general case is hard, since other
parts of the clone may have created arbitrary files. But if we know the
original is just empty, we can simply delete everything in it, but not
the outer directory.

-Peff

  reply	other threads:[~2018-01-02 20:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-02 11:10 Git removes existing folder when cancelling clone Stephan Janssen
2018-01-02 11:12 ` Robert P. J. Day
2018-01-02 20:04   ` Jeff King [this message]
2018-01-02 21:07     ` [PATCH 0/4] " Jeff King
2018-01-02 21:08       ` [PATCH 1/4] t5600: fix outdated comment about unborn HEAD Jeff King
2018-01-02 21:09       ` [PATCH 2/4] t5600: modernize style Jeff King
2018-01-02 21:10       ` [PATCH 3/4] clone: factor out dir_exists() helper Jeff King
2018-01-04 23:47         ` Junio C Hamano
2018-01-04 23:54           ` Jeff King
2018-01-05  0:22             ` Jeff King
2018-01-05 19:19               ` Junio C Hamano
2018-01-02 21:11       ` [PATCH 4/4] clone: do not clean up directories we didn't create Jeff King
2018-01-02 22:49         ` Eric Sunshine
2018-01-02 23:39           ` Jeff King
2018-01-05 18:50             ` Junio C Hamano
2018-01-04 23:48         ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180102200443.GA1703@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=rpjday@crashcourse.ca \
    --cc=sjanssen@you-get.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).