![]() ![]() My favourite part: for i in $(git submodule foreach -quiet 'echo $path') To make this work, everything in the iteration must be wrapped in the double-quotes and the Git commands are wrapped in parentheses (operator precedence). Again, it only happens if a pull actually brought in new stuff.įinally, the final || true is ensuring that script continues on errors. Notice a few things: First of all, I'm chaining some Git commands using & - meaning previous command must execute without error.Īfter a possible successful pull (if new stuff was found on the remote), I do a push to ensure that a possible merge-commit is not left behind on the client. ![]() Then I update/pull all submodules: git submodule foreach "(git checkout $BRANCH & git pull -ff origin $BRANCH & git push origin $BRANCH) || true" Then some submodule initializing, might be necessary, if new submodules have been added or are not initialized yet: git submodule sync git checkout $BRANCH & git pull -ff origin $BRANCH Then I pull the parent repository's latest stuff (I prefer to use -ff (fast-forwarding) whenever I'm just doing pulls. ![]() The first couple of sections is some checking that the arguments are there. Feel free to make this even more complex. To run it, execute git-update-submodules.sh /path/to/base/repo BRANCH_NAMEįirst of all, I assume that the branch with name $BRANCH (second argument) exists in all repositories. Git commit -m "Updated $BRANCH branch of deployment repo to point to latest head of submodules" Git submodule foreach "(git checkout $BRANCH & git pull -ff origin $BRANCH & git push origin $BRANCH) || true"įor i in $(git submodule foreach -quiet 'echo $path') Git checkout $BRANCH & git pull -ff origin $BRANCH It would be cool to have an automated iteration through each submodule, updating the parent repository pointer (using git add) to point to the head of the submodule(s).Įcho "Missing 1st argument: should be path to folder of a git repo" Įcho "Missing 2nd argument (branch name)" a script to update the parent repository's commit pointers. Not very practical, since you would have to hardcode n paths to all n submodules in e.g. This would be done by git submodule foreach git pull origin BRANCH New stuff has happened in one or more submodules, and I want to 1) pull these changes and 2) update the parent repository to point to the HEAD (latest) commit of this/these submodules. Scenario 2, which I think is what OP is aiming at This is, as pointed out, done with git submodule foreach git pull origin BRANCH Using my parent repository's pointers to submodules, I want to check out the commit in each submodule that the parent repository is pointing to, possibly after first iterating through all submodules and updating/pulling these from remote. It seems like two different scenarios are being mixed together in this discussion: Thus far I've just been rm-ing the module and re-adding it, but this is both wrong in principle and tedious in practice. I've also tried git fetch mod, which appears to do a fetch (but can't possibly, because it's not prompting for a password!), but git log and git show deny the existence of new commits. Nothing to commit (working directory clean) Submodule 'mod' registered for path 'mod' # At this point, changes submodule needs to change too. Hello world.Ģ files changed, 4 insertions(+), 0 deletions(-) Remote: Total 131 (delta 54), reused 0 (delta 0) Initialized empty Git repository in /./foo/.git/ It doesn't do anything (no output, success exit code). Now, my understanding is that git submodule update should do this, but it doesn't. Commit B has been pushed to that URL, and I want the submodule to retrieve the commit, and change to it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |