Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (C) 2006 Carl D. Worth <cworth@cworth.org> |
| 4 | # |
| 5 | |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 6 | test_description='test git clone to cleanup after failure |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 7 | |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 8 | This test covers the fact that if git clone fails, it should remove |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 9 | the directory it created, to avoid the user having to manually |
Jeff King | d45420c | 2018-01-02 16:11:39 -0500 | [diff] [blame] | 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 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 15 | |
| 16 | . ./test-lib.sh |
| 17 | |
Jeff King | d45420c | 2018-01-02 16:11:39 -0500 | [diff] [blame] | 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 | |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 25 | test_expect_success 'clone of non-existent source should fail' ' |
| 26 | test_must_fail git clone foo bar |
| 27 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 28 | |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 29 | test_expect_success 'failed clone should not leave a directory' ' |
| 30 | test_path_is_missing bar |
| 31 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 32 | |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 33 | test_expect_success 'create a repo to clone' ' |
| 34 | test_create_repo foo |
| 35 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 36 | |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 37 | test_expect_success 'create objects in repo for later corruption' ' |
| 38 | test_commit -C foo file |
| 39 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 40 | |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 41 | # source repository given to git clone should be relative to the |
Yasushi SHOJI | ced78b3 | 2006-10-14 21:02:51 +0900 | [diff] [blame] | 42 | # current path not to the target dir |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 43 | test_expect_success 'clone of non-existent (relative to $PWD) source should fail' ' |
| 44 | test_must_fail git clone ../foo baz |
| 45 | ' |
Yasushi SHOJI | ced78b3 | 2006-10-14 21:02:51 +0900 | [diff] [blame] | 46 | |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 47 | test_expect_success 'clone should work now that source exists' ' |
| 48 | git clone foo bar |
| 49 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 50 | |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 51 | test_expect_success 'successful clone must leave the directory' ' |
| 52 | test_path_is_dir bar |
| 53 | ' |
Jens Lehmann | 9be1980 | 2013-01-05 21:17:04 +0100 | [diff] [blame] | 54 | |
| 55 | test_expect_success 'failed clone --separate-git-dir should not leave any directories' ' |
Jeff King | d45420c | 2018-01-02 16:11:39 -0500 | [diff] [blame] | 56 | corrupt_repo && |
Jens Lehmann | 9be1980 | 2013-01-05 21:17:04 +0100 | [diff] [blame] | 57 | test_must_fail git clone --separate-git-dir gitdir foo worktree && |
Jeff King | 8486b84 | 2018-01-02 16:09:00 -0500 | [diff] [blame] | 58 | test_path_is_missing gitdir && |
| 59 | test_path_is_missing worktree |
Jens Lehmann | 9be1980 | 2013-01-05 21:17:04 +0100 | [diff] [blame] | 60 | ' |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 61 | |
Jeff King | d45420c | 2018-01-02 16:11:39 -0500 | [diff] [blame] | 62 | test_expect_success 'failed clone into empty leaves directory (vanilla)' ' |
| 63 | mkdir -p empty && |
| 64 | corrupt_repo && |
| 65 | test_must_fail git clone foo empty && |
| 66 | test_dir_is_empty empty |
| 67 | ' |
| 68 | |
| 69 | test_expect_success 'failed clone into empty leaves directory (bare)' ' |
| 70 | mkdir -p empty && |
| 71 | corrupt_repo && |
| 72 | test_must_fail git clone --bare foo empty && |
| 73 | test_dir_is_empty empty |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'failed clone into empty leaves directory (separate)' ' |
| 77 | mkdir -p empty-git empty-wt && |
| 78 | corrupt_repo && |
| 79 | test_must_fail git clone --separate-git-dir empty-git foo empty-wt && |
| 80 | test_dir_is_empty empty-git && |
| 81 | test_dir_is_empty empty-wt |
| 82 | ' |
| 83 | |
| 84 | test_expect_success 'failed clone into empty leaves directory (separate, git)' ' |
| 85 | mkdir -p empty-git && |
| 86 | corrupt_repo && |
| 87 | test_must_fail git clone --separate-git-dir empty-git foo no-wt && |
| 88 | test_dir_is_empty empty-git && |
| 89 | test_path_is_missing no-wt |
| 90 | ' |
| 91 | |
| 92 | test_expect_success 'failed clone into empty leaves directory (separate, wt)' ' |
| 93 | mkdir -p empty-wt && |
| 94 | corrupt_repo && |
| 95 | test_must_fail git clone --separate-git-dir no-git foo empty-wt && |
| 96 | test_path_is_missing no-git && |
| 97 | test_dir_is_empty empty-wt |
| 98 | ' |
| 99 | |
Carl Worth | 5508a61 | 2006-02-17 13:33:28 -0800 | [diff] [blame] | 100 | test_done |