Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes edge case with subrepo push failing on rebase #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rhbradford
Copy link

We have found that in some cases, a subrepo push fails when rebasing.

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.
The subrepo push is automated as part of the build and can cross with other developer commits.

We propose starting 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

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, 
and 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)

Note that 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 most recent .gitrepo file (subrepo.parent=D, subrepo.commit=C')
to determine the initial commit for the subrepo branch.
Again, the rev-list used in subrepo:branch starts from D and gives [E, F].
This time, however, when processing E, which is the initial commit to the branch,
the subrepo branch process starts from C', and produces:

A' -> C' -> E''

which will always rebase successfully.

jameswalmsley added a commit to jameswalmsley/git-subrepo that referenced this pull request Mar 20, 2021
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.
@benhyland
Copy link

Just rebased this to upstream master, still curious to know whether it can be accepted by upstream although we are doing fine running off a fork for ourselves. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants