|
| 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_failure 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_must_fail git submodule update && |
| 22 | + test_path_is_missing b/sm |
| 23 | +' |
| 24 | + |
| 25 | +test_expect_failure SYMLINKS,CASE_INSENSITIVE_FS 'git submodule update must not create submodule behind symlink on case insensitive fs' ' |
| 26 | + rm -rf a b && |
| 27 | + mkdir b && |
| 28 | + ln -s b A && |
| 29 | + test_must_fail git submodule update && |
| 30 | + test_path_is_missing b/sm |
| 31 | +' |
| 32 | + |
| 33 | +prepare_symlink_to_repo() { |
| 34 | + rm -rf a && |
| 35 | + mkdir a && |
| 36 | + git init a/target && |
| 37 | + git -C a/target fetch ../../upstream && |
| 38 | + ln -s target a/sm |
| 39 | +} |
| 40 | + |
| 41 | +test_expect_success SYMLINKS 'git restore --recurse-submodules must not be confused by a symlink' ' |
| 42 | + prepare_symlink_to_repo && |
| 43 | + test_must_fail git restore --recurse-submodules a/sm && |
| 44 | + test_path_is_missing a/sm/submodule_file && |
| 45 | + test_path_is_dir a/target/.git && |
| 46 | + test_path_is_missing a/target/submodule_file |
| 47 | +' |
| 48 | + |
| 49 | +test_expect_failure SYMLINKS 'git restore --recurse-submodules must not migrate git dir of symlinked repo' ' |
| 50 | + prepare_symlink_to_repo && |
| 51 | + rm -rf .git/modules && |
| 52 | + test_must_fail git restore --recurse-submodules a/sm && |
| 53 | + test_path_is_dir a/target/.git && |
| 54 | + test_path_is_missing .git/modules/a/sm && |
| 55 | + test_path_is_missing a/target/submodule_file |
| 56 | +' |
| 57 | + |
| 58 | +test_expect_failure SYMLINKS 'git checkout -f --recurse-submodules must not migrate git dir of symlinked repo when removing submodule' ' |
| 59 | + prepare_symlink_to_repo && |
| 60 | + rm -rf .git/modules && |
| 61 | + test_must_fail git checkout -f --recurse-submodules initial && |
| 62 | + test_path_is_dir a/target/.git && |
| 63 | + test_path_is_missing .git/modules/a/sm |
| 64 | +' |
| 65 | + |
| 66 | +test_done |
0 commit comments