Skip to content

Commit c1fc5d3

Browse files
committed
Merge branch 'jc/submodule-add' into seen
"git submodule add" to add a submodule under <name> segfaulted, when a submodule.<name>.something is already in .gitmodules file without defining where its submodule.<name>.path is, which has been corrected. Comments? * jc/submodule-add: submodule add: sanity check existing .gitmodules
2 parents 35603e5 + 29a262a commit c1fc5d3

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

builtin/submodule--helper.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,13 @@ static int determine_submodule_update_strategy(struct repository *r,
19031903
const char *val;
19041904
int ret;
19051905

1906+
/*
1907+
* NEEDSWORK: audit and ensure that update_submodule() has right
1908+
* to assume that submodule_from_path() above will always succeed.
1909+
*/
1910+
if (!sub)
1911+
BUG("update_submodule assumes a submodule exists at path (%s)",
1912+
path);
19061913
key = xstrfmt("submodule.%s.update", sub->name);
19071914

19081915
if (update) {
@@ -3527,14 +3534,15 @@ static int module_add(int argc, const char **argv, const char *prefix,
35273534
}
35283535
}
35293536

3530-
if(!add_data.sm_name)
3537+
if (!add_data.sm_name)
35313538
add_data.sm_name = add_data.sm_path;
35323539

35333540
existing = submodule_from_name(the_repository,
35343541
null_oid(the_hash_algo),
35353542
add_data.sm_name);
35363543

3537-
if (existing && strcmp(existing->path, add_data.sm_path)) {
3544+
if (existing && existing->path &&
3545+
strcmp(existing->path, add_data.sm_path)) {
35383546
if (!force) {
35393547
die(_("submodule name '%s' already used for path '%s'"),
35403548
add_data.sm_name, existing->path);

t/t7400-submodule-basic.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ test_expect_success 'submodule deinit works on empty repository' '
4848
git submodule deinit --all
4949
'
5050

51+
test_expect_success 'submodule add with incomplete .gitmodules' '
52+
test_when_finished "rm -f expect actual" &&
53+
test_when_finished "git config remove-section submodule.one" &&
54+
test_when_finished "git rm -f one .gitmodules" &&
55+
git init one &&
56+
git -C one commit --allow-empty -m one-initial &&
57+
git config -f .gitmodules submodule.one.ignore all &&
58+
59+
git submodule add ./one &&
60+
61+
for var in ignore path url
62+
do
63+
git config -f .gitmodules --get "submodule.one.$var" ||
64+
return 1
65+
done >actual &&
66+
test_write_lines all one ./one >expect &&
67+
test_cmp expect actual
68+
'
69+
5170
test_expect_success 'setup - initial commit' '
5271
>t &&
5372
git add t &&

0 commit comments

Comments
 (0)