2006-08-04 01:41:29 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2006 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Try various core-level commands in subdirectory.
|
|
|
|
'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
2011-05-26 00:10:41 +04:00
|
|
|
. "$TEST_DIRECTORY"/lib-read-tree.sh
|
2006-08-04 01:41:29 +04: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 09:52:14 +04:00
|
|
|
git update-index --add one &&
|
2014-04-28 16:57:36 +04:00
|
|
|
case "$(git ls-files)" in
|
2010-06-24 21:44:49 +04:00
|
|
|
one) echo pass one ;;
|
2006-08-04 01:41:29 +04:00
|
|
|
*) echo bad one; exit 1 ;;
|
|
|
|
esac &&
|
2010-09-07 05:42:54 +04:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
git update-index --add two &&
|
2014-04-28 16:57:36 +04:00
|
|
|
case "$(git ls-files)" in
|
2010-09-07 05:42:54 +04:00
|
|
|
two) echo pass two ;;
|
|
|
|
*) echo bad two; exit 1 ;;
|
|
|
|
esac
|
2010-09-06 22:39:54 +04:00
|
|
|
) &&
|
2014-04-28 16:57:36 +04:00
|
|
|
case "$(git ls-files)" in
|
2010-06-24 21:44:49 +04:00
|
|
|
dir/two"$LF"one) echo pass both ;;
|
2006-08-04 01:41:29 +04:00
|
|
|
*) echo bad; exit 1 ;;
|
|
|
|
esac
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'cat-file' '
|
2014-04-28 16:57:36 +04:00
|
|
|
two=$(git ls-files -s dir/two) &&
|
|
|
|
two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") &&
|
2006-08-04 01:41:29 +04:00
|
|
|
echo "$two" &&
|
2007-07-03 09:52:14 +04:00
|
|
|
git cat-file -p "$two" >actual &&
|
2006-08-04 01:41:29 +04:00
|
|
|
cmp dir/two actual &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
git cat-file -p "$two" >actual &&
|
|
|
|
cmp two actual
|
|
|
|
)
|
2006-08-04 01:41:29 +04:00
|
|
|
'
|
|
|
|
rm -f actual dir/actual
|
|
|
|
|
|
|
|
test_expect_success 'diff-files' '
|
|
|
|
echo a >>one &&
|
|
|
|
echo d >>dir/two &&
|
2014-04-28 16:57:36 +04:00
|
|
|
case "$(git diff-files --name-only)" in
|
2010-06-24 21:44:49 +04:00
|
|
|
dir/two"$LF"one) echo pass top ;;
|
2006-08-04 01:41:29 +04:00
|
|
|
*) echo bad top; exit 1 ;;
|
|
|
|
esac &&
|
|
|
|
# diff should not omit leading paths
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd dir &&
|
2014-04-28 16:57:36 +04:00
|
|
|
case "$(git diff-files --name-only)" in
|
2010-09-07 14:29:20 +04:00
|
|
|
dir/two"$LF"one) echo pass subdir ;;
|
|
|
|
*) echo bad subdir; exit 1 ;;
|
|
|
|
esac &&
|
2014-04-28 16:57:36 +04:00
|
|
|
case "$(git diff-files --name-only .)" in
|
2010-09-07 14:29:20 +04:00
|
|
|
dir/two) echo pass subdir limited ;;
|
|
|
|
*) echo bad subdir limited; exit 1 ;;
|
|
|
|
esac
|
|
|
|
)
|
2006-08-04 01:41:29 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'write-tree' '
|
2014-04-28 16:57:36 +04:00
|
|
|
top=$(git write-tree) &&
|
2006-08-04 01:41:29 +04:00
|
|
|
echo $top &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd dir &&
|
2014-04-28 16:57:36 +04:00
|
|
|
sub=$(git write-tree) &&
|
2010-09-07 14:29:20 +04:00
|
|
|
echo $sub &&
|
|
|
|
test "z$top" = "z$sub"
|
|
|
|
)
|
2006-08-04 01:41:29 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout-index' '
|
2007-07-03 09:52:14 +04:00
|
|
|
git checkout-index -f -u one &&
|
2006-08-04 01:41:29 +04:00
|
|
|
cmp one original.one &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
git checkout-index -f -u two &&
|
|
|
|
cmp two ../original.two
|
|
|
|
)
|
2006-08-04 01:41:29 +04:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'read-tree' '
|
|
|
|
rm -f one dir/two &&
|
2014-04-28 16:57:36 +04:00
|
|
|
tree=$(git write-tree) &&
|
2011-05-26 00:10:41 +04:00
|
|
|
read_tree_u_must_succeed --reset -u "$tree" &&
|
2006-08-04 01:41:29 +04:00
|
|
|
cmp one original.one &&
|
|
|
|
cmp dir/two original.two &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd dir &&
|
|
|
|
rm -f two &&
|
2011-05-26 00:10:41 +04:00
|
|
|
read_tree_u_must_succeed --reset -u "$tree" &&
|
2010-09-07 14:29:20 +04:00
|
|
|
cmp two ../original.two &&
|
|
|
|
cmp ../one ../original.one
|
|
|
|
)
|
2006-08-04 01:41:29 +04:00
|
|
|
'
|
|
|
|
|
2010-11-26 18:32:37 +03:00
|
|
|
test_expect_success 'alias expansion' '
|
|
|
|
(
|
2012-12-29 03:03:06 +04:00
|
|
|
git config alias.test-status-alias status &&
|
2010-11-26 18:32:37 +03:00
|
|
|
cd dir &&
|
|
|
|
git status &&
|
2012-12-29 03:03:06 +04:00
|
|
|
git test-status-alias
|
2010-11-26 18:32:37 +03:00
|
|
|
)
|
|
|
|
'
|
2011-04-27 12:36:26 +04:00
|
|
|
|
2014-07-22 02:09:27 +04:00
|
|
|
test_expect_success !MINGW '!alias expansion' '
|
2011-04-27 12:36:26 +04:00
|
|
|
pwd >expect &&
|
|
|
|
(
|
2012-12-29 03:03:06 +04:00
|
|
|
git config alias.test-alias-directory !pwd &&
|
2011-04-27 12:36:26 +04:00
|
|
|
cd dir &&
|
2012-12-29 03:03:06 +04:00
|
|
|
git test-alias-directory >../actual
|
2011-04-27 12:36:26 +04:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-04-27 12:36:27 +04:00
|
|
|
test_expect_success 'GIT_PREFIX for !alias' '
|
|
|
|
printf "dir/" >expect &&
|
|
|
|
(
|
2012-12-29 03:03:06 +04:00
|
|
|
git config alias.test-alias-directory "!sh -c \"printf \$GIT_PREFIX\"" &&
|
2011-04-27 12:36:27 +04:00
|
|
|
cd dir &&
|
2012-12-29 03:03:06 +04:00
|
|
|
git test-alias-directory >../actual
|
2011-04-27 12:36:27 +04:00
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-05-26 07:37:12 +04: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 22:01:30 +03:00
|
|
|
echo "dir/" >expect &&
|
|
|
|
write_script diff <<-\EOF &&
|
|
|
|
printf "%s\n" "$GIT_PREFIX"
|
|
|
|
EOF
|
2011-05-26 07:37:12 +04: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 22:01:30 +03:00
|
|
|
echo "change" >two &&
|
2014-03-07 03:22:34 +04:00
|
|
|
GIT_EXTERNAL_DIFF=./diff git diff >../actual
|
2011-05-26 07:37:12 +04:00
|
|
|
git checkout -- two
|
|
|
|
) &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2007-02-04 07:49:16 +03:00
|
|
|
test_expect_success 'no file/rev ambiguity check inside .git' '
|
2007-01-20 05:09:34 +03:00
|
|
|
git commit -a -m 1 &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd .git &&
|
|
|
|
git show -s HEAD
|
|
|
|
)
|
2007-01-20 05:09:34 +03:00
|
|
|
'
|
|
|
|
|
2015-05-19 00:10:26 +03: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 05:09:34 +03:00
|
|
|
git clone -s --bare .git foo.git &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd foo.git &&
|
2015-05-19 00:10:26 +03: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 14:29:20 +04:00
|
|
|
GIT_DIR=. git show -s HEAD
|
|
|
|
)
|
2007-01-20 05:09:34 +03:00
|
|
|
'
|
|
|
|
|
2015-05-19 00:10:26 +03:00
|
|
|
test_expect_success 'no file/rev ambiguity check inside a bare repo' '
|
|
|
|
test_when_finished "rm -fr foo.git" &&
|
2007-01-20 05:09:34 +03:00
|
|
|
git clone -s --bare .git foo.git &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd foo.git &&
|
|
|
|
git show -s HEAD
|
|
|
|
)
|
2007-01-20 05:09:34 +03:00
|
|
|
'
|
|
|
|
|
2009-03-05 00:38:24 +03:00
|
|
|
test_expect_success SYMLINKS 'detection should not be fooled by a symlink' '
|
2007-01-20 05:09:34 +03:00
|
|
|
git clone -s .git another &&
|
|
|
|
ln -s another yetanother &&
|
2010-09-07 14:29:20 +04:00
|
|
|
(
|
|
|
|
cd yetanother/.git &&
|
|
|
|
git show -s HEAD
|
|
|
|
)
|
2007-01-20 05:09:34 +03:00
|
|
|
'
|
|
|
|
|
2006-08-04 01:41:29 +04:00
|
|
|
test_done
|