Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='Try various core-level commands in subdirectory. |
| 7 | ' |
| 8 | |
| 9 | . ./test-lib.sh |
Jens Lehmann | ea5070c | 2011-05-25 22:10:41 +0200 | [diff] [blame] | 10 | . "$TEST_DIRECTORY"/lib-read-tree.sh |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 11 | |
| 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" && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 14 | test_write_lines $long >one && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 15 | mkdir dir && |
Eric Sunshine | 0849541 | 2021-12-09 00:11:05 -0500 | [diff] [blame] | 16 | test_write_lines x y z $long a b c >dir/two && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 17 | cp one original.one && |
| 18 | cp dir/two original.two |
| 19 | ' |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 20 | |
| 21 | test_expect_success 'update-index and ls-files' ' |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 22 | git update-index --add one && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 23 | case "$(git ls-files)" in |
Ævar Arnfjörð Bjarmason | 335f878 | 2010-06-24 17:44:49 +0000 | [diff] [blame] | 24 | one) echo pass one ;; |
Eric Sunshine | fe13adb | 2021-12-09 00:10:59 -0500 | [diff] [blame] | 25 | *) echo bad one; return 1 ;; |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 26 | esac && |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 27 | ( |
| 28 | cd dir && |
| 29 | git update-index --add two && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 30 | case "$(git ls-files)" in |
Jonathan Nieder | 18a8269 | 2010-09-06 20:42:54 -0500 | [diff] [blame] | 31 | two) echo pass two ;; |
| 32 | *) echo bad two; exit 1 ;; |
| 33 | esac |
Jens Lehmann | fd4ec4f | 2010-09-06 20:39:54 +0200 | [diff] [blame] | 34 | ) && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 35 | case "$(git ls-files)" in |
Ævar Arnfjörð Bjarmason | 335f878 | 2010-06-24 17:44:49 +0000 | [diff] [blame] | 36 | dir/two"$LF"one) echo pass both ;; |
Eric Sunshine | fe13adb | 2021-12-09 00:10:59 -0500 | [diff] [blame] | 37 | *) echo bad; return 1 ;; |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 38 | esac |
| 39 | ' |
| 40 | |
| 41 | test_expect_success 'cat-file' ' |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 42 | two=$(git ls-files -s dir/two) && |
| 43 | two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 44 | echo "$two" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 45 | git cat-file -p "$two" >actual && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 46 | cmp dir/two actual && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 47 | ( |
| 48 | cd dir && |
| 49 | git cat-file -p "$two" >actual && |
| 50 | cmp two actual |
| 51 | ) |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 52 | ' |
| 53 | rm -f actual dir/actual |
| 54 | |
| 55 | test_expect_success 'diff-files' ' |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 56 | echo a >>one && |
| 57 | echo d >>dir/two && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 58 | case "$(git diff-files --name-only)" in |
Ævar Arnfjörð Bjarmason | 335f878 | 2010-06-24 17:44:49 +0000 | [diff] [blame] | 59 | dir/two"$LF"one) echo pass top ;; |
Eric Sunshine | fe13adb | 2021-12-09 00:10:59 -0500 | [diff] [blame] | 60 | *) echo bad top; return 1 ;; |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 61 | esac && |
| 62 | # diff should not omit leading paths |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 63 | ( |
| 64 | cd dir && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 65 | case "$(git diff-files --name-only)" in |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 66 | dir/two"$LF"one) echo pass subdir ;; |
| 67 | *) echo bad subdir; exit 1 ;; |
| 68 | esac && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 69 | case "$(git diff-files --name-only .)" in |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 70 | dir/two) echo pass subdir limited ;; |
| 71 | *) echo bad subdir limited; exit 1 ;; |
| 72 | esac |
| 73 | ) |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 74 | ' |
| 75 | |
| 76 | test_expect_success 'write-tree' ' |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 77 | top=$(git write-tree) && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 78 | echo $top && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 79 | ( |
| 80 | cd dir && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 81 | sub=$(git write-tree) && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 82 | echo $sub && |
| 83 | test "z$top" = "z$sub" |
| 84 | ) |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 85 | ' |
| 86 | |
| 87 | test_expect_success 'checkout-index' ' |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 88 | git checkout-index -f -u one && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 89 | cmp one original.one && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 90 | ( |
| 91 | cd dir && |
| 92 | git checkout-index -f -u two && |
| 93 | cmp two ../original.two |
| 94 | ) |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 95 | ' |
| 96 | |
| 97 | test_expect_success 'read-tree' ' |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 98 | rm -f one dir/two && |
Elia Pinto | c9e454c | 2014-04-28 05:57:36 -0700 | [diff] [blame] | 99 | tree=$(git write-tree) && |
Jens Lehmann | ea5070c | 2011-05-25 22:10:41 +0200 | [diff] [blame] | 100 | read_tree_u_must_succeed --reset -u "$tree" && |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 101 | cmp one original.one && |
| 102 | cmp dir/two original.two && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 103 | ( |
| 104 | cd dir && |
| 105 | rm -f two && |
Jens Lehmann | ea5070c | 2011-05-25 22:10:41 +0200 | [diff] [blame] | 106 | read_tree_u_must_succeed --reset -u "$tree" && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 107 | cmp two ../original.two && |
| 108 | cmp ../one ../original.one |
| 109 | ) |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 110 | ' |
| 111 | |
Michael J Gruber | 101662c | 2010-11-26 22:32:37 +0700 | [diff] [blame] | 112 | test_expect_success 'alias expansion' ' |
| 113 | ( |
Aaron Schrab | d16ece2 | 2012-12-28 18:03:06 -0500 | [diff] [blame] | 114 | git config alias.test-status-alias status && |
Michael J Gruber | 101662c | 2010-11-26 22:32:37 +0700 | [diff] [blame] | 115 | cd dir && |
| 116 | git status && |
Aaron Schrab | d16ece2 | 2012-12-28 18:03:06 -0500 | [diff] [blame] | 117 | git test-status-alias |
Michael J Gruber | 101662c | 2010-11-26 22:32:37 +0700 | [diff] [blame] | 118 | ) |
| 119 | ' |
Michael J Gruber | 0daed41 | 2011-04-27 10:36:26 +0200 | [diff] [blame] | 120 | |
Junio C Hamano | f57a871 | 2014-07-21 15:09:27 -0700 | [diff] [blame] | 121 | test_expect_success !MINGW '!alias expansion' ' |
Michael J Gruber | 0daed41 | 2011-04-27 10:36:26 +0200 | [diff] [blame] | 122 | pwd >expect && |
| 123 | ( |
Aaron Schrab | d16ece2 | 2012-12-28 18:03:06 -0500 | [diff] [blame] | 124 | git config alias.test-alias-directory !pwd && |
Michael J Gruber | 0daed41 | 2011-04-27 10:36:26 +0200 | [diff] [blame] | 125 | cd dir && |
Aaron Schrab | d16ece2 | 2012-12-28 18:03:06 -0500 | [diff] [blame] | 126 | git test-alias-directory >../actual |
Michael J Gruber | 0daed41 | 2011-04-27 10:36:26 +0200 | [diff] [blame] | 127 | ) && |
| 128 | test_cmp expect actual |
| 129 | ' |
| 130 | |
Michael J Gruber | 7cf16a1 | 2011-04-27 10:36:27 +0200 | [diff] [blame] | 131 | test_expect_success 'GIT_PREFIX for !alias' ' |
| 132 | printf "dir/" >expect && |
| 133 | ( |
Aaron Schrab | d16ece2 | 2012-12-28 18:03:06 -0500 | [diff] [blame] | 134 | git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" && |
Michael J Gruber | 7cf16a1 | 2011-04-27 10:36:27 +0200 | [diff] [blame] | 135 | cd dir && |
Aaron Schrab | d16ece2 | 2012-12-28 18:03:06 -0500 | [diff] [blame] | 136 | git test-alias-directory >../actual |
Michael J Gruber | 7cf16a1 | 2011-04-27 10:36:27 +0200 | [diff] [blame] | 137 | ) && |
| 138 | test_cmp expect actual |
| 139 | ' |
| 140 | |
David Aguilar | 1f5d271 | 2011-05-25 20:37:12 -0700 | [diff] [blame] | 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. |
Junio C Hamano | a3bb8ca | 2016-04-10 12:01:30 -0700 | [diff] [blame] | 144 | echo "dir/" >expect && |
| 145 | write_script diff <<-\EOF && |
| 146 | printf "%s\n" "$GIT_PREFIX" |
| 147 | EOF |
David Aguilar | 1f5d271 | 2011-05-25 20:37:12 -0700 | [diff] [blame] | 148 | ( |
| 149 | cd dir && |
Junio C Hamano | a3bb8ca | 2016-04-10 12:01:30 -0700 | [diff] [blame] | 150 | echo "change" >two && |
Eric Sunshine | f2deabf | 2018-07-01 20:23:56 -0400 | [diff] [blame] | 151 | GIT_EXTERNAL_DIFF=./diff git diff >../actual && |
David Aguilar | 1f5d271 | 2011-05-25 20:37:12 -0700 | [diff] [blame] | 152 | git checkout -- two |
| 153 | ) && |
| 154 | test_cmp expect actual |
| 155 | ' |
| 156 | |
Pavel Roskin | 3dff537 | 2007-02-03 23:49:16 -0500 | [diff] [blame] | 157 | test_expect_success 'no file/rev ambiguity check inside .git' ' |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 158 | git commit -a -m 1 && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 159 | ( |
| 160 | cd .git && |
| 161 | git show -s HEAD |
| 162 | ) |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 163 | ' |
| 164 | |
Stefan Beller | 66d2e04 | 2015-05-18 14:10:26 -0700 | [diff] [blame] | 165 | test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' ' |
| 166 | test_when_finished "rm -fr foo.git" && |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 167 | git clone -s --bare .git foo.git && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 168 | ( |
| 169 | cd foo.git && |
Stefan Beller | 66d2e04 | 2015-05-18 14:10:26 -0700 | [diff] [blame] | 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. |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 173 | GIT_DIR=. git show -s HEAD |
| 174 | ) |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 175 | ' |
| 176 | |
Stefan Beller | 66d2e04 | 2015-05-18 14:10:26 -0700 | [diff] [blame] | 177 | test_expect_success 'no file/rev ambiguity check inside a bare repo' ' |
| 178 | test_when_finished "rm -fr foo.git" && |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 179 | git clone -s --bare .git foo.git && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 180 | ( |
| 181 | cd foo.git && |
| 182 | git show -s HEAD |
| 183 | ) |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 184 | ' |
| 185 | |
Johannes Sixt | 704a314 | 2009-03-04 22:38:24 +0100 | [diff] [blame] | 186 | test_expect_success SYMLINKS 'detection should not be fooled by a symlink' ' |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 187 | git clone -s .git another && |
| 188 | ln -s another yetanother && |
Jens Lehmann | fd3c32c | 2010-09-07 12:29:20 +0200 | [diff] [blame] | 189 | ( |
| 190 | cd yetanother/.git && |
| 191 | git show -s HEAD |
| 192 | ) |
Johannes Schindelin | 6802563 | 2007-01-20 03:09:34 +0100 | [diff] [blame] | 193 | ' |
| 194 | |
Junio C Hamano | c43ce6d | 2006-08-03 14:41:29 -0700 | [diff] [blame] | 195 | test_done |