From f4a38d3eec95fa8024c4ab7fad077beaa9f7e76e Mon Sep 17 00:00:00 2001 From: Richard Bradford Date: Wed, 8 Jul 2020 13:49:24 +0100 Subject: [PATCH] Fix edge case with subrepo push Note that our use case is to publish a subdirectory of a monorepo to a public subrepo. We only ever push, as there are never any other changes to the remote subrepo. That push is automated as part of the build and can cross with other developer commits. Start the subrepo branch from the most recent subrepo.commit value instead of from the subrepo.commit value that was current at the time of the first commit to be included in the branch. A simplified example of the situation: Parent repo log A -> B -> C -> D -> E -> F -> G F: commit of .gitrepo file (subrepo.parent=D, subrepo.commit=C') E: commit in subrepo directory D: some commit C: commit in subrepo directory B: commit of .gitrepo file (subrepo.parent=A, subrepo.commit=A') A: commit in subrepo directory [Whilst pushing C to remote, D and E were committed to parent, then the result of the push was committed to parent in F] Remote repo log A' -> C' C': commit corresponding to C A': commit corresponding to A Now we want to push E to remote: Before this change: The rev-list used in subrepo:branch starts from D and gives [E, F]. commit E has .gitrepo file (subrepo.parent=A, subrepo.commit=A') so the subrepo branch process starts from A', and produces: A' -> E'' (F'' is filtered out as it is empty after .gitrepo is removed) C' has been omitted from the subrepo branch. This can cause a conflict during rebase if E depends on C. With this change, we always use the .gitrepo file (subrepo.parent=D, subrepo.commit=C') when processing E, so the subrepo branch process starts from C', and produces: A' -> C' -> E'' which will always rebase successfully. --- lib/git-subrepo | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/git-subrepo b/lib/git-subrepo index a6d5d96a..85d64570 100755 --- a/lib/git-subrepo +++ b/lib/git-subrepo @@ -64,7 +64,7 @@ Options: h Show the command summary help Help overview version Print the git-subrepo version number - + a,all Perform command on all current subrepos A,ALL Perform command on all subrepos and subsubrepos b,branch= Specify the upstream branch to push/pull/fetch @@ -77,7 +77,7 @@ file= Specify a commit message file r,remote= Specify the upstream remote to push/pull/fetch s,squash Squash commits on push u,update Add the --branch and/or --remote overrides to .gitrepo - + q,quiet Show minimal output v,verbose Show verbose output d,debug Show the actual commands used @@ -788,8 +788,8 @@ subrepo:branch() { [[ $prev_commit ]] && first_parent=(-p "$prev_commit") second_parent=() if [[ -z $first_gitrepo_commit ]]; then - first_gitrepo_commit=$gitrepo_commit - second_parent=(-p "$gitrepo_commit") + first_gitrepo_commit=$subrepo_commit + second_parent=(-p "$subrepo_commit") fi if [[ $join_method != rebase ]]; then