Skip to content

Commit e801be0

Browse files
committed
Merge branch 'sb/submodule-init'
Error message fix. * sb/submodule-init: submodule update --init: display correct path from submodule
2 parents 9dc7f78 + 6e7c14e commit e801be0

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

builtin/submodule--helper.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,12 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
317317
/* Only loads from .gitmodules, no overlay with .git/config */
318318
gitmodules_config();
319319

320-
if (prefix) {
321-
strbuf_addf(&sb, "%s%s", prefix, path);
320+
if (prefix && get_super_prefix())
321+
die("BUG: cannot have prefix and superprefix");
322+
else if (prefix)
323+
displaypath = xstrdup(relative_path(path, prefix, &sb));
324+
else if (get_super_prefix()) {
325+
strbuf_addf(&sb, "%s%s", get_super_prefix(), path);
322326
displaypath = strbuf_detach(&sb, NULL);
323327
} else
324328
displaypath = xstrdup(path);
@@ -403,9 +407,6 @@ static int module_init(int argc, const char **argv, const char *prefix)
403407
int i;
404408

405409
struct option module_init_options[] = {
406-
OPT_STRING(0, "prefix", &prefix,
407-
N_("path"),
408-
N_("alternative anchor for relative paths")),
409410
OPT__QUIET(&quiet, N_("Suppress output for initializing a submodule")),
410411
OPT_END()
411412
};
@@ -1144,7 +1145,7 @@ static struct cmd_struct commands[] = {
11441145
{"relative-path", resolve_relative_path, 0},
11451146
{"resolve-relative-url", resolve_relative_url, 0},
11461147
{"resolve-relative-url-test", resolve_relative_url_test, 0},
1147-
{"init", module_init, 0},
1148+
{"init", module_init, SUPPORT_SUPER_PREFIX},
11481149
{"remote-branch", resolve_remote_submodule_branch, 0},
11491150
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
11501151
};

git-submodule.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ cmd_init()
371371
shift
372372
done
373373

374-
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} "$@"
374+
git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} "$@"
375375
}
376376

377377
#

t/t7406-submodule-update.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
140140
test_i18ncmp expect2 actual2
141141
'
142142

143+
cat <<EOF >expect2
144+
Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
145+
EOF
146+
147+
test_expect_success 'submodule update --init from and of subdirectory' '
148+
git init withsubs &&
149+
(cd withsubs &&
150+
mkdir foo &&
151+
git submodule add "$(pwd)/../rebasing" foo/sub &&
152+
(cd foo &&
153+
git submodule deinit -f sub &&
154+
git submodule update --init sub 2>../../actual2
155+
)
156+
) &&
157+
test_i18ncmp expect2 actual2
158+
'
159+
143160
apos="'";
144161
test_expect_success 'submodule update does not fetch already present commits' '
145162
(cd submodule &&

0 commit comments

Comments
 (0)