Skip to content

Commit d9c0c64

Browse files
committed
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.
1 parent a04d8c2 commit d9c0c64

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/git-subrepo

+2-2
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ subrepo:branch() {
747747
[[ -n $prev_commit ]] && first_parent="-p $prev_commit"
748748
local second_parent=
749749
if [[ -z "$first_gitrepo_commit" ]]; then
750-
first_gitrepo_commit="$gitrepo_commit"
751-
second_parent="-p $gitrepo_commit"
750+
first_gitrepo_commit="$subrepo_commit"
751+
second_parent="-p $subrepo_commit"
752752
fi
753753

754754
if [[ "$join_method" != "rebase" ]]; then

0 commit comments

Comments
 (0)