Skip to content

Commit

Permalink
Store exact submodule commits for direct submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
KSR-Yasuda committed Feb 8, 2024
1 parent 4f11a32 commit 388a0a4
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion git-archive-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 388a0a4

Please sign in to comment.