3 # Copyright (C) 2006 Carl D. Worth <cworth@cworth.org>
6 test_description
='test git clone to cleanup after failure
8 This test covers the fact that if git clone fails, it should remove
9 the directory it created, to avoid the user having to manually
10 remove the directory before attempting a clone again.
12 Unless the directory already exists, in which case we clean up only what we
16 TEST_PASSES_SANITIZE_LEAK
=true
20 test_when_finished
"rmdir foo/.git/objects.bak" &&
21 mkdir foo
/.git
/objects.bak
/ &&
22 test_when_finished
"mv foo/.git/objects.bak/* foo/.git/objects/" &&
23 mv foo
/.git
/objects
/* foo
/.git
/objects.bak
/
26 test_expect_success
'clone of non-existent source should fail' '
27 test_must_fail git clone foo bar
30 test_expect_success
'failed clone should not leave a directory' '
31 test_path_is_missing bar
34 test_expect_success
'create a repo to clone' '
38 test_expect_success
'create objects in repo for later corruption' '
39 test_commit -C foo file &&
40 git -C foo checkout --detach &&
41 test_commit -C foo detached
44 # source repository given to git clone should be relative to the
45 # current path not to the target dir
46 test_expect_success
'clone of non-existent (relative to $PWD) source should fail' '
47 test_must_fail git clone ../foo baz
50 test_expect_success
'clone should work now that source exists' '
54 test_expect_success
'successful clone must leave the directory' '
58 test_expect_success
'failed clone --separate-git-dir should not leave any directories' '
60 test_must_fail git clone --separate-git-dir gitdir foo worktree &&
61 test_path_is_missing gitdir &&
62 test_path_is_missing worktree
65 test_expect_success
'failed clone into empty leaves directory (vanilla)' '
68 test_must_fail git clone foo empty &&
69 test_dir_is_empty empty
72 test_expect_success
'failed clone into empty leaves directory (bare)' '
75 test_must_fail git clone --bare foo empty &&
76 test_dir_is_empty empty
79 test_expect_success
'failed clone into empty leaves directory (separate)' '
80 mkdir -p empty-git empty-wt &&
82 test_must_fail git clone --separate-git-dir empty-git foo empty-wt &&
83 test_dir_is_empty empty-git &&
84 test_dir_is_empty empty-wt
87 test_expect_success
'failed clone into empty leaves directory (separate, git)' '
90 test_must_fail git clone --separate-git-dir empty-git foo no-wt &&
91 test_dir_is_empty empty-git &&
92 test_path_is_missing no-wt
95 test_expect_success
'failed clone into empty leaves directory (separate, wt)' '
98 test_must_fail git clone --separate-git-dir no-git foo empty-wt &&
99 test_path_is_missing no-git &&
100 test_dir_is_empty empty-wt
103 test_expect_success
'transport failure cleans up directory' '
104 test_must_fail git clone --no-local \
105 -u "f() { git-upload-pack \"\$@\"; return 1; }; f" \
107 test_path_is_missing broken-clone