From 388a0a45e304be2e8025d2a5f642d7754fab6d57 Mon Sep 17 00:00:00 2001 From: yasuda Date: Thu, 8 Feb 2024 15:42:22 +0900 Subject: [PATCH] Store exact submodule commits for direct submodule. --- git-archive-all.sh | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/git-archive-all.sh b/git-archive-all.sh index 13e01e6..739b064 100755 --- a/git-archive-all.sh +++ b/git-archive-all.sh @@ -249,9 +249,27 @@ fi if [ $VERBOSE -eq 1 ]; then echo -n "archiving submodules..." fi + +TOP_TREEISH=$TREEISH +TOP_TREEISH_HASH=$(git rev-parse "$TOP_TREEISH") +TOP_HEAD_HASH=$(git rev-parse HEAD) git submodule status --recursive --cached >> "$TMPLIST" while read path; do - TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST") # git submodule does not list trailing slashes in $path + # git submodule does not list trailing slashes in $path. Remove it in $TREEISH search. + TREEISH=$(git ls-tree "${TOP_TREEISH}" "${path%/}" | awk '{ print $3 }') + if [ -z "$TREEISH" ]; then + if [ "$TOP_TREEISH_HASH" != "$TOP_HEAD_HASH" ]; then + echo >&2 -e "\e[33;1mWarning:\e[22m Submodule \"${path%/}\" hash for top repo's ${TOP_TREEISH} was not obtained. Use the commit for top repo's HEAD.\e[m" + fi + + TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST") + if [ -z "$TREEISH" ]; then + echo >&2 -e "\e[33;1mWarning:\e[22m Submodule \"${path%/}\" hash for top repo's HEAD was not obtained. Use the commit for the submodule's HEAD.\e[m" + TREEISH=HEAD + fi + fi + echo >&2 "Submodule \"${path%/}\" commit for top repo's ${TOP_TREEISH}: ${TREEISH:-HEAD} ($(git -C ${path} name-rev --name-only "${TREEISH}"))" + cd "$path" rm -f "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT git archive --format=$FORMAT --prefix="${PREFIX}$path" $ARCHIVE_OPTS ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT