3 # Copyright (c) 2016 Jacob Keller, based on t4041 by Jens Lehmann
6 test_description
='Test for submodule diff on non-checked out submodule
8 This test tries to verify that add_submodule_odb works when the submodule was
9 initialized previously but the checkout has since been removed.
12 TEST_PASSES_SANITIZE_LEAK
=true
15 # Tested non-UTF-8 encoding
16 test_encoding
="ISO8859-1"
18 # String "added" in German (translated with Google Translate), encoded in UTF-8,
19 # used in sample commit log messages in add_file() function below.
20 added
=$
(printf "hinzugef\303\274gt")
28 echo "$name" >"$name" &&
31 # "git commit -m" would break MinGW, as Windows refuse to pass
32 # $test_encoding encoded parameter to git.
33 echo "Add $name ($added $name)" |
iconv -f utf-8
-t $test_encoding |
34 git
-c "i18n.commitEncoding=$test_encoding" commit
-F -
36 git rev-parse
--short --verify HEAD
42 git commit
"$@" -m "Commit $*" >/dev
/null
45 test_expect_success
'setup - submodules' '
46 test_create_repo sm2 &&
48 add_file sm2 foo1 foo2 &&
49 smhead1=$(git -C sm2 rev-parse --short --verify HEAD)
52 test_expect_success
'setup - git submodule add' '
53 git -c protocol.file.allow=always submodule add ./sm2 sm1 &&
54 commit_file sm1 .gitmodules &&
55 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
56 cat >expected <<-EOF &&
57 Submodule sm1 0000000...$smhead1 (new submodule)
59 test_cmp expected actual
62 test_expect_success
'submodule directory removed' '
64 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
65 cat >expected <<-EOF &&
66 Submodule sm1 0000000...$smhead1 (new submodule)
68 test_cmp expected actual
71 test_expect_success
'setup - submodule multiple commits' '
72 git submodule update --checkout sm1 &&
73 smhead2=$(add_file sm1 foo3 foo4) &&
75 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
76 cat >expected <<-EOF &&
77 Submodule sm1 $smhead1..$smhead2:
78 > Add foo4 ($added foo4)
79 > Add foo3 ($added foo3)
81 test_cmp expected actual
84 test_expect_success
'submodule removed multiple commits' '
86 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
87 cat >expected <<-EOF &&
88 Submodule sm1 $smhead1..$smhead2:
89 > Add foo4 ($added foo4)
90 > Add foo3 ($added foo3)
92 test_cmp expected actual
95 test_expect_success
'submodule not initialized in new clone' '
97 git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
98 cat >expected <<-EOF &&
99 Submodule sm1 $smhead1...$smhead2 (commits not present)
101 test_cmp expected actual
104 test_expect_success
'setup submodule moved' '
105 git submodule update --checkout sm1 &&
108 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
109 cat >expected <<-EOF &&
110 Submodule sm4 0000000...$smhead2 (new submodule)
112 test_cmp expected actual
115 test_expect_success
'submodule moved then removed' '
116 smhead3=$(add_file sm4 foo6 foo7) &&
119 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
120 cat >expected <<-EOF &&
121 Submodule sm4 $smhead2..$smhead3:
122 > Add foo7 ($added foo7)
123 > Add foo6 ($added foo6)
125 test_cmp expected actual