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