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

Re: [PATCH 1/2] git clone: check for non-empty directory

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jul 1, 2020, 16:00 UTC
Message-ID
<CAPig+cT+cXuM3Asu6+Z25pGV2uRm6K1iAeYVhic9kqk1mS84-g@mail.gmail.com>
In-Reply-To
<20200701093653.3706-2-ben@wijen.net>
On Wed, Jul 1, 2020 at 5:46 AM Ben Wijen <ben@wijen.net> wrote:
Show 15 quoted lines
> When using git clone with --separate-git-dir realgitdir and
> realgitdir already exists, it's content is destroyed.
>
> Extend test to make sure content is left intact
>
> Signed-off-by: Ben Wijen <ben@wijen.net>
> ---
> diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh
> @@ -271,7 +271,8 @@ test_expect_success 'fetch from gitfile parent' '
>  test_expect_success 'clone separate gitdir where target already exists' '
>         rm -rf dst &&
> -       test_must_fail git clone --separate-git-dir realgitdir src dst
> +       test_must_fail git clone --separate-git-dir realgitdir src dst &&
> +       test -f realgitdir/config
>  '

This addresses the immediate problem of the directory content being destroyed, which is good. But, we can future-proof it even more by also verifying (to some degree) that the existing content has not been disturbed. Doing so would give us greater confidence against some future change breaking "realgitdir" in some fashion other than merely emptying it. For instance, we might do this:

    rm -rf dst &&
    echo foo=bar >realgitdir/config &&
    test_must_fail git clone --separate-git-dir realgitdir src dst &&
    grep foo=bar realgitdir/config

One other observation: To preserve bisectability (git-bisect) of git.git itself, we want to ensure that the entire test suite still passes at each point in a patch series. Making this change to the test in its own patch introduces a failure into the test suite, which is undesirable. One way to address this shortcoming would be to temporarily change this test from 'test_must_succeed' to 'test_must_fail', and then flip it back to 'test_must_succeed' in patch 2/2. A cleaner approach is simply to combine the two patches so that the fix and updated test are bundled together (which makes sense anyhow in this case since this patch is so short and need not stand on its own).

Previous: Ben WijenNext: Eric Sunshine
Message 3 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.