git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/1] git clone: don't clone into non-empty directory

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 6, 2020, 22:40 UTC
Message-ID
<xmqqv9j08dxo.fsf@gitster.c.googlers.com>
In-Reply-To
<20200702081335.16786-2-ben@wijen.net>
Ben Wijen <ben@wijen.net> writes:
> When using git clone with --separate-git-dir realgitdir and
> realgitdir already exists, it's content is destroyed.
>
> So, make sure we don't clone into an existing non-empty directory.

This came from d45420c1 (clone: do not clean up directories we didn't create, 2018-01-02), where we claimed

    Because we know that the only directory we'll write into is
    an empty one, we can handle this case by just passing the
    KEEP_TOPLEVEL flag to our recursive delete (if we could
    write into populated directories, we'd have to keep track of
    what we wrote and what we did not, which would be much
    harder).

The assumed use case is that somebody created an empty directory for our use in a grandparent directory where we have no write permission and gave it to us, and we want to do a "git clone" into it while keeping that directory alive. But we didn't make sure the directory was not empty ourselves---we just assumed it to be empty.

And the originally envisioned use case does not have anything to do with the use of --separate-git-dir at all. So from that point of view, this change does not break the originally envisioned use case, so this probably is not regressing any existing and valid use case that may not involve "--separate-git-dir", but I'd rather see that the commit message explain these things to its readers to justify itself.

Thanks.
Previous: Ben WijenNext: Ben Wijen
Message 12 of 14 in “git clone with --separate-git-dir destroys existing directory content”
  1. 0/2 git clone with --separate-git-dir destroys existing directory contentBen Wijen, Jul 1, 2020
  2. 1/2 git clone: check for non-empty directoryBen Wijen, Jul 1, 2020
  3. Eric SunshineJul 1, 2020
  4. Eric SunshineJul 1, 2020
  5. Eric SunshineJul 2, 2020
  6. 2/2 git clone: don't clone into non-empty directoryBen Wijen, Jul 1, 2020
  7. Eric SunshineJul 1, 2020
  8. BenJul 2, 2020
  9. Eric SunshineJul 1, 2020
  10. 0/1 git clone: don't clone into non-empty directoryBen Wijen, Jul 2, 2020
  11. 1/1 git clone: don't clone into non-empty directoryBen Wijen, Jul 2, 2020
  12. Junio C HamanoJul 6, 2020
  13. 1/1 git clone: don't clone into non-empty directoryBen Wijen, Jul 10, 2020
  14. 0/1 git clone: don't clone into non-empty directoryBen Wijen, Jul 10, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.