Skip to content

Commit 89f7de4

Browse files
Show clearer error message when subrepo_parent is not an ancestor of HEAD
Before, there would be a cryptic error about invalid parameters, because prev_commit would never get set. This situation can occur when the commit that last touched the subrepo has been rebased.
1 parent d4a04f1 commit 89f7de4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/git-subrepo

+12
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,18 @@ subrepo:branch() {
700700
local first_gitrepo_commit=
701701

702702
o "Subrepo parent: $subrepo_parent"
703+
704+
# Check if the subrepo parent is an ancestor of HEAD.
705+
# For example rebasing the commit that touched the subrepo
706+
# could make the commit no longer match.
707+
local parent_is_ancestor=
708+
git merge-base --is-ancestor "$subrepo_parent" HEAD && parent_is_ancestor="true"
709+
if [[ -z "$parent_is_ancestor" ]]; then
710+
error "The previous commit where the subrepo was updated, '$subrepo_parent' is not an ancestor of HEAD. \n \
711+
Did you rebase that commit?\n \
712+
Try manually setting subrepo.parent in .gitrepo to the hash of the correct commit."
713+
fi
714+
703715
if [[ -n "$subrepo_parent" ]]; then
704716
local prev_commit=
705717
local ancestor=

0 commit comments

Comments
 (0)