Skip to content

Commit d92dbf1

Browse files
committed
Merge branch 'jk/submodule-init-segv-fix'
Fix a segv in 'submodule init' when url is not given for a submodule. * jk/submodule-init-segv-fix: submodule_init: die cleanly on submodules without url defined
2 parents b0f8987 + 627fde1 commit d92dbf1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

builtin/submodule--helper.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,12 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
376376
strbuf_reset(&sb);
377377
strbuf_addf(&sb, "submodule.%s.url", sub->name);
378378
if (git_config_get_string(sb.buf, &url)) {
379-
url = xstrdup(sub->url);
380-
381-
if (!url)
379+
if (!sub->url)
382380
die(_("No url found for submodule path '%s' in .gitmodules"),
383381
displaypath);
384382

383+
url = xstrdup(sub->url);
384+
385385
/* Possibly a url relative to parent */
386386
if (starts_with_dot_dot_slash(url) ||
387387
starts_with_dot_slash(url)) {

t/t7400-submodule-basic.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ test_expect_success 'submodule update aborts on missing .gitmodules file' '
3838
test_i18ngrep "Submodule path .sub. not initialized" actual
3939
'
4040

41+
test_expect_success 'submodule update aborts on missing gitmodules url' '
42+
test_when_finished "git update-index --remove sub" &&
43+
git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
44+
test_when_finished "rm -f .gitmodules" &&
45+
git config -f .gitmodules submodule.s.path sub &&
46+
test_must_fail git submodule init
47+
'
48+
4149
test_expect_success 'configuration parsing' '
4250
test_when_finished "rm -f .gitmodules" &&
4351
cat >.gitmodules <<-\EOF &&

0 commit comments

Comments
 (0)