fixup! submodule: prevent overwriting .gitmodules on path reuse
Junio C Hamano committed
Jul 24, 2025 at 13:44 UTC
9305027adef9b8e8de8b2bee11dd442c7e579490
2 files changed
+4
-4
builtin/submodule--helper.c
+2
-3
@@ -3459,7 +3459,6 @@ static int module_add(int argc, const char **argv, const char *prefix,
3459
char *to_free = NULL;
3460
const struct submodule *existing;
3461
struct strbuf buf = STRBUF_INIT;
3462
- int i;
3462
char *sm_name_to_free = NULL;
3463
struct option options[] = {
3464
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,
3569
if (existing && strcmp(existing->path, add_data.sm_path)) {
3570
if (!force) {
3571
die(_("submodule name '%s' already used for path '%s'"),
3573
- add_data.sm_name, existing->path);
3572
+ add_data.sm_name, existing->path);
3573
}
3574
/* --force: build <name><n> until unique */
3576
- for (i = 1; ; i++) {
3575
+ for (int i = 1; ; i++) {
3576
strbuf_reset(&buf);
3577
strbuf_addf(&buf, "%s%d", add_data.sm_name, i);
3578
if (!submodule_from_name(the_repository,
t/t7400-submodule-basic.sh
+2
-1
@@ -1500,7 +1500,8 @@ test_expect_success 'submodule add fails when name is reused' '
1500
# Now adding a *new* repo at the old name must fail
1501
git init ../child2-origin &&
1502
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
1505
)
1506
'
1507