Skip to content

Commit 1f8d711

Browse files
bmwillgitster
authored andcommitted
submodule--helper init: set submodule.<name>.active
When initializing a submodule set the submodule.<name>.active config to true if the module hasn't already been configured to be active by some other means (e.g. a pathspec set in submodule.active). Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb62e0a commit 1f8d711

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

builtin/submodule--helper.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,18 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
356356
die(_("No url found for submodule path '%s' in .gitmodules"),
357357
displaypath);
358358

359+
/*
360+
* NEEDSWORK: In a multi-working-tree world, this needs to be
361+
* set in the per-worktree config.
362+
*
363+
* Set active flag for the submodule being initialized
364+
*/
365+
if (!is_submodule_initialized(path)) {
366+
strbuf_reset(&sb);
367+
strbuf_addf(&sb, "submodule.%s.active", sub->name);
368+
git_config_set_gently(sb.buf, "true");
369+
}
370+
359371
/*
360372
* Copy url setting when it is not set yet.
361373
* To look up the url in .git/config, we must not fall back to

t/t7400-submodule-basic.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,4 +1256,15 @@ test_expect_success 'clone and subsequent updates correctly auto-initialize subm
12561256
test_cmp expect2 actual
12571257
'
12581258

1259+
test_expect_success 'init properly sets the config' '
1260+
test_when_finished "rm -rf multisuper_clone" &&
1261+
git clone --recurse-submodules="." \
1262+
--recurse-submodules=":(exclude)sub0" \
1263+
multisuper multisuper_clone &&
1264+
1265+
git -C multisuper_clone submodule init -- sub0 sub1 &&
1266+
git -C multisuper_clone config --get submodule.sub0.active &&
1267+
test_must_fail git -C multisuper_clone config --get submodule.sub1.active
1268+
'
1269+
12591270
test_done

0 commit comments

Comments
 (0)