From 1348bbe6477ee1bce27cde3af1a8312f568dd6ae Mon Sep 17 00:00:00 2001 From: Oski Kervinen Date: Fri, 19 Jul 2019 15:22:26 +0300 Subject: [PATCH 1/2] 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. --- lib/git-subrepo | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/git-subrepo b/lib/git-subrepo index 68918cbe..1902e1ad 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -700,6 +700,18 @@ subrepo:branch() { local first_gitrepo_commit= o "Subrepo parent: $subrepo_parent" + + # 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 + if [[ -n "$subrepo_parent" ]]; then local prev_commit= local ancestor= From f2615153f9d886a8301abd13280f353e7cfe8846 Mon Sep 17 00:00:00 2001 From: Oski Kervinen Date: Mon, 22 Jul 2019 09:28:22 +0300 Subject: [PATCH 2/2] Only verify the parent commit when it is going to be used Moved the parent verification inside the branch that actually depends on the parent. Without that it fails needlessly when there is no parent yet. --- lib/git-subrepo | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index 1902e1ad..dff9fd53 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -701,18 +701,19 @@ subrepo:branch() { o "Subrepo parent: $subrepo_parent" - # 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 - if [[ -n "$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"