Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use relative URLs for git submodules #4879

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

rpadaki
Copy link
Contributor

@rpadaki rpadaki commented May 16, 2023

Summary

This PR closes #1925 and maybe some other duplicate issues where people are complaining about not knowing how to clone submodules. It also removes the need for this section in the Wiki.

It does so by modifying the submodule configuration to inherit the parent repository's cloning method.

Feel free to close this if there's no appetite to mess with submodules at the moment!

Implementation

Git actually allows submodule URLs to be specified relative to the repo's upstream URL. For example, let's say I have a GitHub repo OpenEmu/repo with a submodule configured like:

# .gitmodules
[submodule "dep"]
  path = dep
  url = ../../OpenEmu/dep.git

If I clone git clone https://github.com/OpenEmu/repo and initialize the submodule, this would use https://github.com/OpenEmu/dep.git as the submodule URL. Meanwhile, if I were to use git clone git@github.com:OpenEmu/repo, this would use git@github.com/OpenEmu/dep.git. That is, this approach is agnostic between HTTPS and SSH cloning, and just inherits the parent repo's upstream URL!

Notes

  • Whenever changing the URLs in .gitmodules, make sure to run git submodule sync to actually update those URLs in the submodule repositories. This would only need to happen when changing between this and other branches and if this branch gets merged.
  • This assumes that all submodules are available on the same URL (github.com) as the parent repo. Submodules not on GitHub would need to be specified via an absolute URL. Currently all submodules are GitHub repos, so non-issue.
    • As a result, this would break OpenEmu mirrored on other git services like Gitlab unless all of the submodule repos are also mirrored on that service. Don't see this as an issue because the only up-to-date OpenEmu seems to be here.
  • Instead of url = ../../OpenEmu/dep.git, I could have just as easily set url = ../dep.git. The reason to fully qualify the repo owner/name is because it ensures that the URLs are correct for forks -- when I fork OpenEmu into rpadaki/OpenEmu, I still want to use OpenEmu/XXX.git repos for the submodules, not rpadaki/XXX.git.

@rpadaki rpadaki closed this Aug 18, 2023
@J-rg J-rg reopened this Aug 29, 2023
@J-rg J-rg merged commit a04c513 into OpenEmu:master Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

URL scheme for Git submodules
2 participants