Raw
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-lib.sh
17
18 corrupt_repo () {
19 test_when_finished "rmdir foo/.git/objects.bak" &&
20 mkdir foo/.git/objects.bak/ &&
21 test_when_finished "mv foo/.git/objects.bak/* foo/.git/objects/" &&
22 mv foo/.git/objects/* foo/.git/objects.bak/
23 }
24
25 test_expect_success 'clone of non-existent source should fail' '
26 test_must_fail git clone foo bar
27 '
28
29 test_expect_success 'failed clone should not leave a directory' '
30 test_path_is_missing bar
31 '
32
33 test_expect_success 'create a repo to clone' '
34 test_create_repo foo
35 '
36
37 test_expect_success 'create objects in repo for later corruption' '
38 test_commit -C foo file &&
39 git -C foo checkout --detach &&
40 test_commit -C foo detached
41 '
42
43 # source repository given to git clone should be relative to the
44 # current path not to the target dir
45 test_expect_success 'clone of non-existent (relative to $PWD) source should fail' '
46 test_must_fail git clone ../foo baz
47 '
48
49 test_expect_success 'clone should work now that source exists' '
50 git clone foo bar
51 '
52
53 test_expect_success 'successful clone must leave the directory' '
54 test_path_is_dir bar
55 '
56
57 test_expect_success 'failed clone --separate-git-dir should not leave any directories' '
58 corrupt_repo &&
59 test_must_fail git clone --separate-git-dir gitdir foo worktree &&
60 test_path_is_missing gitdir &&
61 test_path_is_missing worktree
62 '
63
64 test_expect_success 'failed clone into empty leaves directory (vanilla)' '
65 mkdir -p empty &&
66 corrupt_repo &&
67 test_must_fail git clone foo empty &&
68 test_dir_is_empty empty
69 '
70
71 test_expect_success 'failed clone into empty leaves directory (bare)' '
72 mkdir -p empty &&
73 corrupt_repo &&
74 test_must_fail git clone --bare foo empty &&
75 test_dir_is_empty empty
76 '
77
78 test_expect_success 'failed clone into empty leaves directory (separate)' '
79 mkdir -p empty-git empty-wt &&
80 corrupt_repo &&
81 test_must_fail git clone --separate-git-dir empty-git foo empty-wt &&
82 test_dir_is_empty empty-git &&
83 test_dir_is_empty empty-wt
84 '
85
86 test_expect_success 'failed clone into empty leaves directory (separate, git)' '
87 mkdir -p empty-git &&
88 corrupt_repo &&
89 test_must_fail git clone --separate-git-dir empty-git foo no-wt &&
90 test_dir_is_empty empty-git &&
91 test_path_is_missing no-wt
92 '
93
94 test_expect_success 'failed clone into empty leaves directory (separate, wt)' '
95 mkdir -p empty-wt &&
96 corrupt_repo &&
97 test_must_fail git clone --separate-git-dir no-git foo empty-wt &&
98 test_path_is_missing no-git &&
99 test_dir_is_empty empty-wt
100 '
101
102 test_expect_success 'transport failure cleans up directory' '
103 test_must_fail git clone --no-local \
104 -u "f() { git-upload-pack \"\$@\"; return 1; }; f" \
105 foo broken-clone &&
106 test_path_is_missing broken-clone
107 '
108
109 test_done