Skip to content

Commit 8498657

Browse files
committed
Merge branch 'ab/submodule-add-f'
* ab/submodule-add-f: git submodule: add submodules with git add -f <path>
2 parents aa57328 + 31991b0 commit 8498657

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Documentation/git-submodule.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ is the superproject and submodule repositories will be kept
9595
together in the same relative location, and only the
9696
superproject's URL needs to be provided: git-submodule will correctly
9797
locate the submodule using the relative URL in .gitmodules.
98+
+
99+
The submodule will be added with "git add --force <path>". I.e. git
100+
doesn't care if the new path is in a `gitignore`. Your invocation of
101+
"git submodule add" is considered enough to override it.
98102

99103
status::
100104
Show the status of the submodules. This will print the SHA-1 of the

git-submodule.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ cmd_add()
234234
) || die "Unable to checkout submodule '$path'"
235235
fi
236236

237-
git add "$path" ||
237+
git add --force "$path" ||
238238
die "Failed to add submodule '$path'"
239239

240240
git config -f .gitmodules submodule."$path".path "$path" &&
241241
git config -f .gitmodules submodule."$path".url "$repo" &&
242-
git add .gitmodules ||
242+
git add --force .gitmodules ||
243243
die "Failed to register submodule '$path'"
244244
}
245245

t/t7400-submodule-basic.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ test_expect_success 'setup - hide init subdirectory' '
4242
'
4343

4444
test_expect_success 'setup - repository to add submodules to' '
45-
git init addtest
45+
git init addtest &&
46+
git init addtest-ignore
4647
'
4748

4849
# The 'submodule add' tests need some repository to add as a submodule.
@@ -85,6 +86,27 @@ test_expect_success 'submodule add' '
8586
test_cmp empty untracked
8687
'
8788

89+
test_expect_success 'submodule add to .gitignored path' '
90+
echo "refs/heads/master" >expect &&
91+
>empty &&
92+
93+
(
94+
cd addtest-ignore &&
95+
# Does not use test_commit due to the ignore
96+
echo "*" > .gitignore &&
97+
git add --force .gitignore &&
98+
git commit -m"Ignore everything" &&
99+
git submodule add "$submodurl" submod &&
100+
git submodule init
101+
) &&
102+
103+
rm -f heads head untracked &&
104+
inspect addtest/submod ../.. &&
105+
test_cmp expect heads &&
106+
test_cmp expect head &&
107+
test_cmp empty untracked
108+
'
109+
88110
test_expect_success 'submodule add --branch' '
89111
echo "refs/heads/initial" >expect-head &&
90112
cat <<-\EOF >expect-heads &&

0 commit comments

Comments
 (0)