2006-08-03 23:41:29 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Try various core-level commands in subdirectory.
|
|
|
|
'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
2011-05-25 22:10:41 +02:00
|
|
|
. "$TEST_DIRECTORY"/lib-read-tree.sh
|
2006-08-03 23:41:29 +02:00
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
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" &&
|
|
|
|
for c in $long; do echo $c; done >one &&
|
|
|
|
mkdir dir &&
|
|
|
|
for c in x y z $long a b c; do echo $c; done >dir/two &&
|
|
|
|
cp one original.one &&
|
|
|
|
cp dir/two original.two
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'update-index and ls-files' '
|
2007-07-03 07:52:14 +02:00
|
|
|
git update-index --add one &&
|
2014-04-28 14:57:36 +02:00
|
|
|
case "$(git ls-files)" in
|
2010-06-24 19:44:49 +02:00
|
|
|
one) echo pass one ;;
|
2021-12-09 06:10:59 +01:00
|
|
|
*) echo bad one; return 1 ;;
|
2006-08-03 23:41:29 +02:00
|
|
|
esac &&
|
2010-09-07 03:42:54 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
git update-index --add two &&
|
2014-04-28 14:57:36 +02:00
|
|
|
case "$(git ls-files)" in
|
2010-09-07 03:42:54 +02:00
|
|
|
two) echo pass two ;;
|
|
|
|
*) echo bad two; exit 1 ;;
|
|
|
|
esac
|
2010-09-06 20:39:54 +02:00
|
|
|
) &&
|
2014-04-28 14:57:36 +02:00
|
|
|
case "$(git ls-files)" in
|
2010-06-24 19:44:49 +02:00
|
|
|
dir/two"$LF"one) echo pass both ;;
|
2021-12-09 06:10:59 +01:00
|
|
|
*) echo bad; return 1 ;;
|
2006-08-03 23:41:29 +02:00
|
|
|
esac
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'cat-file' '
|
2014-04-28 14:57:36 +02:00
|
|
|
two=$(git ls-files -s dir/two) &&
|
|
|
|
two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
|
2006-08-03 23:41:29 +02:00
|
|
|
echo "$two" &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git cat-file -p "$two" >actual &&
|
2006-08-03 23:41:29 +02:00
|
|
|
cmp dir/two actual &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
git cat-file -p "$two" >actual &&
|
|
|
|
cmp two actual
|
|
|
|
)
|
2006-08-03 23:41:29 +02:00
|
|
|
'
|
|
|
|
rm -f actual dir/actual
|
|
|
|
|
|
|
|
test_expect_success 'diff-files' '
|
|
|
|
echo a >>one &&
|
|
|
|
echo d >>dir/two &&
|
2014-04-28 14:57:36 +02:00
|
|
|
case "$(git diff-files --name-only)" in
|
2010-06-24 19:44:49 +02:00
|
|
|
dir/two"$LF"one) echo pass top ;;
|
2021-12-09 06:10:59 +01:00
|
|
|
*) echo bad top; return 1 ;;
|
2006-08-03 23:41:29 +02:00
|
|
|
esac &&
|
|
|
|
# diff should not omit leading paths
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
2014-04-28 14:57:36 +02:00
|
|
|
case "$(git diff-files --name-only)" in
|
2010-09-07 12:29:20 +02:00
|
|
|
dir/two"$LF"one) echo pass subdir ;;
|
|
|
|
*) echo bad subdir; exit 1 ;;
|
|
|
|
esac &&
|
2014-04-28 14:57:36 +02:00
|
|
|
case "$(git diff-files --name-only .)" in
|
2010-09-07 12:29:20 +02:00
|
|
|
dir/two) echo pass subdir limited ;;
|
|
|
|
*) echo bad subdir limited; exit 1 ;;
|
|
|
|
esac
|
|
|
|
)
|
2006-08-03 23:41:29 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'write-tree' '
|
2014-04-28 14:57:36 +02:00
|
|
|
top=$(git write-tree) &&
|
2006-08-03 23:41:29 +02:00
|
|
|
echo $top &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
2014-04-28 14:57:36 +02:00
|
|
|
sub=$(git write-tree) &&
|
2010-09-07 12:29:20 +02:00
|
|
|
echo $sub &&
|
|
|
|
test "z$top" = "z$sub"
|
|
|
|
)
|
2006-08-03 23:41:29 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout-index' '
|
2007-07-03 07:52:14 +02:00
|
|
|
git checkout-index -f -u one &&
|
2006-08-03 23:41:29 +02:00
|
|
|
cmp one original.one &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
git checkout-index -f -u two &&
|
|
|
|
cmp two ../original.two
|
|
|
|
)
|
2006-08-03 23:41:29 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree' '
|
|
|
|
rm -f one dir/two &&
|
2014-04-28 14:57:36 +02:00
|
|
|
tree=$(git write-tree) &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed --reset -u "$tree" &&
|
2006-08-03 23:41:29 +02:00
|
|
|
cmp one original.one &&
|
|
|
|
cmp dir/two original.two &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
rm -f two &&
|
2011-05-25 22:10:41 +02:00
|
|
|
read_tree_u_must_succeed --reset -u "$tree" &&
|
2010-09-07 12:29:20 +02:00
|
|
|
cmp two ../original.two &&
|
|
|
|
cmp ../one ../original.one
|
|
|
|
)
|
2006-08-03 23:41:29 +02:00
|
|
|
'
|
|
|
|
|
2010-11-26 16:32:37 +01:00
|
|
|
test_expect_success 'alias expansion' '
|
|
|
|
(
|
2012-12-29 00:03:06 +01:00
|
|
|
git config alias.test-status-alias status &&
|
2010-11-26 16:32:37 +01:00
|
|
|
cd dir &&
|
|
|
|
git status &&
|
2012-12-29 00:03:06 +01:00
|
|
|
git test-status-alias
|
2010-11-26 16:32:37 +01:00
|
|
|
)
|
|
|
|
'
|
2011-04-27 10:36:26 +02:00
|
|
|
|
2014-07-22 00:09:27 +02:00
|
|
|
test_expect_success !MINGW '!alias expansion' '
|
2011-04-27 10:36:26 +02:00
|
|
|
pwd >expect &&
|
|
|
|
(
|
2012-12-29 00:03:06 +01:00
|
|
|
git config alias.test-alias-directory !pwd &&
|
2011-04-27 10:36:26 +02:00
|
|
|
cd dir &&
|
2012-12-29 00:03:06 +01:00
|
|
|
git test-alias-directory >../actual
|
2011-04-27 10:36:26 +02:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-04-27 10:36:27 +02:00
|
|
|
test_expect_success 'GIT_PREFIX for !alias' '
|
|
|
|
printf "dir/" >expect &&
|
|
|
|
(
|
2012-12-29 00:03:06 +01:00
|
|
|
git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
|
2011-04-27 10:36:27 +02:00
|
|
|
cd dir &&
|
2012-12-29 00:03:06 +01:00
|
|
|
git test-alias-directory >../actual
|
2011-04-27 10:36:27 +02:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-05-26 05:37:12 +02:00
|
|
|
test_expect_success 'GIT_PREFIX for built-ins' '
|
|
|
|
# Use GIT_EXTERNAL_DIFF to test that the "diff" built-in
|
|
|
|
# receives the GIT_PREFIX variable.
|
t1020: do not overuse printf and use write_script
The test prepares a sample file "dir/two" with a single incomplete
line in it with "printf", and also prepares a small helper script
"diff" to create a file with a single incomplete line in it, again
with "printf". The output from the latter is compared with an
expected output, again prepared with "printf" hence lacking the
final LF. There is no reason for this test to be using files with
an incomplete line at the end, and these look more like a mistake
of not using
printf "%s\n" "string to be written"
and using
printf "string to be written"
Depending on what would be in $GIT_PREFIX, using the latter form
could be a bug waiting to happen. Correct them.
Also, the test uses hardcoded #!/bin/sh to create a small helper
script. For a small task like what the generated script does, it
does not matter too much in that what appears as /bin/sh would not
be _so_ broken, but while we are at it, use write_script instead,
which happens to make the result easier to read by reducing need
of one level of quoting.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-10 21:01:30 +02:00
|
|
|
echo "dir/" >expect &&
|
|
|
|
write_script diff <<-\EOF &&
|
|
|
|
printf "%s\n" "$GIT_PREFIX"
|
|
|
|
EOF
|
2011-05-26 05:37:12 +02:00
|
|
|
(
|
|
|
|
cd dir &&
|
t1020: do not overuse printf and use write_script
The test prepares a sample file "dir/two" with a single incomplete
line in it with "printf", and also prepares a small helper script
"diff" to create a file with a single incomplete line in it, again
with "printf". The output from the latter is compared with an
expected output, again prepared with "printf" hence lacking the
final LF. There is no reason for this test to be using files with
an incomplete line at the end, and these look more like a mistake
of not using
printf "%s\n" "string to be written"
and using
printf "string to be written"
Depending on what would be in $GIT_PREFIX, using the latter form
could be a bug waiting to happen. Correct them.
Also, the test uses hardcoded #!/bin/sh to create a small helper
script. For a small task like what the generated script does, it
does not matter too much in that what appears as /bin/sh would not
be _so_ broken, but while we are at it, use write_script instead,
which happens to make the result easier to read by reducing need
of one level of quoting.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-10 21:01:30 +02:00
|
|
|
echo "change" >two &&
|
2018-07-02 02:23:56 +02:00
|
|
|
GIT_EXTERNAL_DIFF=./diff git diff >../actual &&
|
2011-05-26 05:37:12 +02:00
|
|
|
git checkout -- two
|
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2007-02-04 05:49:16 +01:00
|
|
|
test_expect_success 'no file/rev ambiguity check inside .git' '
|
2007-01-20 03:09:34 +01:00
|
|
|
git commit -a -m 1 &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd .git &&
|
|
|
|
git show -s HEAD
|
|
|
|
)
|
2007-01-20 03:09:34 +01:00
|
|
|
'
|
|
|
|
|
2015-05-18 23:10:26 +02:00
|
|
|
test_expect_success 'no file/rev ambiguity check inside a bare repo (explicit GIT_DIR)' '
|
|
|
|
test_when_finished "rm -fr foo.git" &&
|
2007-01-20 03:09:34 +01:00
|
|
|
git clone -s --bare .git foo.git &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd foo.git &&
|
2015-05-18 23:10:26 +02:00
|
|
|
# older Git needed help by exporting GIT_DIR=.
|
|
|
|
# to realize that it is inside a bare repository.
|
|
|
|
# We keep this test around for regression testing.
|
2010-09-07 12:29:20 +02:00
|
|
|
GIT_DIR=. git show -s HEAD
|
|
|
|
)
|
2007-01-20 03:09:34 +01:00
|
|
|
'
|
|
|
|
|
2015-05-18 23:10:26 +02:00
|
|
|
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
|
|
|
|
test_when_finished "rm -fr foo.git" &&
|
2007-01-20 03:09:34 +01:00
|
|
|
git clone -s --bare .git foo.git &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd foo.git &&
|
|
|
|
git show -s HEAD
|
|
|
|
)
|
2007-01-20 03:09:34 +01:00
|
|
|
'
|
|
|
|
|
2009-03-04 22:38:24 +01:00
|
|
|
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
|
2007-01-20 03:09:34 +01:00
|
|
|
git clone -s .git another &&
|
|
|
|
ln -s another yetanother &&
|
2010-09-07 12:29:20 +02:00
|
|
|
(
|
|
|
|
cd yetanother/.git &&
|
|
|
|
git show -s HEAD
|
|
|
|
)
|
2007-01-20 03:09:34 +01:00
|
|
|
'
|
|
|
|
|
2006-08-03 23:41:29 +02:00
|
|
|
test_done
|