Skip to content

Commit f4a38d3

Browse files
rhbradfordbenhyland
authored andcommitted
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 110b9eb commit f4a38d3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/git-subrepo

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Options:
6464
h Show the command summary
6565
help Help overview
6666
version Print the git-subrepo version number
67-
67+
6868
a,all Perform command on all current subrepos
6969
A,ALL Perform command on all subrepos and subsubrepos
7070
b,branch= Specify the upstream branch to push/pull/fetch
@@ -77,7 +77,7 @@ file= Specify a commit message file
7777
r,remote= Specify the upstream remote to push/pull/fetch
7878
s,squash Squash commits on push
7979
u,update Add the --branch and/or --remote overrides to .gitrepo
80-
80+
8181
q,quiet Show minimal output
8282
v,verbose Show verbose output
8383
d,debug Show the actual commands used
@@ -788,8 +788,8 @@ subrepo:branch() {
788788
[[ $prev_commit ]] && first_parent=(-p "$prev_commit")
789789
second_parent=()
790790
if [[ -z $first_gitrepo_commit ]]; then
791-
first_gitrepo_commit=$gitrepo_commit
792-
second_parent=(-p "$gitrepo_commit")
791+
first_gitrepo_commit=$subrepo_commit
792+
second_parent=(-p "$subrepo_commit")
793793
fi
794794

795795
if [[ $join_method != rebase ]]; then

0 commit comments

Comments
 (0)