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.
14 # Tested non-UTF-8 encoding
15 test_encoding
="ISO8859-1"
17 # String "added" in German (translated with Google Translate), encoded in UTF-8,
18 # used in sample commit log messages in add_file() function below.
19 added
=$
(printf "hinzugef\303\274gt")
27 echo "$name" >"$name" &&
30 # "git commit -m" would break MinGW, as Windows refuse to pass
31 # $test_encoding encoded parameter to git.
32 echo "Add $name ($added $name)" |
iconv -f utf-8
-t $test_encoding |
33 git
-c "i18n.commitEncoding=$test_encoding" commit
-F -
35 git rev-parse
--short --verify HEAD
41 git commit
"$@" -m "Commit $*" >/dev
/null
44 test_expect_success
'setup - submodules' '
45 test_create_repo sm2 &&
47 add_file sm2 foo1 foo2 &&
48 smhead1=$(git -C sm2 rev-parse --short --verify HEAD)
51 test_expect_success
'setup - git submodule add' '
52 git -c protocol.file.allow=always submodule add ./sm2 sm1 &&
53 commit_file sm1 .gitmodules &&
54 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
55 cat >expected <<-EOF &&
56 Submodule sm1 0000000...$smhead1 (new submodule)
58 test_cmp expected actual
61 test_expect_success
'submodule directory removed' '
63 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
64 cat >expected <<-EOF &&
65 Submodule sm1 0000000...$smhead1 (new submodule)
67 test_cmp expected actual
70 test_expect_success
'setup - submodule multiple commits' '
71 git submodule update --checkout sm1 &&
72 smhead2=$(add_file sm1 foo3 foo4) &&
74 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
75 cat >expected <<-EOF &&
76 Submodule sm1 $smhead1..$smhead2:
77 > Add foo4 ($added foo4)
78 > Add foo3 ($added foo3)
80 test_cmp expected actual
83 test_expect_success
'submodule removed multiple commits' '
85 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
86 cat >expected <<-EOF &&
87 Submodule sm1 $smhead1..$smhead2:
88 > Add foo4 ($added foo4)
89 > Add foo3 ($added foo3)
91 test_cmp expected actual
94 test_expect_success
'submodule not initialized in new clone' '
96 git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
97 cat >expected <<-EOF &&
98 Submodule sm1 $smhead1...$smhead2 (commits not present)
100 test_cmp expected actual
103 test_expect_success
'setup submodule moved' '
104 git submodule update --checkout sm1 &&
107 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
108 cat >expected <<-EOF &&
109 Submodule sm4 0000000...$smhead2 (new submodule)
111 test_cmp expected actual
114 test_expect_success
'submodule moved then removed' '
115 smhead3=$(add_file sm4 foo6 foo7) &&
118 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
119 cat >expected <<-EOF &&
120 Submodule sm4 $smhead2..$smhead3:
121 > Add foo7 ($added foo7)
122 > Add foo6 ($added foo6)
124 test_cmp expected actual