Skip to content

Commit 78c6a1a

Browse files
committed
tests: Add new t2206-add-submodule-ignored.sh to test ignore=all scenario
The tests verify that the submodule behavior is intact and updating the config with ignore=all also behaves as intended Signed-off-by: Claus Schneider(Eficode) <claus.schneider@eficode.com>
1 parent fa7cf4e commit 78c6a1a

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

t/t2206-add-submodule-ignored.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/sh
2+
# shellcheck disable=SC2016
3+
4+
5+
# shellcheck disable=SC2034
6+
test_description='git add respects submodule ignore=all and explicit pathspec'
7+
8+
# This test covers the behavior of "git add", "git status" and "git log" when
9+
# dealing with submodules that have the ignore=all setting in
10+
# .gitmodules. It ensures that changes in such submodules are
11+
# ignored by default, but can be staged with "git add --force".
12+
13+
# shellcheck disable=SC1091
14+
. ./test-lib.sh
15+
16+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
17+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18+
19+
base_path=$(pwd -P)
20+
21+
#1
22+
test_expect_success 'setup: create origin repos' '
23+
cd "${base_path}" &&
24+
git config --global protocol.file.allow always &&
25+
git init sub &&
26+
pwd &&
27+
cd sub &&
28+
test_commit sub_file1 &&
29+
git tag v1.0 &&
30+
test_commit sub_file2 &&
31+
git tag v2.0 &&
32+
test_commit sub_file3 &&
33+
git tag v3.0 &&
34+
cd "${base_path}" &&
35+
git init main &&
36+
cd main &&
37+
test_commit first &&
38+
cd "${base_path}"
39+
'
40+
#2
41+
# add submodule with default config (ignore=none) and
42+
# check log that is contains a path entry for the submodule 'sub'
43+
# change the commit in the submodule and check that 'git status' shows it as modified
44+
test_expect_success 'main: add submodule with default config' '
45+
cd "${base_path}" &&
46+
cd main &&
47+
git submodule add ../sub &&
48+
git commit -m "add submodule" &&
49+
git log --oneline --name-only | grep "^sub$" &&
50+
git -C sub reset --hard v2.0 &&
51+
git status --porcelain | grep "^ M sub$" &&
52+
echo
53+
'
54+
#3
55+
# change the submodule config to ignore=all and check that status and log do not show changes
56+
test_expect_success 'main: submodule config ignore=all' '
57+
cd "${base_path}" &&
58+
cd main &&
59+
git config -f .gitmodules submodule.sub.ignore all &&
60+
GIT_TRACE=1 git add . &&
61+
git commit -m "update submodule config sub.ignore all" &&
62+
! git status --porcelain | grep "^.*$" &&
63+
! git log --oneline --name-only | grep "^sub$" &&
64+
echo
65+
'
66+
#4
67+
# change the commit in the submodule and check that 'git status' does not show it as modified
68+
# but 'git status --ignore-submodules=none' does show it as modified
69+
test_expect_success 'sub: change to different sha1 and check status in main' '
70+
cd "${base_path}" &&
71+
cd main &&
72+
git -C sub reset --hard v1.0 &&
73+
! git status --porcelain | grep "^ M sub$" &&
74+
git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
75+
echo
76+
'
77+
78+
#5
79+
# check that normal 'git add' does not stage the change in the submodule
80+
test_expect_success 'main: check normal add and status' '
81+
cd "${base_path}" &&
82+
cd main &&
83+
GIT_TRACE=1 git add . &&
84+
! git status --porcelain | grep "^ M sub$" &&
85+
echo
86+
'
87+
88+
#6
89+
# check that 'git add --force .' does not stage the change in the submodule
90+
# and that 'git status' does not show it as modified
91+
test_expect_success 'main: check --force add . and status' '
92+
cd "${base_path}" &&
93+
cd main &&
94+
GIT_TRACE=1 git add --force . &&
95+
! git status --porcelain | grep "^M sub$" &&
96+
echo
97+
'
98+
99+
#7
100+
# check that 'git add .' does not stage the change in the submodule
101+
# and that 'git status' does not show it as modified
102+
test_expect_success 'main: check _add sub_ and status' '
103+
cd "${base_path}" &&
104+
cd main &&
105+
GIT_TRACE=1 git add sub | grep "Skipping submodule due to ignore=all: sub" &&
106+
! git status --porcelain | grep "^M sub$" &&
107+
echo
108+
'
109+
110+
#8
111+
# check that 'git add --force sub' does stage the change in the submodule
112+
# check that 'git add --force ./sub/' does stage the change in the submodule
113+
# and that 'git status --porcelain' does show it as modified
114+
# commit it..
115+
# check that 'git log --ignore-submodules=none' shows the submodule change
116+
# in the log
117+
test_expect_success 'main: check force add sub and ./sub/ and status' '
118+
cd "${base_path}" &&
119+
cd main &&
120+
echo "Adding with --force should work: git add --force sub" &&
121+
GIT_TRACE=1 git add --force sub &&
122+
git status --porcelain | grep "^M sub$" &&
123+
git restore --staged sub &&
124+
! git status --porcelain | grep "^M sub$" &&
125+
echo "Adding with --force should work: git add --force ./sub/" &&
126+
GIT_TRACE=1 git add --force ./sub/ &&
127+
git status --porcelain | grep "^M sub$" &&
128+
git commit -m "update submodule pointer" &&
129+
! git status --porcelain | grep "^ M sub$" &&
130+
git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
131+
echo
132+
'
133+
134+
test_done
135+
exit 0

0 commit comments

Comments
 (0)