Skip to content

Commit e7411ba

Browse files
committed
Add context for missing parent error message
I did not find it immediately obvious how to gather the information needed to fix a missing parent error. Search the repository for the values needed and present them as part of the message. Fixes #617, #415, #600
1 parent cc0e29f commit e7411ba

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

lib/git-subrepo

+10-3
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,16 @@ subrepo:branch() {
753753
local parent_is_ancestor=
754754
git merge-base --is-ancestor "$subrepo_parent" HEAD && parent_is_ancestor="true"
755755
if [[ -z "$parent_is_ancestor" ]]; then
756-
error "The previous commit where the subrepo was updated, '$subrepo_parent' is not an ancestor of HEAD. \n \
757-
Did you rebase that commit?\n \
758-
Try manually setting subrepo.parent in .gitrepo to the hash of the correct commit."
756+
local prev_merge_point
757+
prev_merge_point=$(git log -1 -G "commit =" --format="%H" "$gitrepo")
758+
# We want the SHA of the patch before the sync point just in case someone made a modifcation in the
759+
# actual sync commit
760+
prev_merge_point=$(git log -1 --format="%H" "$prev_merge_point"^)
761+
error "The last sync point (where upstream and the subrepo were equal) is not an ancestor. \n \
762+
This is usually caused by a rebase affecting that commit. \n \
763+
To recover set the subrepo parent in '$gitrepo'\n \
764+
to '$prev_merge_point' \n \
765+
and validate the subrepo by comparing with 'git subrepo branch $subdir'"
759766
fi
760767

761768
local prev_commit=

0 commit comments

Comments
 (0)