2008-03-11 14:52:19 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2008 Ping Yin
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Summary support for submodules
|
|
|
|
|
2020-08-21 18:59:52 +02:00
|
|
|
This test script tries to verify the sanity of summary subcommand of git submodule.
|
2008-03-11 14:52:19 +01:00
|
|
|
'
|
2020-09-09 22:53:05 +02:00
|
|
|
|
2020-08-12 21:44:03 +02:00
|
|
|
# NOTE: This test script uses 'git add' instead of 'git submodule add' to add
|
|
|
|
# submodules to the superproject. Some submodule subcommands such as init and
|
|
|
|
# deinit might not work as expected in this script. t7421 does not have this
|
|
|
|
# caveat.
|
2020-09-09 22:53:05 +02:00
|
|
|
#
|
2020-08-21 18:59:52 +02:00
|
|
|
# NEEDSWORK: This test script is old fashioned and may need a big cleanup due to
|
|
|
|
# various reasons, one of them being that there are lots of commands taking place
|
|
|
|
# outside of 'test_expect_success' block, which is no longer in good-style.
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2022-09-01 01:14:15 +02:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2008-03-11 14:52:19 +01:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
add_file () {
|
|
|
|
sm=$1
|
|
|
|
shift
|
|
|
|
owd=$(pwd)
|
|
|
|
cd "$sm"
|
|
|
|
for name; do
|
2020-08-21 18:59:48 +02:00
|
|
|
echo "$name" >"$name" &&
|
2008-03-11 14:52:19 +01:00
|
|
|
git add "$name" &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "Add $name"
|
|
|
|
done >/dev/null
|
2020-08-21 18:59:49 +02:00
|
|
|
git rev-parse --short HEAD
|
2008-03-11 14:52:19 +01:00
|
|
|
cd "$owd"
|
|
|
|
}
|
|
|
|
commit_file () {
|
|
|
|
test_tick &&
|
|
|
|
git commit "$@" -m "Commit $*" >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
test_create_repo sm1 &&
|
2008-04-13 03:57:08 +02:00
|
|
|
add_file . foo >/dev/null
|
2008-03-11 14:52:19 +01:00
|
|
|
|
|
|
|
head1=$(add_file sm1 foo1 foo2)
|
|
|
|
|
|
|
|
test_expect_success 'added submodule' "
|
|
|
|
git add sm1 &&
|
|
|
|
git submodule summary >actual &&
|
2010-11-14 15:44:16 +01:00
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 0000000...$head1 (2):
|
|
|
|
> Add foo2
|
2013-06-16 16:18:18 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:18 +02:00
|
|
|
test_cmp expected actual
|
|
|
|
"
|
|
|
|
|
|
|
|
test_expect_success 'added submodule (subdirectory)' "
|
|
|
|
mkdir sub &&
|
|
|
|
(
|
|
|
|
cd sub &&
|
|
|
|
git submodule summary >../actual
|
|
|
|
) &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* ../sm1 0000000...$head1 (2):
|
|
|
|
> Add foo2
|
2013-06-16 16:18:18 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:18 +02:00
|
|
|
test_cmp expected actual
|
|
|
|
"
|
|
|
|
|
|
|
|
test_expect_success 'added submodule (subdirectory only)' "
|
|
|
|
(
|
|
|
|
cd sub &&
|
|
|
|
git submodule summary . >../actual
|
|
|
|
) &&
|
2018-07-27 19:48:11 +02:00
|
|
|
test_must_be_empty actual
|
2013-06-16 16:18:18 +02:00
|
|
|
"
|
|
|
|
|
|
|
|
test_expect_success 'added submodule (subdirectory with explicit path)' "
|
|
|
|
(
|
|
|
|
cd sub &&
|
|
|
|
git submodule summary ../sm1 >../actual
|
|
|
|
) &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* ../sm1 0000000...$head1 (2):
|
|
|
|
> Add foo2
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2010-11-14 15:44:16 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
head2=$(add_file sm1 foo3)
|
|
|
|
|
|
|
|
test_expect_success 'modified submodule(forward)' "
|
|
|
|
git submodule summary >actual &&
|
2010-11-14 15:44:16 +01:00
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head1...$head2 (1):
|
|
|
|
> Add foo3
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2010-11-14 15:44:16 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
2009-08-13 21:32:50 +02:00
|
|
|
test_expect_success 'modified submodule(forward), --files' "
|
|
|
|
git submodule summary --files >actual &&
|
2010-11-14 15:44:16 +01:00
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head1...$head2 (1):
|
|
|
|
> Add foo3
|
2009-08-13 21:32:50 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2010-11-14 15:44:16 +01:00
|
|
|
test_cmp expected actual
|
2009-08-13 21:32:50 +02:00
|
|
|
"
|
|
|
|
|
2013-09-01 22:06:49 +02:00
|
|
|
test_expect_success 'no ignore=all setting has any effect' "
|
|
|
|
git config -f .gitmodules submodule.sm1.path sm1 &&
|
|
|
|
git config -f .gitmodules submodule.sm1.ignore all &&
|
|
|
|
git config submodule.sm1.ignore all &&
|
|
|
|
git config diff.ignoreSubmodules all &&
|
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head1...$head2 (1):
|
|
|
|
> Add foo3
|
2013-09-01 22:06:49 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-09-01 22:06:49 +02:00
|
|
|
test_cmp expected actual &&
|
|
|
|
git config --unset diff.ignoreSubmodules &&
|
|
|
|
git config --remove-section submodule.sm1 &&
|
|
|
|
git config -f .gitmodules --remove-section submodule.sm1
|
|
|
|
"
|
|
|
|
|
|
|
|
|
2008-03-11 14:52:19 +01:00
|
|
|
commit_file sm1 &&
|
2010-09-07 03:42:54 +02:00
|
|
|
head3=$(
|
|
|
|
cd sm1 &&
|
|
|
|
git reset --hard HEAD~2 >/dev/null &&
|
2020-08-21 18:59:49 +02:00
|
|
|
git rev-parse --short HEAD
|
2010-09-06 20:39:54 +02:00
|
|
|
)
|
2008-03-11 14:52:19 +01:00
|
|
|
|
|
|
|
test_expect_success 'modified submodule(backward)' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head2...$head3 (2):
|
|
|
|
< Add foo3
|
|
|
|
< Add foo2
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2010-11-14 15:44:16 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
head4=$(add_file sm1 foo4 foo5) &&
|
|
|
|
head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
|
|
|
|
test_expect_success 'modified submodule(backward and forward)' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head2...$head4 (4):
|
|
|
|
> Add foo5
|
|
|
|
> Add foo4
|
|
|
|
< Add foo3
|
|
|
|
< Add foo2
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2010-11-14 15:44:16 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
test_expect_success '--summary-limit' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary -n 3 >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head2...$head4 (4):
|
|
|
|
> Add foo5
|
|
|
|
> Add foo4
|
|
|
|
< Add foo3
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:13 +02:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
mv sm1 sm1-bak &&
|
|
|
|
echo sm1 >sm1 &&
|
|
|
|
head5=$(git hash-object sm1 | cut -c1-7) &&
|
|
|
|
git add sm1 &&
|
|
|
|
rm -f sm1 &&
|
|
|
|
mv sm1-bak sm1
|
|
|
|
|
|
|
|
test_expect_success 'typechanged submodule(submodule->blob), --cached' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary --cached >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head4(submodule)->$head5(blob) (3):
|
|
|
|
< Add foo5
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
2009-08-13 21:32:50 +02:00
|
|
|
test_expect_success 'typechanged submodule(submodule->blob), --files' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary --files >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head5(blob)->$head4(submodule) (3):
|
|
|
|
> Add foo5
|
2009-08-13 21:32:50 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected actual
|
2009-08-13 21:32:50 +02:00
|
|
|
"
|
|
|
|
|
2008-03-11 14:52:19 +01:00
|
|
|
rm -rf sm1 &&
|
|
|
|
git checkout-index sm1
|
|
|
|
test_expect_success 'typechanged submodule(submodule->blob)' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head4(submodule)->$head5(blob):
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
rm -f sm1 &&
|
|
|
|
test_create_repo sm1 &&
|
|
|
|
head6=$(add_file sm1 foo6 foo7)
|
|
|
|
test_expect_success 'nonexistent commit' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head4...$head6:
|
|
|
|
Warn: sm1 doesn't contain commit $head4_full
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
commit_file
|
|
|
|
test_expect_success 'typechanged submodule(blob->submodule)' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head5(blob)->$head6(submodule) (2):
|
|
|
|
> Add foo7
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
commit_file sm1 &&
|
|
|
|
rm -rf sm1
|
|
|
|
test_expect_success 'deleted submodule' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head6...0000000:
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:13 +02:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
2017-06-14 12:58:25 +02:00
|
|
|
test_expect_success 'create second submodule' '
|
|
|
|
test_create_repo sm2 &&
|
|
|
|
head7=$(add_file sm2 foo8 foo9) &&
|
|
|
|
git add sm2
|
|
|
|
'
|
2008-03-11 14:52:19 +01:00
|
|
|
|
|
|
|
test_expect_success 'multiple submodules' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head6...0000000:
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm2 0000000...$head7 (2):
|
|
|
|
> Add foo9
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:13 +02:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
test_expect_success 'path filter' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary sm2 >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm2 0000000...$head7 (2):
|
|
|
|
> Add foo9
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:13 +02:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
commit_file sm2
|
|
|
|
test_expect_success 'given commit' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary HEAD^ >actual &&
|
|
|
|
cat >expected <<-EOF &&
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head6...0000000:
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm2 0000000...$head7 (2):
|
|
|
|
> Add foo9
|
2008-03-11 14:52:19 +01:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2013-06-16 16:18:13 +02:00
|
|
|
test_cmp expected actual
|
2008-03-11 14:52:19 +01:00
|
|
|
"
|
|
|
|
|
2008-04-12 17:05:31 +02:00
|
|
|
test_expect_success '--for-status' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git submodule summary --for-status HEAD^ >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp - actual <<-EOF
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm1 $head6...0000000:
|
2013-09-06 19:43:06 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
* sm2 0000000...$head7 (2):
|
|
|
|
> Add foo9
|
2013-09-06 19:43:06 +02:00
|
|
|
|
2020-08-21 18:59:51 +02:00
|
|
|
EOF
|
2008-04-12 17:05:31 +02:00
|
|
|
"
|
|
|
|
|
2009-08-13 21:32:50 +02:00
|
|
|
test_expect_success 'fail when using --files together with --cached' "
|
2013-06-16 16:18:13 +02:00
|
|
|
test_must_fail git submodule summary --files --cached
|
2009-08-13 21:32:50 +02:00
|
|
|
"
|
|
|
|
|
2010-02-16 11:21:14 +01:00
|
|
|
test_expect_success 'should not fail in an empty repo' "
|
2013-06-16 16:18:13 +02:00
|
|
|
git init xyzzy &&
|
|
|
|
cd xyzzy &&
|
|
|
|
git submodule summary >output 2>&1 &&
|
2018-08-19 23:57:24 +02:00
|
|
|
test_must_be_empty output
|
2010-02-16 11:21:14 +01:00
|
|
|
"
|
|
|
|
|
2008-03-11 14:52:19 +01:00
|
|
|
test_done
|