David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 David Symonds |
| 4 | |
| 5 | test_description='git checkout from subdirectories' |
| 6 | |
Ævar Arnfjörð Bjarmason | 9081a42 | 2021-11-16 19:27:38 +0100 | [diff] [blame] | 7 | TEST_PASSES_SANITIZE_LEAK=true |
David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success setup ' |
| 11 | |
| 12 | echo "base" > file0 && |
| 13 | git add file0 && |
| 14 | mkdir dir1 && |
| 15 | echo "hello" > dir1/file1 && |
| 16 | git add dir1/file1 && |
| 17 | mkdir dir2 && |
| 18 | echo "bonjour" > dir2/file2 && |
| 19 | git add dir2/file2 && |
| 20 | test_tick && |
| 21 | git commit -m "populate tree" |
| 22 | |
| 23 | ' |
| 24 | |
| 25 | test_expect_success 'remove and restore with relative path' ' |
| 26 | |
| 27 | ( |
| 28 | cd dir1 && |
| 29 | rm ../file0 && |
| 30 | git checkout HEAD -- ../file0 && |
| 31 | test "base" = "$(cat ../file0)" && |
| 32 | rm ../dir2/file2 && |
| 33 | git checkout HEAD -- ../dir2/file2 && |
| 34 | test "bonjour" = "$(cat ../dir2/file2)" && |
| 35 | rm ../file0 ./file1 && |
| 36 | git checkout HEAD -- .. && |
| 37 | test "base" = "$(cat ../file0)" && |
| 38 | test "hello" = "$(cat file1)" |
| 39 | ) |
| 40 | |
| 41 | ' |
| 42 | |
| 43 | test_expect_success 'checkout with empty prefix' ' |
| 44 | |
| 45 | rm file0 && |
| 46 | git checkout HEAD -- file0 && |
| 47 | test "base" = "$(cat file0)" |
| 48 | |
| 49 | ' |
| 50 | |
| 51 | test_expect_success 'checkout with simple prefix' ' |
| 52 | |
| 53 | rm dir1/file1 && |
| 54 | git checkout HEAD -- dir1 && |
| 55 | test "hello" = "$(cat dir1/file1)" && |
| 56 | rm dir1/file1 && |
| 57 | git checkout HEAD -- dir1/file1 && |
| 58 | test "hello" = "$(cat dir1/file1)" |
| 59 | |
| 60 | ' |
| 61 | |
Stefan Beller | b0afc02 | 2013-10-09 16:35:11 +0200 | [diff] [blame] | 62 | test_expect_success 'checkout with complex relative path' ' |
| 63 | ( |
| 64 | cd dir1 && |
| 65 | rm file1 && |
| 66 | git checkout HEAD -- ../dir1/../dir1/file1 && |
| 67 | test "hello" = "$(cat file1)" |
| 68 | ) |
David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 69 | ' |
| 70 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 71 | test_expect_success 'relative path outside tree should fail' \ |
Junio C Hamano | 7435982 | 2008-02-28 13:09:30 -0800 | [diff] [blame] | 72 | 'test_must_fail git checkout HEAD -- ../../Makefile' |
David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 73 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 74 | test_expect_success 'incorrect relative path to file should fail (1)' \ |
Junio C Hamano | 7435982 | 2008-02-28 13:09:30 -0800 | [diff] [blame] | 75 | 'test_must_fail git checkout HEAD -- ../file0' |
David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 76 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 77 | test_expect_success 'incorrect relative path should fail (2)' \ |
Junio C Hamano | 7435982 | 2008-02-28 13:09:30 -0800 | [diff] [blame] | 78 | '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )' |
David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 79 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 80 | test_expect_success 'incorrect relative path should fail (3)' \ |
Junio C Hamano | 7435982 | 2008-02-28 13:09:30 -0800 | [diff] [blame] | 81 | '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )' |
David Symonds | fed1b5c | 2007-11-09 20:12:28 +1100 | [diff] [blame] | 82 | |
| 83 | test_done |