blob: 9fdbb2af80e0a82429289d06b24d4dcfac3f263d [file] [log] [blame]
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -07001#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Try various core-level commands in subdirectory.
7'
8
9. ./test-lib.sh
Jens Lehmannea5070c2011-05-25 22:10:41 +020010. "$TEST_DIRECTORY"/lib-read-tree.sh
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070011
12test_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" &&
Eric Sunshine08495412021-12-09 00:11:05 -050014 test_write_lines $long >one &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070015 mkdir dir &&
Eric Sunshine08495412021-12-09 00:11:05 -050016 test_write_lines x y z $long a b c >dir/two &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070017 cp one original.one &&
18 cp dir/two original.two
19'
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070020
21test_expect_success 'update-index and ls-files' '
Junio C Hamano5be60072007-07-02 22:52:14 -070022 git update-index --add one &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070023 case "$(git ls-files)" in
Ævar Arnfjörð Bjarmason335f8782010-06-24 17:44:49 +000024 one) echo pass one ;;
Eric Sunshinefe13adb2021-12-09 00:10:59 -050025 *) echo bad one; return 1 ;;
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070026 esac &&
Jonathan Nieder18a82692010-09-06 20:42:54 -050027 (
28 cd dir &&
29 git update-index --add two &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070030 case "$(git ls-files)" in
Jonathan Nieder18a82692010-09-06 20:42:54 -050031 two) echo pass two ;;
32 *) echo bad two; exit 1 ;;
33 esac
Jens Lehmannfd4ec4f2010-09-06 20:39:54 +020034 ) &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070035 case "$(git ls-files)" in
Ævar Arnfjörð Bjarmason335f8782010-06-24 17:44:49 +000036 dir/two"$LF"one) echo pass both ;;
Eric Sunshinefe13adb2021-12-09 00:10:59 -050037 *) echo bad; return 1 ;;
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070038 esac
39'
40
41test_expect_success 'cat-file' '
Elia Pintoc9e454c2014-04-28 05:57:36 -070042 two=$(git ls-files -s dir/two) &&
43 two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070044 echo "$two" &&
Junio C Hamano5be60072007-07-02 22:52:14 -070045 git cat-file -p "$two" >actual &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070046 cmp dir/two actual &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020047 (
48 cd dir &&
49 git cat-file -p "$two" >actual &&
50 cmp two actual
51 )
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070052'
53rm -f actual dir/actual
54
55test_expect_success 'diff-files' '
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070056 echo a >>one &&
57 echo d >>dir/two &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070058 case "$(git diff-files --name-only)" in
Ævar Arnfjörð Bjarmason335f8782010-06-24 17:44:49 +000059 dir/two"$LF"one) echo pass top ;;
Eric Sunshinefe13adb2021-12-09 00:10:59 -050060 *) echo bad top; return 1 ;;
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070061 esac &&
62 # diff should not omit leading paths
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020063 (
64 cd dir &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070065 case "$(git diff-files --name-only)" in
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020066 dir/two"$LF"one) echo pass subdir ;;
67 *) echo bad subdir; exit 1 ;;
68 esac &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070069 case "$(git diff-files --name-only .)" in
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020070 dir/two) echo pass subdir limited ;;
71 *) echo bad subdir limited; exit 1 ;;
72 esac
73 )
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070074'
75
76test_expect_success 'write-tree' '
Elia Pintoc9e454c2014-04-28 05:57:36 -070077 top=$(git write-tree) &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070078 echo $top &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020079 (
80 cd dir &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070081 sub=$(git write-tree) &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020082 echo $sub &&
83 test "z$top" = "z$sub"
84 )
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070085'
86
87test_expect_success 'checkout-index' '
Junio C Hamano5be60072007-07-02 22:52:14 -070088 git checkout-index -f -u one &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070089 cmp one original.one &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +020090 (
91 cd dir &&
92 git checkout-index -f -u two &&
93 cmp two ../original.two
94 )
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070095'
96
97test_expect_success 'read-tree' '
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -070098 rm -f one dir/two &&
Elia Pintoc9e454c2014-04-28 05:57:36 -070099 tree=$(git write-tree) &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200100 read_tree_u_must_succeed --reset -u "$tree" &&
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -0700101 cmp one original.one &&
102 cmp dir/two original.two &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200103 (
104 cd dir &&
105 rm -f two &&
Jens Lehmannea5070c2011-05-25 22:10:41 +0200106 read_tree_u_must_succeed --reset -u "$tree" &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200107 cmp two ../original.two &&
108 cmp ../one ../original.one
109 )
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -0700110'
111
Michael J Gruber101662c2010-11-26 22:32:37 +0700112test_expect_success 'alias expansion' '
113 (
Aaron Schrabd16ece22012-12-28 18:03:06 -0500114 git config alias.test-status-alias status &&
Michael J Gruber101662c2010-11-26 22:32:37 +0700115 cd dir &&
116 git status &&
Aaron Schrabd16ece22012-12-28 18:03:06 -0500117 git test-status-alias
Michael J Gruber101662c2010-11-26 22:32:37 +0700118 )
119'
Michael J Gruber0daed412011-04-27 10:36:26 +0200120
Junio C Hamanof57a8712014-07-21 15:09:27 -0700121test_expect_success !MINGW '!alias expansion' '
Michael J Gruber0daed412011-04-27 10:36:26 +0200122 pwd >expect &&
123 (
Aaron Schrabd16ece22012-12-28 18:03:06 -0500124 git config alias.test-alias-directory !pwd &&
Michael J Gruber0daed412011-04-27 10:36:26 +0200125 cd dir &&
Aaron Schrabd16ece22012-12-28 18:03:06 -0500126 git test-alias-directory >../actual
Michael J Gruber0daed412011-04-27 10:36:26 +0200127 ) &&
128 test_cmp expect actual
129'
130
Michael J Gruber7cf16a12011-04-27 10:36:27 +0200131test_expect_success 'GIT_PREFIX for !alias' '
132 printf "dir/" >expect &&
133 (
Aaron Schrabd16ece22012-12-28 18:03:06 -0500134 git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
Michael J Gruber7cf16a12011-04-27 10:36:27 +0200135 cd dir &&
Aaron Schrabd16ece22012-12-28 18:03:06 -0500136 git test-alias-directory >../actual
Michael J Gruber7cf16a12011-04-27 10:36:27 +0200137 ) &&
138 test_cmp expect actual
139'
140
David Aguilar1f5d2712011-05-25 20:37:12 -0700141test_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.
Junio C Hamanoa3bb8ca2016-04-10 12:01:30 -0700144 echo "dir/" >expect &&
145 write_script diff <<-\EOF &&
146 printf "%s\n" "$GIT_PREFIX"
147 EOF
David Aguilar1f5d2712011-05-25 20:37:12 -0700148 (
149 cd dir &&
Junio C Hamanoa3bb8ca2016-04-10 12:01:30 -0700150 echo "change" >two &&
Eric Sunshinef2deabf2018-07-01 20:23:56 -0400151 GIT_EXTERNAL_DIFF=./diff git diff >../actual &&
David Aguilar1f5d2712011-05-25 20:37:12 -0700152 git checkout -- two
153 ) &&
154 test_cmp expect actual
155'
156
Pavel Roskin3dff5372007-02-03 23:49:16 -0500157test_expect_success 'no file/rev ambiguity check inside .git' '
Johannes Schindelin68025632007-01-20 03:09:34 +0100158 git commit -a -m 1 &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200159 (
160 cd .git &&
161 git show -s HEAD
162 )
Johannes Schindelin68025632007-01-20 03:09:34 +0100163'
164
Stefan Beller66d2e042015-05-18 14:10:26 -0700165test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' '
166 test_when_finished "rm -fr foo.git" &&
Johannes Schindelin68025632007-01-20 03:09:34 +0100167 git clone -s --bare .git foo.git &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200168 (
169 cd foo.git &&
Stefan Beller66d2e042015-05-18 14:10:26 -0700170 # 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.
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200173 GIT_DIR=. git show -s HEAD
174 )
Johannes Schindelin68025632007-01-20 03:09:34 +0100175'
176
Stefan Beller66d2e042015-05-18 14:10:26 -0700177test_expect_success 'no file/rev ambiguity check inside a bare repo' '
178 test_when_finished "rm -fr foo.git" &&
Johannes Schindelin68025632007-01-20 03:09:34 +0100179 git clone -s --bare .git foo.git &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200180 (
181 cd foo.git &&
182 git show -s HEAD
183 )
Johannes Schindelin68025632007-01-20 03:09:34 +0100184'
185
Johannes Sixt704a3142009-03-04 22:38:24 +0100186test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
Johannes Schindelin68025632007-01-20 03:09:34 +0100187 git clone -s .git another &&
188 ln -s another yetanother &&
Jens Lehmannfd3c32c2010-09-07 12:29:20 +0200189 (
190 cd yetanother/.git &&
191 git show -s HEAD
192 )
Johannes Schindelin68025632007-01-20 03:09:34 +0100193'
194
Junio C Hamanoc43ce6d2006-08-03 14:41:29 -0700195test_done