t/Makefile: introduce TEST_SHELL_PATH
[alt-git.git] / t / t4059-diff-submodule-not-initialized.sh
blob49bca7b48d910fa1128435f121c849e45a7eefa6
1 #!/bin/sh
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-lib.sh
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")
21 add_file () {
23 cd "$1" &&
24 shift &&
25 for name
27 echo "$name" >"$name" &&
28 git add "$name" &&
29 test_tick &&
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 -
34 done >/dev/null &&
35 git rev-parse --short --verify HEAD
39 commit_file () {
40 test_tick &&
41 git commit "$@" -m "Commit $*" >/dev/null
44 test_expect_success 'setup - submodules' '
45 test_create_repo sm2 &&
46 add_file . foo &&
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 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)
57 EOF
58 test_cmp expected actual
61 test_expect_success 'submodule directory removed' '
62 rm -rf sm1 &&
63 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
64 cat >expected <<-EOF &&
65 Submodule sm1 0000000...$smhead1 (new submodule)
66 EOF
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) &&
73 commit_file sm1 &&
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)
79 EOF
80 test_cmp expected actual
83 test_expect_success 'submodule removed multiple commits' '
84 rm -rf sm1 &&
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)
90 EOF
91 test_cmp expected actual
94 test_expect_success 'submodule not initialized in new clone' '
95 git clone . sm3 &&
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)
99 EOF
100 test_cmp expected actual
103 test_expect_success 'setup submodule moved' '
104 git submodule update --checkout sm1 &&
105 git mv sm1 sm4 &&
106 commit_file sm4 &&
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) &&
116 commit_file sm4 &&
117 rm -rf sm4 &&
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
127 test_done