Search code examples
gitgithubgit-submodulesgithub-pagesgit-subtree

Can a github repo be made to always refer to the latest version of its submodule repos?


I'm making a webapp that does version control of files using git and it has the option of being hosted on GitHub Pages with some missing features (features not supported by a git-only backend).

Now the "app" itself is separated from the users content, the user content is version controlled but the app is not (or at least doesn't need to be for the functionality of the app itself), but both need to be uploaded to github pages and to isolate the content's version control, and to have different permissions for the app vs content, I host the app itself in gh-pages and the content as a git submodule inside the gh-pages repo.

This works, the app/site is built and gets exposed on username.github.io/sitename/ with everything accessible, except there is a catch.

The catch is that for some reason the submodule content repo is referred to at a specific commit instead of just the latest version of the repo, which means I can't just update the content repo and have everything work but also have to update the app repo to refer to the latest version of the submodule, on every content repo commit.

Which gets a bit tedious since I almost never actually have to update the app repo unless there is a new version of the app but I update the content repo daily, as well as the fact that the content repo should be editable by many people but the app repo by few.

So my question is:

  • How can I define a submodule to always refer to the latest commit of a repo?
  • How can I trigger a build of the site by only updating the submodule repo?
  • How can the gh-pages repo always reflect the latest version of its submodules, so that the gh-pages site is always serving the latest content?

How I create the submodule

# Create app master + app-content master, then:
git init
git remote add origin https://github.com/01AutoMonkey/app.git
git submodule add https://github.com/01AutoMonkey/app-content ./wiki
cd wiki
git remote add origin https://github.com/01AutoMonkey/app-content.git
# And then push to both repos and create a gh-pages branch.
# The site is now running but if I update app-content the update isn't reflected on the site until I refer to the new commit in the app repo.

Solution

  • Please find my responses inline:

    How can I define a submodule to always refer to the latest commit of a repo?

    This is not possible from the concept and purpose of git-submodule. Though for easy update purpose you can configure a branch for a submodule.

    $ git config -f .gitmodules submodule.hs-srvcommon.branch sprint is the command which will override the default master branch with sprint. (hs-srvcommon is the name of the submodule directory)

    How can I trigger a build of the site by only updating the submodule repo?

    You can write commands to trigger your build on the commits made on the submodule repo using the git-hooks on the submodule. The git-hooks configured on the submodule work the same way as the git-hooks for main repo work. The residing place for the hooks of the submodules are .git/modules/your-sub-module-name/hooks Refer: https://git-scm.com/docs/githooks

    How can the gh-pages repo always reflect the latest version of its submodules, so that the gh-pages site is always serving the latest content?

    Ohh this again should be feasible with using the git-hooks for the submodule. All you need to do is configure the post-commit/push-hooks on the submodule so that they also update the main repo references to the submodule commit sha ids.

    May this answer help you in doing some git operations on the main repo from inside the git-hooks of the submodule repo.