Merge branch 'jc/exclusion-doc'
[alt-git.git] / t / t1020-subdirectory.sh
blob8e22b03cdd132bd54f9db44d362c15d129415651
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Try various core-level commands in subdirectory.
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-read-tree.sh
12 test_expect_success setup '
13 long="a b c d e f g h i j k l m n o p q r s t u v w x y z" &&
14 for c in $long; do echo $c; done >one &&
15 mkdir dir &&
16 for c in x y z $long a b c; do echo $c; done >dir/two &&
17 cp one original.one &&
18 cp dir/two original.two
21 test_expect_success 'update-index and ls-files' '
22 git update-index --add one &&
23 case "$(git ls-files)" in
24 one) echo pass one ;;
25 *) echo bad one; exit 1 ;;
26 esac &&
28 cd dir &&
29 git update-index --add two &&
30 case "$(git ls-files)" in
31 two) echo pass two ;;
32 *) echo bad two; exit 1 ;;
33 esac
34 ) &&
35 case "$(git ls-files)" in
36 dir/two"$LF"one) echo pass both ;;
37 *) echo bad; exit 1 ;;
38 esac
41 test_expect_success 'cat-file' '
42 two=$(git ls-files -s dir/two) &&
43 two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
44 echo "$two" &&
45 git cat-file -p "$two" >actual &&
46 cmp dir/two actual &&
48 cd dir &&
49 git cat-file -p "$two" >actual &&
50 cmp two actual
53 rm -f actual dir/actual
55 test_expect_success 'diff-files' '
56 echo a >>one &&
57 echo d >>dir/two &&
58 case "$(git diff-files --name-only)" in
59 dir/two"$LF"one) echo pass top ;;
60 *) echo bad top; exit 1 ;;
61 esac &&
62 # diff should not omit leading paths
64 cd dir &&
65 case "$(git diff-files --name-only)" in
66 dir/two"$LF"one) echo pass subdir ;;
67 *) echo bad subdir; exit 1 ;;
68 esac &&
69 case "$(git diff-files --name-only .)" in
70 dir/two) echo pass subdir limited ;;
71 *) echo bad subdir limited; exit 1 ;;
72 esac
76 test_expect_success 'write-tree' '
77 top=$(git write-tree) &&
78 echo $top &&
80 cd dir &&
81 sub=$(git write-tree) &&
82 echo $sub &&
83 test "z$top" = "z$sub"
87 test_expect_success 'checkout-index' '
88 git checkout-index -f -u one &&
89 cmp one original.one &&
91 cd dir &&
92 git checkout-index -f -u two &&
93 cmp two ../original.two
97 test_expect_success 'read-tree' '
98 rm -f one dir/two &&
99 tree=$(git write-tree) &&
100 read_tree_u_must_succeed --reset -u "$tree" &&
101 cmp one original.one &&
102 cmp dir/two original.two &&
104 cd dir &&
105 rm -f two &&
106 read_tree_u_must_succeed --reset -u "$tree" &&
107 cmp two ../original.two &&
108 cmp ../one ../original.one
112 test_expect_success 'alias expansion' '
114 git config alias.test-status-alias status &&
115 cd dir &&
116 git status &&
117 git test-status-alias
121 test_expect_success !MINGW '!alias expansion' '
122 pwd >expect &&
124 git config alias.test-alias-directory !pwd &&
125 cd dir &&
126 git test-alias-directory >../actual
127 ) &&
128 test_cmp expect actual
131 test_expect_success 'GIT_PREFIX for !alias' '
132 printf "dir/" >expect &&
134 git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
135 cd dir &&
136 git test-alias-directory >../actual
137 ) &&
138 test_cmp expect actual
141 test_expect_success 'GIT_PREFIX for built-ins' '
142 # Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
143 # receives the GIT_PREFIX variable.
144 printf "dir/" >expect &&
145 printf "#!/bin/sh\n" >diff &&
146 printf "printf \"\$GIT_PREFIX\"" >>diff &&
147 chmod +x diff &&
149 cd dir &&
150 printf "change" >two &&
151 GIT_EXTERNAL_DIFF=./diff git diff >../actual
152 git checkout -- two
153 ) &&
154 test_cmp expect actual
157 test_expect_success 'no file/rev ambiguity check inside .git' '
158 git commit -a -m 1 &&
160 cd .git &&
161 git show -s HEAD
165 test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' '
166 test_when_finished "rm -fr foo.git" &&
167 git clone -s --bare .git foo.git &&
169 cd foo.git &&
170 # older Git needed help by exporting GIT_DIR=.
171 # to realize that it is inside a bare repository.
172 # We keep this test around for regression testing.
173 GIT_DIR=. git show -s HEAD
177 test_expect_success 'no file/rev ambiguity check inside a bare repo' '
178 test_when_finished "rm -fr foo.git" &&
179 git clone -s --bare .git foo.git &&
181 cd foo.git &&
182 git show -s HEAD
186 test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
187 git clone -s .git another &&
188 ln -s another yetanother &&
190 cd yetanother/.git &&
191 git show -s HEAD
195 test_done