From 207f62acb4452507f963f5103d2b8c8dff518c90 Mon Sep 17 00:00:00 2001 From: yasuda Date: Thu, 8 Feb 2024 18:30:16 +0900 Subject: [PATCH] Try to search non-direct submodule's exact commit --- git-archive-all.sh | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/git-archive-all.sh b/git-archive-all.sh index 739b064..501126f 100755 --- a/git-archive-all.sh +++ b/git-archive-all.sh @@ -257,17 +257,37 @@ git submodule status --recursive --cached >> "$TMPLIST" while read path; do # 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 + # It is not top repo's direct submodule. + ppath=${path%/}; ppath=${ppath%/*} + pathbase=${path%/}; pathbase=${pathbase##*/} + while [ -n "${ppath}" ]; do + PARENT_TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${ppath}"'$@\1@ p' "$TMPLIST" | tail -n1) + if [ -n "$PARENT_TREEISH" ]; then + TREEISH=$(git -C "${ppath}" ls-tree "${PARENT_TREEISH}" "${pathbase}" | awk '{ print $3 }') + fi + if [ ${ppath} == ${ppath%/*} ]; then + break + else + pathbase="${ppath##*/}/${pathbase}" + ppath=${ppath%/*} + fi + done + fi + 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") + TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST" | tail -n1) 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 " ${TREEISH} ${path%/}" >> "${TMPLIST}" # Update the chosen commit echo >&2 "Submodule \"${path%/}\" commit for top repo's ${TOP_TREEISH}: ${TREEISH:-HEAD} ($(git -C ${path} name-rev --name-only "${TREEISH}"))" cd "$path"