submodule init: warn about falling back to a local path
When a submodule is initialized, the config variable 'submodule.<name>.url' is set depending on the value of the same variable in the .gitmodules file. When the URL indicates to be relative, then the url is computed relative to its default remote. The default remote cannot be determined accurately in all cases, such that it falls back to 'origin'. The 'origin' remote may not exist, though. In that case we give up looking for a suitable remote and we'll just assume it to be a local relative path. This can be confusing to users as there is a lot of guessing involved, which is not obvious to the user. So in the corner case of assuming a local autoritative truth, warn the user to lessen the confusion. This behavior was introduced in4d6893200
(submodule add: allow relative repository path even when no url is set, 2011-06-06), which shared the code with submodule-init and then ported to C in3604242f08
(submodule: port init from shell to C, 2016-04-15). In case of submodule-add, this behavior makes sense in some use cases[1], however for submodule-init there does not seem to be an immediate obvious use case to fall back to a local submodule. However there might be, so warn instead of die here. While adding the warning, also clarify the behavior of relative URLs in the documentation. [1] e.g. http://stackoverflow.com/questions/8721984/git-ignore-files-for-public-repository-but-not-for-private "store a secret locally in a submodule, with no intention to publish it" Reported-by: Shawn Pearce <spearce@spearce.org> Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e7e07d5a4f
commit
d1b3b81aab
@ -356,12 +356,10 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
|
||||
strbuf_addf(&remotesb, "remote.%s.url", remote);
|
||||
free(remote);
|
||||
|
||||
if (git_config_get_string(remotesb.buf, &remoteurl))
|
||||
/*
|
||||
* The repository is its own
|
||||
* authoritative upstream
|
||||
*/
|
||||
if (git_config_get_string(remotesb.buf, &remoteurl)) {
|
||||
warning(_("could not lookup configuration '%s'. Assuming this repository is its own authoritative upstream."), remotesb.buf);
|
||||
remoteurl = xgetcwd();
|
||||
}
|
||||
relurl = relative_url(remoteurl, url, NULL);
|
||||
strbuf_release(&remotesb);
|
||||
free(remoteurl);
|
||||
|
Reference in New Issue
Block a user