The problem: Can I pin git modules to specific commits?
I am writing a build script to produce an artifact which is a Zip archive of multiple submodules with a few requirements.
- the artifact generated must be tagged / versioned
- the tag of the repo with the build script must be used to version the artifact
Here is the rub:
If I checkout:
git clone git@whatever:thing/mybuildscipt
and then do
git submodule update --init
I need the exact commit number of each submodule to be recorded in the build script's repo (ideally in .gitmodules) so that in the future, if I should do
git checkout 1.2.3
git submodule update
I am going to the same submodules as they were at when the build script repo was tagged with "1.2.3".
Long ago, this is exactly how git submodules worked: They were pinned to a specific commit and that commit hash was actually in the .gitmodule
- I need that behavior and it's not at all clear to me, based on my research, if it's still possible.
Here is a summary of the commands being run the in build script, so that you can get the idea what is to be accomplished. Ultimately if I checkout a specific version of the git repo that contains the build script, it should produce an identical zip archive as before.
export NEXT_VERSION=$(
git tag --sort=committerdate \
| tail -1 \
| awk -F '.' '{print $1"."$2"." $3 +1}')
git submodule update --init
# remove the .git dir to save space
git submodule | awk '{print $2}' | xargs -I {} -n 1 rm -fR {}/.git
git submodule | awk '{print $2}' | xargs zip -qr ${FILE_NAME}
# push to object storage
mc cp ${FILE_NAME} ${ALIAS}/${bucket}/${FILE_NAME}
# tag
git tag ${NEXT_VERSION}
# update tags
git push --tags origin