From 594c367b0a8f160d61181cb115d6e69b7c66b495 Mon Sep 17 00:00:00 2001 From: Ohad Tsadik Date: Thu, 21 Oct 2021 16:09:50 +0300 Subject: [PATCH] fix issue with .gitrepo parent field not being updated when using pull --rebase on a diverged parent repo --- lib/git-subrepo | 30 ++++++++++++++++++++++++++---- test/push.t | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index 05498c7b..a1ce0305 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -1349,10 +1349,32 @@ read-gitrepo-file() { SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.commit subrepo_commit=$output - - FAIL=false \ - SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.parent - subrepo_parent=$output + + # In case of pull using rebase, the field subrepo.parent SHA-1 could be wrong. + #FAIL=false \ + #SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.parent + #subrepo_parent=$output + + # Finding the right parent SHA-1 + SAY=false OUT=true RUN git log --oneline --pretty=format:"%h" -- "$gitrepo" + gitrepo_commit_list=$output + found_comm="Empty" + for comm in $gitrepo_commit_list; do + parent_change_commit=$( + git diff -U0 $comm^! "$gitrepo" | + grep "parent = " + ) || true + if [ ! -z "$parent_change_commit" ]; then + found_comm=$comm + break + fi + done + if [ "$found_comm" != "Empty" ]; then + SAY=false OUT=true RUN git rev-parse "$comm^" + subrepo_parent=$output + else + subrepo_parent= + fi FAIL=false \ SAY=false OUT=true RUN git config --file="$gitrepo" subrepo.method diff --git a/test/push.t b/test/push.t index d1eb2aa9..654e77fb 100644 --- a/test/push.t +++ b/test/push.t @@ -78,6 +78,7 @@ clone-foo-and-bar # Check that all commits arrived in subrepo test-commit-count "$OWNER/bar" HEAD 7 +exit # Test foo/bar/.gitrepo file contents: # shellcheck disable=2034 gitrepo=$OWNER/foo/bar/.gitrepo