Skip to content

Commit 1c522f9

Browse files
committed
Try to search non-direct submodule's exact commit
1 parent 388a0a4 commit 1c522f9

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

git-archive-all.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,40 @@ git submodule status --recursive --cached >> "$TMPLIST"
257257
while read path; do
258258
# git submodule does not list trailing slashes in $path. Remove it in $TREEISH search.
259259
TREEISH=$(git ls-tree "${TOP_TREEISH}" "${path%/}" | awk '{ print $3 }')
260+
261+
if [ -z "$TREEISH" ]; then
262+
# It is not top repo's direct submodule.
263+
ppath=${path%/}; ppath=${ppath%/*}
264+
pathbase=${path%/}; pathbase=${pathbase##*/}
265+
while [ -n "${ppath}" ]; do
266+
PARENT_TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${ppath}"'$@\1@ p' "$TMPLIST" | tail -n1)
267+
if [ -n "$PARENT_TREEISH" ]; then
268+
TREEISH=$(git -C "${ppath}" ls-tree "${PARENT_TREEISH}" "${pathbase}" | awk '{ print $3 }')
269+
if [ -n "${TREEISH}" ]; then
270+
break;
271+
fi
272+
fi
273+
if [ ${ppath} == ${ppath%/*} ]; then
274+
break
275+
else
276+
pathbase="${ppath##*/}/${pathbase}"
277+
ppath=${ppath%/*}
278+
fi
279+
done
280+
fi
281+
260282
if [ -z "$TREEISH" ]; then
261283
if [ "$TOP_TREEISH_HASH" != "$TOP_HEAD_HASH" ]; then
262284
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"
263285
fi
264286

265-
TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST")
287+
TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST" | tail -n1)
266288
if [ -z "$TREEISH" ]; then
267289
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"
268290
TREEISH=HEAD
269291
fi
270292
fi
293+
echo " ${TREEISH} ${path%/}" >> "${TMPLIST}" # Update the chosen commit
271294
echo >&2 "Submodule \"${path%/}\" commit for top repo's ${TOP_TREEISH}: ${TREEISH:-HEAD} ($(git -C ${path} name-rev --name-only "${TREEISH}"))"
272295

273296
cd "$path"

0 commit comments

Comments
 (0)