submodule update --init: display correct path from submodule
In the submodule helper we did not correctly handled the display path for initializing submodules when both the submodule is inside a subdirectory as well as the command being invoked from a subdirectory (as viewed from the superproject). This was broken in 3604242f080, which was written at a time where there was no super-prefix available, so we abused the --prefix option for the same purpose and could get only one case right (the call from within a subdirectory, not the submodule being in a subdirectory). Test-provided-by: David Turner <novalis@novalis.org> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
f6f8586140
commit
6e7c14e65c
@ -317,8 +317,12 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
|
|||||||
/* Only loads from .gitmodules, no overlay with .git/config */
|
/* Only loads from .gitmodules, no overlay with .git/config */
|
||||||
gitmodules_config();
|
gitmodules_config();
|
||||||
|
|
||||||
if (prefix) {
|
if (prefix && get_super_prefix())
|
||||||
strbuf_addf(&sb, "%s%s", prefix, path);
|
die("BUG: cannot have prefix and superprefix");
|
||||||
|
else if (prefix)
|
||||||
|
displaypath = xstrdup(relative_path(path, prefix, &sb));
|
||||||
|
else if (get_super_prefix()) {
|
||||||
|
strbuf_addf(&sb, "%s%s", get_super_prefix(), path);
|
||||||
displaypath = strbuf_detach(&sb, NULL);
|
displaypath = strbuf_detach(&sb, NULL);
|
||||||
} else
|
} else
|
||||||
displaypath = xstrdup(path);
|
displaypath = xstrdup(path);
|
||||||
@ -403,9 +407,6 @@ static int module_init(int argc, const char **argv, const char *prefix)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
struct option module_init_options[] = {
|
struct option module_init_options[] = {
|
||||||
OPT_STRING(0, "prefix", &prefix,
|
|
||||||
N_("path"),
|
|
||||||
N_("alternative anchor for relative paths")),
|
|
||||||
OPT__QUIET(&quiet, N_("Suppress output for initializing a submodule")),
|
OPT__QUIET(&quiet, N_("Suppress output for initializing a submodule")),
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
@ -1129,7 +1130,7 @@ static struct cmd_struct commands[] = {
|
|||||||
{"relative-path", resolve_relative_path, 0},
|
{"relative-path", resolve_relative_path, 0},
|
||||||
{"resolve-relative-url", resolve_relative_url, 0},
|
{"resolve-relative-url", resolve_relative_url, 0},
|
||||||
{"resolve-relative-url-test", resolve_relative_url_test, 0},
|
{"resolve-relative-url-test", resolve_relative_url_test, 0},
|
||||||
{"init", module_init, 0},
|
{"init", module_init, SUPPORT_SUPER_PREFIX},
|
||||||
{"remote-branch", resolve_remote_submodule_branch, 0},
|
{"remote-branch", resolve_remote_submodule_branch, 0},
|
||||||
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
|
{"absorb-git-dirs", absorb_git_dirs, SUPPORT_SUPER_PREFIX},
|
||||||
};
|
};
|
||||||
|
@ -374,7 +374,7 @@ cmd_init()
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
git ${wt_prefix:+-C "$wt_prefix"} submodule--helper init ${GIT_QUIET:+--quiet} ${prefix:+--prefix "$prefix"} "$@"
|
git ${wt_prefix:+-C "$wt_prefix"} ${prefix:+--super-prefix "$prefix"} submodule--helper init ${GIT_QUIET:+--quiet} "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -140,6 +140,23 @@ test_expect_success 'submodule update --init --recursive from subdirectory' '
|
|||||||
test_i18ncmp expect2 actual2
|
test_i18ncmp expect2 actual2
|
||||||
'
|
'
|
||||||
|
|
||||||
|
cat <<EOF >expect2
|
||||||
|
Submodule 'foo/sub' ($pwd/withsubs/../rebasing) registered for path 'sub'
|
||||||
|
EOF
|
||||||
|
|
||||||
|
test_expect_success 'submodule update --init from and of subdirectory' '
|
||||||
|
git init withsubs &&
|
||||||
|
(cd withsubs &&
|
||||||
|
mkdir foo &&
|
||||||
|
git submodule add "$(pwd)/../rebasing" foo/sub &&
|
||||||
|
(cd foo &&
|
||||||
|
git submodule deinit -f sub &&
|
||||||
|
git submodule update --init sub 2>../../actual2
|
||||||
|
)
|
||||||
|
) &&
|
||||||
|
test_i18ncmp expect2 actual2
|
||||||
|
'
|
||||||
|
|
||||||
apos="'";
|
apos="'";
|
||||||
test_expect_success 'submodule update does not fetch already present commits' '
|
test_expect_success 'submodule update does not fetch already present commits' '
|
||||||
(cd submodule &&
|
(cd submodule &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user