interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t4059-diff-submodule-not-initialized.sh

137 lines · 3597 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2016 Jacob Keller, based on t4041 by Jens Lehmann
4#
5
6test_description='Test for submodule diff on non-checked out submodule
7
8This test tries to verify that add_submodule_odb works when the submodule was
9initialized previously but the checkout has since been removed.
10'
11
12. ./test-lib.sh
13
14
15# Test non-UTF-8 encoding in case iconv is available.
16if test_have_prereq ICONV
17then
18 test_encoding="ISO8859-1"
19 # String "added" in German (translated with Google Translate), encoded in UTF-8,
20 # used in sample commit log messages in add_file() function below.
21 added=$(printf "hinzugef\303\274gt")
22else
23 test_encoding="UTF-8"
24 added="added"
25fi
26
27add_file () {
28 (
29 cd "$1" &&
30 shift &&
31 for name
32 do
33 echo "$name" >"$name" &&
34 git add "$name" &&
35 test_tick &&
36 # "git commit -m" would break MinGW, as Windows refuse to pass
37 # $test_encoding encoded parameter to git.
38 message="Add $name ($added $name)" &&
39 if test_have_prereq ICONV
40 then
41 message=$(echo "$message" | iconv -f utf-8 -t $test_encoding)
42 fi &&
43 echo "$message" | git -c "i18n.commitEncoding=$test_encoding" commit -F -
44 done >/dev/null &&
45 git rev-parse --short --verify HEAD
46 )
47}
48
49commit_file () {
50 test_tick &&
51 git commit "$@" -m "Commit $*" >/dev/null
52}
53
54test_expect_success 'setup - submodules' '
55 test_create_repo sm2 &&
56 add_file . foo &&
57 add_file sm2 foo1 foo2 &&
58 smhead1=$(git -C sm2 rev-parse --short --verify HEAD)
59'
60
61test_expect_success 'setup - git submodule add' '
62 git -c protocol.file.allow=always submodule add ./sm2 sm1 &&
63 commit_file sm1 .gitmodules &&
64 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
65 cat >expected <<-EOF &&
66 Submodule sm1 0000000...$smhead1 (new submodule)
67 EOF
68 test_cmp expected actual
69'
70
71test_expect_success 'submodule directory removed' '
72 rm -rf sm1 &&
73 git diff-tree -p --no-commit-id --submodule=log HEAD -- sm1 >actual &&
74 cat >expected <<-EOF &&
75 Submodule sm1 0000000...$smhead1 (new submodule)
76 EOF
77 test_cmp expected actual
78'
79
80test_expect_success 'setup - submodule multiple commits' '
81 git submodule update --checkout sm1 &&
82 smhead2=$(add_file sm1 foo3 foo4) &&
83 commit_file sm1 &&
84 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
85 cat >expected <<-EOF &&
86 Submodule sm1 $smhead1..$smhead2:
87 > Add foo4 ($added foo4)
88 > Add foo3 ($added foo3)
89 EOF
90 test_cmp expected actual
91'
92
93test_expect_success 'submodule removed multiple commits' '
94 rm -rf sm1 &&
95 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
96 cat >expected <<-EOF &&
97 Submodule sm1 $smhead1..$smhead2:
98 > Add foo4 ($added foo4)
99 > Add foo3 ($added foo3)
100 EOF
101 test_cmp expected actual
102'
103
104test_expect_success 'submodule not initialized in new clone' '
105 git clone . sm3 &&
106 git -C sm3 diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
107 cat >expected <<-EOF &&
108 Submodule sm1 $smhead1...$smhead2 (commits not present)
109 EOF
110 test_cmp expected actual
111'
112
113test_expect_success 'setup submodule moved' '
114 git submodule update --checkout sm1 &&
115 git mv sm1 sm4 &&
116 commit_file sm4 &&
117 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
118 cat >expected <<-EOF &&
119 Submodule sm4 0000000...$smhead2 (new submodule)
120 EOF
121 test_cmp expected actual
122'
123
124test_expect_success 'submodule moved then removed' '
125 smhead3=$(add_file sm4 foo6 foo7) &&
126 commit_file sm4 &&
127 rm -rf sm4 &&
128 git diff-tree -p --no-commit-id --submodule=log HEAD >actual &&
129 cat >expected <<-EOF &&
130 Submodule sm4 $smhead2..$smhead3:
131 > Add foo7 ($added foo7)
132 > Add foo6 ($added foo6)
133 EOF
134 test_cmp expected actual
135'
136
137test_done