mirror of
https://github.com/git/git.git
synced 2025-12-23 12:14:22 +01:00
Merge branch 'jc/submodule-add' into jch
"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
This commit is contained in:
@@ -1898,6 +1898,13 @@ static int determine_submodule_update_strategy(struct repository *r,
|
|||||||
const char *val;
|
const char *val;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NEEDSWORK: audit and ensure that update_submodule() has right
|
||||||
|
* to assume that submodule_from_path() above will always succeed.
|
||||||
|
*/
|
||||||
|
if (!sub)
|
||||||
|
BUG("update_submodule assumes a submodule exists at path (%s)",
|
||||||
|
path);
|
||||||
key = xstrfmt("submodule.%s.update", sub->name);
|
key = xstrfmt("submodule.%s.update", sub->name);
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
@@ -3523,14 +3530,15 @@ static int module_add(int argc, const char **argv, const char *prefix,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!add_data.sm_name)
|
if (!add_data.sm_name)
|
||||||
add_data.sm_name = add_data.sm_path;
|
add_data.sm_name = add_data.sm_path;
|
||||||
|
|
||||||
existing = submodule_from_name(the_repository,
|
existing = submodule_from_name(the_repository,
|
||||||
null_oid(the_hash_algo),
|
null_oid(the_hash_algo),
|
||||||
add_data.sm_name);
|
add_data.sm_name);
|
||||||
|
|
||||||
if (existing && strcmp(existing->path, add_data.sm_path)) {
|
if (existing && existing->path &&
|
||||||
|
strcmp(existing->path, add_data.sm_path)) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
die(_("submodule name '%s' already used for path '%s'"),
|
die(_("submodule name '%s' already used for path '%s'"),
|
||||||
add_data.sm_name, existing->path);
|
add_data.sm_name, existing->path);
|
||||||
|
|||||||
@@ -48,6 +48,25 @@ test_expect_success 'submodule deinit works on empty repository' '
|
|||||||
git submodule deinit --all
|
git submodule deinit --all
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'submodule add with incomplete .gitmodules' '
|
||||||
|
test_when_finished "rm -f expect actual" &&
|
||||||
|
test_when_finished "git config remove-section submodule.one" &&
|
||||||
|
test_when_finished "git rm -f one .gitmodules" &&
|
||||||
|
git init one &&
|
||||||
|
git -C one commit --allow-empty -m one-initial &&
|
||||||
|
git config -f .gitmodules submodule.one.ignore all &&
|
||||||
|
|
||||||
|
git submodule add ./one &&
|
||||||
|
|
||||||
|
for var in ignore path url
|
||||||
|
do
|
||||||
|
git config -f .gitmodules --get "submodule.one.$var" ||
|
||||||
|
return 1
|
||||||
|
done >actual &&
|
||||||
|
test_write_lines all one ./one >expect &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'setup - initial commit' '
|
test_expect_success 'setup - initial commit' '
|
||||||
>t &&
|
>t &&
|
||||||
git add t &&
|
git add t &&
|
||||||
|
|||||||
Reference in New Issue
Block a user