| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='check that submodule operations do not follow symlinks' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'prepare' ' |
| 8 | git config --global protocol.file.allow always && |
| 9 | test_commit initial && |
| 10 | git init upstream && |
| 11 | test_commit -C upstream upstream submodule_file && |
| 12 | git submodule add ./upstream a/sm && |
| 13 | test_tick && |
| 14 | git commit -m submodule |
| 15 | ' |
| 16 | |
| 17 | test_expect_success SYMLINKS 'git submodule update must not create submodule behind symlink' ' |
| 18 | rm -rf a b && |
| 19 | mkdir b && |
| 20 | ln -s b a && |
| 21 | test_path_is_missing b/sm && |
| 22 | test_must_fail git submodule update && |
| 23 | test_path_is_missing b/sm |
| 24 | ' |
| 25 | |
| 26 | test_expect_success SYMLINKS,CASE_INSENSITIVE_FS 'git submodule update must not create submodule behind symlink on case insensitive fs' ' |
| 27 | rm -rf a b && |
| 28 | mkdir b && |
| 29 | ln -s b A && |
| 30 | test_must_fail git submodule update && |
| 31 | test_path_is_missing b/sm |
| 32 | ' |
| 33 | |
| 34 | prepare_symlink_to_repo() { |
| 35 | rm -rf a && |
| 36 | mkdir a && |
| 37 | git init a/target && |
| 38 | git -C a/target fetch ../../upstream && |
| 39 | ln -s target a/sm |
| 40 | } |
| 41 | |
| 42 | test_expect_success SYMLINKS 'git restore --recurse-submodules must not be confused by a symlink' ' |
| 43 | prepare_symlink_to_repo && |
| 44 | test_must_fail git restore --recurse-submodules a/sm && |
| 45 | test_path_is_missing a/sm/submodule_file && |
| 46 | test_path_is_dir a/target/.git && |
| 47 | test_path_is_missing a/target/submodule_file |
| 48 | ' |
| 49 | |
| 50 | test_expect_success SYMLINKS 'git restore --recurse-submodules must not migrate git dir of symlinked repo' ' |
| 51 | prepare_symlink_to_repo && |
| 52 | rm -rf .git/modules && |
| 53 | test_must_fail git restore --recurse-submodules a/sm && |
| 54 | test_path_is_dir a/target/.git && |
| 55 | test_path_is_missing .git/modules/a/sm && |
| 56 | test_path_is_missing a/target/submodule_file |
| 57 | ' |
| 58 | |
| 59 | test_expect_success SYMLINKS 'git checkout -f --recurse-submodules must not migrate git dir of symlinked repo when removing submodule' ' |
| 60 | prepare_symlink_to_repo && |
| 61 | rm -rf .git/modules && |
| 62 | test_must_fail git checkout -f --recurse-submodules initial && |
| 63 | test_path_is_dir a/target/.git && |
| 64 | test_path_is_missing .git/modules/a/sm |
| 65 | ' |
| 66 | |
| 67 | test_done |