From: Johan Herland <hidden> Date: 2016-06-15 22:45:06
As suggested in a thread some time ago, one could redefine the URL used to
fetch submodules by adding a 'url.*.insteadOf' rule prior to the first
invocation of 'git submodule update'.
However, this does not work with current Git, because the super-repo config
(which is home to the 'url.*.insteadOf' rule) is not consulted by the 'git
clone' that is invoked by 'git submodule update'.
These patches fix this issue by making 'git submodule' explicitly rewrite
the submodule URL according to the super-repo config, prior to calling 'git
clone'.
In order for the 'git submodule' shell script to properly rewrite URLs, it
must gain access to the URL rewriting functionality in remote.c. To expose
the URL rewriting functionality to 'git submodule' (and others, if needed),
a new option ('rewrite-url') has been added to 'git config'.
The patch series is based on master. Whether or not this should be
considered for v1.6.0 is to be decided by Junio. (My personal opinion is
that although we're late in the release cycle, the patches are fairly
straightforward, and should not pose a great risk of regressions.)
Johan Herland (5):
Add testcase for 'git submodule' with url.*.insteadOf set in the
super-repo
Teach 'git config' to rewrite URLs according to current
url.*.insteadOf rules
Add selftest for new option '--rewrite-url' to 'git config'
Add documentation on the new --rewrite-url option to 'git config'
Teach 'git submodule' to rewrite submodule URLs according to
super-repo's rules
Documentation/git-config.txt | 10 ++++++++++
builtin-config.c | 23 ++++++++++++++++++++++-
git-submodule.sh | 6 ++++++
t/t1300-repo-config.sh | 14 ++++++++++++++
t/t7400-submodule-basic.sh | 11 +++++++++++
5 files changed, 63 insertions(+), 1 deletions(-)
Have fun!
...Johan
From: Johan Herland <hidden> Date: 2016-06-15 22:45:06
Currently, setting url.*.insteadOf in the super-repo in order to rewrite
submodule URLs, don't work. When cloning/fetching the submodule, the
super-repo config is never consulted, and thus the url.*.insteadOf rule
is never seen. This adds a testcase that confirms the current behaviour.
Signed-off-by: Johan Herland <redacted>
---
t/t7400-submodule-basic.sh | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
From: Johan Herland <hidden> Date: 2016-06-15 22:45:06
This patch adds the --rewrite-url option to 'git config'. The option takes
exactly one argument; a URL that is to be rewritten according to the longest
matching url.*.insteadOf rule in the current config. The resulting URL is
printed on stdout, and 0 is returned.
The rationale for this patch is to enable access to Git's URL rewriting
functionality from shell scripts.
The URL rewriting functionality is implemented by piggybacking on the
existing URL rewriting code in remote.c.
Signed-off-by: Johan Herland <redacted>
---
builtin-config.c | 23 ++++++++++++++++++++++-
1 files changed, 22 insertions(+), 1 deletions(-)
@@ -157,6 +158,15 @@ See also <<FILES>>. output. The optional `default` parameter is used instead, if there is no color configured for `name`.+--rewrite-url url::++ Rewrite `url` according to the longest matching URL rewriting rule+ (see documentation on `url.<base>.insteadOf` for more information+ on URL rewriting rules), and output the resulting URL to the+ standard output. If there is no matching URL rewriting rule, the+ original `url` is printed on the standard output. In either case,+ the exit code is 0.+ [[FILES]] FILES -----
From: Johan Herland <hidden> Date: 2016-06-15 22:45:06
When a 'url.*.insteadOf' rule in the superrepo matches a submodule URL, we
should rewrite the submodule URL accordingly, so that we don't request the
submodule from location that is inaccessible (or unwanted by the user for
some other reason).
Signed-off-by: Johan Herland <redacted>
---
git-submodule.sh | 6 ++++++
t/t7400-submodule-basic.sh | 2 +-
2 files changed, 7 insertions(+), 1 deletions(-)
@@ -96,6 +96,12 @@ module_clone()test-e"$path"&&die"A file already exist at path '$path'"+# The user may have added url.*.insteadOf rules intending to rewrite+# submodule URLs. We must explicitly do this rewrite before calling+# 'git clone', since 'git clone' will not consult the super-repo+# config and thus never see any url.*.insteadOf rules placed therein.+url=$(gitconfig--rewrite-url"$url")+git-clone-n"$url""$path"||die"Clone of '$url' into submodule path '$path' failed"}
From: Johan Herland <hidden> Date: 2016-06-15 22:45:06
Currently, setting url.*.insteadOf in the super-repo in order to rewrite
submodule URLs, don't work. When cloning/fetching the submodule, the
super-repo config is never consulted, and thus the url.*.insteadOf rule
is never seen. This adds a testcase that confirms the current behaviour.
Signed-off-by: Johan Herland <redacted>
---
t/t7400-submodule-basic.sh | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
The previous patch was whitespace-damaged. Sorry. Trying again.
...Johan
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:45:06
Hi,
On Mon, 4 Aug 2008, Johan Herland wrote:
As suggested in a thread some time ago, one could redefine the URL used
to fetch submodules by adding a 'url.*.insteadOf' rule prior to the
first invocation of 'git submodule update'.
If I suggested it, but forgot the "--global" flag to "git config", I
apologize.
Ciao,
Dscho
From: Johan Herland <hidden> Date: 2016-06-15 22:45:06
On Monday 04 August 2008, Johannes Schindelin wrote:
On Mon, 4 Aug 2008, Johan Herland wrote:
quoted
As suggested in a thread some time ago, one could redefine the URL used
to fetch submodules by adding a 'url.*.insteadOf' rule prior to the
first invocation of 'git submodule update'.
If I suggested it, but forgot the "--global" flag to "git config", I
apologize.
Does this mean that you don't agree with the rationale for this patch? I.e.
that submodule URLs should not be rewritten according to the rules in the
super-repo (but instead require such rules to be set in the user's global
config)?
There are (at least) two reasons for why I think this should work without
having to use '--global':
1. Consistency: Other git commands in the supermodule does _not_ require the
URL rewriting rule to reside in the global config. Why should 'git
submodule' be different.
2. I believe there are valid use cases for adding URL rewriting rules to the
repo config instead of the global config. You may want to check out Fred's
version of project X (including submodules), without making your other
clones of project X start cloning/fetching from Fred.
Puzzled,
...Johan
--
Johan Herland, [off-list ref]
www.herland.net