]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5600-clone-fail-cleanup.sh
commit-reach(repo_get_merge_bases_many_dirty): pass on errors
[thirdparty/git.git] / t / t5600-clone-fail-cleanup.sh
1 #!/bin/sh
2 #
3 # Copyright (C) 2006 Carl D. Worth <cworth@cworth.org>
4 #
5
6 test_description='test git clone to cleanup after failure
7
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.
11
12 Unless the directory already exists, in which case we clean up only what we
13 wrote.
14 '
15
16 TEST_PASSES_SANITIZE_LEAK=true
17 . ./test-lib.sh
18
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/
24 }
25
26 test_expect_success 'clone of non-existent source should fail' '
27 test_must_fail git clone foo bar
28 '
29
30 test_expect_success 'failed clone should not leave a directory' '
31 test_path_is_missing bar
32 '
33
34 test_expect_success 'create a repo to clone' '
35 test_create_repo foo
36 '
37
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
42 '
43
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
48 '
49
50 test_expect_success 'clone should work now that source exists' '
51 git clone foo bar
52 '
53
54 test_expect_success 'successful clone must leave the directory' '
55 test_path_is_dir bar
56 '
57
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
63 '
64
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
70 '
71
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
77 '
78
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
85 '
86
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
93 '
94
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
101 '
102
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
108 '
109
110 test_done