Skip to content

Commit 207f62a

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

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

git-archive-all.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,37 @@ 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+
fi
270+
if [ ${ppath} == ${ppath%/*} ]; then
271+
break
272+
else
273+
pathbase="${ppath##*/}/${pathbase}"
274+
ppath=${ppath%/*}
275+
fi
276+
done
277+
fi
278+
260279
if [ -z "$TREEISH" ]; then
261280
if [ "$TOP_TREEISH_HASH" != "$TOP_HEAD_HASH" ]; then
262281
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"
263282
fi
264283

265-
TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST")
284+
TREEISH=$(sed -nr -e 's@^[ +-]@@' -e 's@ +\(.*\)$@@' -e 's@([^ ]+) +'"${path%/}"'$@\1@ p' "$TMPLIST" | tail -n1)
266285
if [ -z "$TREEISH" ]; then
267286
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"
268287
TREEISH=HEAD
269288
fi
270289
fi
290+
echo " ${TREEISH} ${path%/}" >> "${TMPLIST}" # Update the chosen commit
271291
echo >&2 "Submodule \"${path%/}\" commit for top repo's ${TOP_TREEISH}: ${TREEISH:-HEAD} ($(git -C ${path} name-rev --name-only "${TREEISH}"))"
272292

273293
cd "$path"

0 commit comments

Comments
 (0)