Message ID | 20200701093653.3706-2-ben@wijen.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | git clone with --separate-git-dir destroys existing directory content | expand |
On Wed, Jul 1, 2020 at 5:46 AM Ben Wijen <ben@wijen.net> wrote: > 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).
On Wed, Jul 1, 2020 at 12:00 PM Eric Sunshine <sunshine@sunshineco.com> wrote: > [...] For instance, we might do this: > rm -rf dst && > echo foo=bar >realgitdir/config && I meant to use '>>' here, not '>'.
On Wed, Jul 1, 2020 at 12:00 PM Eric Sunshine <sunshine@sunshineco.com> wrote: > 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. [...] And another correction: I meant 'test_expect_success' and 'test_expect_failure', respectively.
diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 84ea2a3eb7..03901c55f2 100755 --- 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 ' test_expect_success 'clone --reference from original' '
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> --- t/t5601-clone.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)