On Tue, Feb 21, 2017 at 3:00 PM, Jeff King <peff@xxxxxxxx> wrote: > On Tue, Feb 21, 2017 at 10:19:38AM -0800, Stefan Beller wrote: > >> On Mon, Feb 20, 2017 at 11:06 PM, Jeff King <peff@xxxxxxxx> wrote: >> > >> > We'll see if the submodule folks have any ideas on how to implement >> > that. >> > >> >> So from reading your discussion, the user expectation is to have >> `git submodule {init, update --init, sync}` >> to pay attention to url.<base>.insteadOf when setting up the >> submodule.<name>.URL, such that the modified URL is used for the >> initial clone of the submodule (and hence any subsequent usage within >> the submodule). > > Yeah, that was what I was envisioning. > >> Two caveates: >> >> * After running `git submodule init`, you change url.<base>.insteadOf >> in the superproject. How do we need to word the documentation to >> have users expecting this change doesn't affect submodules? >> (See above Any vs. "Any except (initialized) submodules") > > Good question. > > I guess one answer is that this is the wrong approach entirely, and the > right one is something like: submodules should understand that they are > part of a superproject, and respect some whitelisted set of config from > the superproject .git/config file. This would break one of the core assumptions that submodules are "independent" repos. The way of action is a one way street: * The superproject is aware of the submodule and when you invoke a command on the superproject, you may mess around with the submodule, e.g. update/remove it; absorb its git directory. * The submodule is "just" a repository with weird .git link file and a respective core.worktree setup. Currently it doesn't know if it is guided by a superproject. Though I do not know if this is actually a good assumption. e.g. "[PATCH v2] git-prompt.sh: add submodule indicator" https://public-inbox.org/git/1486075892-20676-2-git-send-email-email@xxxxxxxxxxxxxxxx/ really had trouble in the first version to nail down how to tell you are in a submodule, but people want to know that. > > The second half is pretty easy to do (use git_config_from_file on the > super-project's $GIT_DIR There goes the "pretty easy"; currently there is no concept to find out the existence of a super-project. > /config, and pass a callback which filters the > keys before passing them along to the real callback). > > I'm not sure about the first half (submodules know about their > superproject), though. Maybe we need to change that fundamental assumption. So a more sophisticated way (thinking long term here) would be to include the superprojects config file (with exceptions), and that config file has more priority than e.g. the ~/.gitconfig file, but less than the submodules own $GIT_DIR/config file. Then a setting like the url rewriting would be "inherited" by the submodule, with the option to overwrite the default as given by the superproject. > >> * So with the point above the insteadOf config only applies to the >> init/sync process, (i.e. once in time, ideally). >> Is that confusing or actually simplifying the submodule workflow? > > Not sure. That's why I asked you. :) I think that would be ok. With the idea of inheriting the superprojects config, we allow for not storing the rewritten url, so the submodule handling is less of a corner case here, and as another advantage the rewriting rule is applied in real time, e.g. you can change the superprojects rule after the fact and the submodule would automagically make use of it. > > One other caveat: I'm not sure if we do insteadOf recursively, but it > may be surprising to the child "git clone" that we've already applied > the insteadOf rewriting (especially if the rules are coming from > ~/.gitconfig and may be applied twice). When a rule is having effect twice the rule sounds broken. (the outcome ought to be sufficiently different from the original?) > > -Peff Thanks, Stefan