Skip to content

Commit 9305027

Browse files
committed
fixup! submodule: prevent overwriting .gitmodules on path reuse
1 parent bb10dcf commit 9305027

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

builtin/submodule--helper.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,7 +3459,6 @@ static int module_add(int argc, const char **argv, const char *prefix,
34593459
char *to_free = NULL;
34603460
const struct submodule *existing;
34613461
struct strbuf buf = STRBUF_INIT;
3462-
int i;
34633462
char *sm_name_to_free = NULL;
34643463
struct option options[] = {
34653464
OPT_STRING('b', "branch", &add_data.branch, N_("branch"),
@@ -3570,10 +3569,10 @@ static int module_add(int argc, const char **argv, const char *prefix,
35703569
if (existing && strcmp(existing->path, add_data.sm_path)) {
35713570
if (!force) {
35723571
die(_("submodule name '%s' already used for path '%s'"),
3573-
add_data.sm_name, existing->path);
3572+
add_data.sm_name, existing->path);
35743573
}
35753574
/* --force: build <name><n> until unique */
3576-
for (i = 1; ; i++) {
3575+
for (int i = 1; ; i++) {
35773576
strbuf_reset(&buf);
35783577
strbuf_addf(&buf, "%s%d", add_data.sm_name, i);
35793578
if (!submodule_from_name(the_repository,

t/t7400-submodule-basic.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,8 @@ test_expect_success 'submodule add fails when name is reused' '
15001500
# Now adding a *new* repo at the old name must fail
15011501
git init ../child2-origin &&
15021502
git -C ../child2-origin commit --allow-empty -m init &&
1503-
test_must_fail git submodule add ../child2-origin child
1503+
test_must_fail git submodule add ../child2-origin child 2>err &&
1504+
test_grep "already used for" err
15041505
)
15051506
'
15061507

0 commit comments

Comments
 (0)