Merge branch 'cp/git-flush-is-an-env-bool'
[alt-git.git] / t / t5600-clone-fail-cleanup.sh
blobc814afa5656cca57469d0bff5711bc25229d037a
1 #!/bin/sh
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
13 wrote.
16 TEST_PASSES_SANITIZE_LEAK=true
17 . ./test-lib.sh
19 corrupt_repo () {
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' '
35 test_create_repo foo
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' '
51 git clone foo bar
54 test_expect_success 'successful clone must leave the directory' '
55 test_path_is_dir bar
58 test_expect_success 'failed clone --separate-git-dir should not leave any directories' '
59 corrupt_repo &&
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)' '
66 mkdir -p empty &&
67 corrupt_repo &&
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)' '
73 mkdir -p empty &&
74 corrupt_repo &&
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 &&
81 corrupt_repo &&
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)' '
88 mkdir -p empty-git &&
89 corrupt_repo &&
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)' '
96 mkdir -p empty-wt &&
97 corrupt_repo &&
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" \
106 foo broken-clone &&
107 test_path_is_missing broken-clone
110 test_done