Skip to content

Commit cc0e29f

Browse files
OskiKervinen-MFadmorgan
authored andcommitted
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 b03bf53 commit cc0e29f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

lib/git-subrepo

+13
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,20 @@ subrepo:branch() {
744744
local first_gitrepo_commit=
745745

746746
o "Subrepo parent: $subrepo_parent"
747+
747748
if [[ $subrepo_parent ]]; then
749+
750+
# Check if the subrepo parent is an ancestor of HEAD.
751+
# For example rebasing the commit that touched the subrepo
752+
# could make the commit no longer match.
753+
local parent_is_ancestor=
754+
git merge-base --is-ancestor "$subrepo_parent" HEAD && parent_is_ancestor="true"
755+
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."
759+
fi
760+
748761
local prev_commit=
749762
local ancestor=
750763
o "Create new commits with parents into the subrepo fetch"

0 commit comments

Comments
 (0)