Skip to content

Commit 8348a4a

Browse files
committed
create tests for git add of submodule behavior for ignore=all
1 parent b2d5354 commit 8348a4a

File tree

2 files changed

+88
-24
lines changed

2 files changed

+88
-24
lines changed

read-cache.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,6 +3920,8 @@ static void update_callback(struct diff_queue_struct *q,
39203920
struct diff_filepair *p = q->queue[i];
39213921
const char *path = p->one->path;
39223922

3923+
trace_printf("File '%s'\n", path);
3924+
39233925
if (!data->include_sparse &&
39243926
!path_in_sparse_checkout(path, data->index))
39253927
continue;
@@ -3928,30 +3930,19 @@ static void update_callback(struct diff_queue_struct *q,
39283930
default:
39293931
die(_("unexpected diff status %c"), p->status);
39303932
case DIFF_STATUS_MODIFIED:
3931-
const struct submodule *sub = submodule_from_path(data->repo, NULL, path);
3932-
if (sub) {
3933-
if ( sub->ignore ) {
3934-
trace_printf("ignore=%s\n", sub->ignore);
3935-
if (strcmp(sub->ignore, "all") == 0) {
3936-
trace_printf("ignore=all - test\n");
3937-
if ( data->ignored_too ) {
3938-
trace_printf("ignored_too=%d --force given\n", data->ignored_too);
3939-
if ( data->ignored_too > 0 ) {
3940-
trace_printf("Adding submodule even ignore=all is due to --force|-f: %s\n", path);
3941-
} else {
3942-
printf("Skipping submodule with ignore=all: %s\n", path);
3943-
printf(" Use -f if you really want to add them.");
3944-
continue;
3945-
}
3946-
} else {
3947-
trace_printf("--force not set");
3948-
continue;
3949-
}
3950-
} else {
3951-
trace_printf("Skipping submodule with ignore=all: %s\n", path);
3952-
trace_printf(" Use -f if you really want to add them.");
3953-
continue;
3954-
}
3933+
trace_printf("diff modified '%s'\n", path);
3934+
const struct submodule *sub = submodule_from_path(data->repo, null_oid(the_hash_algo), path);
3935+
if ( sub && sub->name )
3936+
trace_printf(" submodule %s\n", sub->name);
3937+
if ( sub && sub->name && sub->ignore && strcmp(sub->ignore, "all") == 0 ) {
3938+
trace_printf("ignore=all %s\n" , path );
3939+
if ( data->ignored_too && data->ignored_too > 0 ) {
3940+
trace_printf("Adding submodule even ignore=all is due to --force|-f: %s\n", path);
3941+
} else {
3942+
trace_printf("Skipping submodule with ignore=all: %s\n", path);
3943+
trace_printf(" Use -f if you really want to add them.");
3944+
/* Skip this path (submodule ignored) and move on to next diff pair */
3945+
continue;
39553946
}
39563947
}
39573948
if (add_file_to_index(data->index, path, data->flags)) {

t/t2206-add-submodule-ignored.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/sh
2+
3+
test_description='git add respects submodule ignore=all and explicit pathspec'
4+
5+
. ./test-lib.sh
6+
7+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9+
10+
base_path=$(pwd -P)
11+
12+
#1
13+
test_expect_success 'setup: create origin repos' '
14+
cd "${base_path}" &&
15+
git config --global protocol.file.allow always &&
16+
git init sub &&
17+
pwd &&
18+
cd sub &&
19+
test_commit sub_file1 &&
20+
git tag v1.0 &&
21+
test_commit sub_file2 &&
22+
git tag v2.0 &&
23+
cd "${base_path}" &&
24+
git init main &&
25+
cd main &&
26+
test_commit first &&
27+
cd "${base_path}"
28+
'
29+
#2
30+
test_expect_success 'main: add submodule and config ignore=all' '
31+
cd "${base_path}" &&
32+
cd main &&
33+
git submodule add ../sub &&
34+
git commit -m "add submodule" &&
35+
git config -f .gitmodules submodule.sub.ignore all &&
36+
git add . &&
37+
git commit -m "update submodule config sub.ignore all" &&
38+
! git status --porcelain | grep "^.*$" &&
39+
echo
40+
'
41+
42+
#3
43+
test_expect_success 'sub: change to different sha1 and check status in main' '
44+
cd "${base_path}" &&
45+
cd main &&
46+
git -C sub reset --hard v1.0 &&
47+
! git status --porcelain | grep "^ M sub$" &&
48+
git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
49+
echo
50+
'
51+
52+
#4
53+
test_expect_success 'main: check normal add and status' '
54+
cd "${base_path}" &&
55+
cd main &&
56+
git add . &&
57+
! git status --porcelain | grep "^ M sub$" &&
58+
echo
59+
'
60+
61+
#5
62+
test_expect_success 'main: check force add and status' '
63+
cd "${base_path}" &&
64+
cd main &&
65+
git add --force . &&
66+
git status --porcelain | grep "^M sub$" &&
67+
git commit -m "update submodule pointer" &&
68+
! git status --porcelain | grep "^ M sub$" &&
69+
git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
70+
echo
71+
'
72+
test_done
73+
exit 0

0 commit comments

Comments
 (0)