Skip to content

Commit 388a0a4

Browse files
committed
Store exact submodule commits for direct submodule.
1 parent 4f11a32 commit 388a0a4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

git-archive-all.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,27 @@ fi
249249
if [ $VERBOSE -eq 1 ]; then
250250
echo -n "archiving submodules..."
251251
fi
252+
253+
TOP_TREEISH=$TREEISH
254+
TOP_TREEISH_HASH=$(git rev-parse "$TOP_TREEISH")
255+
TOP_HEAD_HASH=$(git rev-parse HEAD)
252256
git submodule status --recursive --cached >> "$TMPLIST"
253257
while read path; do
254-
TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST") # git submodule does not list trailing slashes in $path
258+
# git submodule does not list trailing slashes in $path. Remove it in $TREEISH search.
259+
TREEISH=$(git ls-tree "${TOP_TREEISH}" "${path%/}" | awk '{ print $3 }')
260+
if [ -z "$TREEISH" ]; then
261+
if [ "$TOP_TREEISH_HASH" != "$TOP_HEAD_HASH" ]; then
262+
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"
263+
fi
264+
265+
TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST")
266+
if [ -z "$TREEISH" ]; then
267+
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"
268+
TREEISH=HEAD
269+
fi
270+
fi
271+
echo >&2 "Submodule \"${path%/}\" commit for top repo's ${TOP_TREEISH}: ${TREEISH:-HEAD} ($(git -C ${path} name-rev --name-only "${TREEISH}"))"
272+
255273
cd "$path"
256274
rm -f "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT
257275
git archive --format=$FORMAT --prefix="${PREFIX}$path" $ARCHIVE_OPTS ${TREEISH:-HEAD} > "$TMPDIR"/"$(echo "$path" | sed -e 's/\//./g')"$FORMAT

0 commit comments

Comments
 (0)