blob: 8a518a44ea2d2a65f6ee2d9d88c5a8233476c902 [file] [log] [blame]
David Symondsfed1b5c2007-11-09 20:12:28 +11001#!/bin/sh
2#
3# Copyright (c) 2007 David Symonds
4
5test_description='git checkout from subdirectories'
6
Ævar Arnfjörð Bjarmason9081a422021-11-16 19:27:38 +01007TEST_PASSES_SANITIZE_LEAK=true
David Symondsfed1b5c2007-11-09 20:12:28 +11008. ./test-lib.sh
9
10test_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
25test_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
43test_expect_success 'checkout with empty prefix' '
44
45 rm file0 &&
46 git checkout HEAD -- file0 &&
47 test "base" = "$(cat file0)"
48
49'
50
51test_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 Bellerb0afc022013-10-09 16:35:11 +020062test_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 Symondsfed1b5c2007-11-09 20:12:28 +110069'
70
Junio C Hamano41ac4142008-02-01 01:50:53 -080071test_expect_success 'relative path outside tree should fail' \
Junio C Hamano74359822008-02-28 13:09:30 -080072 'test_must_fail git checkout HEAD -- ../../Makefile'
David Symondsfed1b5c2007-11-09 20:12:28 +110073
Junio C Hamano41ac4142008-02-01 01:50:53 -080074test_expect_success 'incorrect relative path to file should fail (1)' \
Junio C Hamano74359822008-02-28 13:09:30 -080075 'test_must_fail git checkout HEAD -- ../file0'
David Symondsfed1b5c2007-11-09 20:12:28 +110076
Junio C Hamano41ac4142008-02-01 01:50:53 -080077test_expect_success 'incorrect relative path should fail (2)' \
Junio C Hamano74359822008-02-28 13:09:30 -080078 '( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )'
David Symondsfed1b5c2007-11-09 20:12:28 +110079
Junio C Hamano41ac4142008-02-01 01:50:53 -080080test_expect_success 'incorrect relative path should fail (3)' \
Junio C Hamano74359822008-02-28 13:09:30 -080081 '( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )'
David Symondsfed1b5c2007-11-09 20:12:28 +110082
83test_done