Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In the superproject, right after a clone, run these commands:
- #!/bin/sh
- #define the actions to take when running submodule update for each submodule
- repo_root=$(git rev-parse --show-toplevel)
- git config submodule.sub1.update '!'"${repo_root}/sparse1.sh"
- git config submodule.sub2.update '!'"${repo_root}/sparse2.sh"
- In this example, we need two scripts because we want different dirs checked out in sub1 and sub2.
- See "dir/to/checkout" in script example below.
- These scripts will be run in lieu of the normal "git checkout <SHA1>" command that is run as part of the submodule update command.
- Then, you can run the update with init command as usual:
- git submodule update --init
- Contents of the the sparse checkout scripts (sparse1.sh / sparse2.sh):
- #!/bin/sh
- #script is called with a single argument, the hash of the submodule commit recorded in the superproject,
- #and it runs in the submodule directory
- git config core.sparseCheckout true
- sub_git_dir=$(git rev-parse --git-dir)
- echo dir/to/checkout > ${sub_git_dir}/info/sparse-checkout
- git checkout --quiet $1
Add Comment
Please, Sign In to add comment