Skip to content

Commit

Permalink
Show clearer error message when subrepo_parent is not an ancestor of …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
OskiKervinen-MF authored and admorgan committed Jul 9, 2024
1 parent 84095bc commit 1e4ca5c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/git-subrepo
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,20 @@ subrepo:branch() {
local first_gitrepo_commit=

o "Subrepo parent: $subrepo_parent"

if [[ $subrepo_parent ]]; then

# Check if the subrepo parent is an ancestor of HEAD.
# For example rebasing the commit that touched the subrepo
# could make the commit no longer match.
local parent_is_ancestor=
git merge-base --is-ancestor "$subrepo_parent" HEAD && parent_is_ancestor="true"
if [[ -z "$parent_is_ancestor" ]]; then
error "The previous commit where the subrepo was updated, '$subrepo_parent' is not an ancestor of HEAD. \n \
Did you rebase that commit?\n \
Try manually setting subrepo.parent in .gitrepo to the hash of the correct commit."
fi

local prev_commit=
local ancestor=
o "Create new commits with parents into the subrepo fetch"
Expand Down

0 comments on commit 1e4ca5c

Please sign in to comment.