-
Notifications
You must be signed in to change notification settings - Fork 23
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
fix: Handle the original parent is a trunk case #117
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,12 +179,21 @@ func syncBranchRebase( | |
}, nil | ||
} | ||
|
||
var origUpstream string | ||
if origParent.Trunk { | ||
// We do not know the original trunk commit hashes. Use the current one as | ||
// an approximation. | ||
origUpstream = newUpstreamCommitHash | ||
} else { | ||
origUpstream = origParent.Head | ||
} | ||
|
||
continuation := SyncBranchContinuation{ | ||
NewParentName: parentState.Name, | ||
} | ||
rebase, err := repo.RebaseParse(git.RebaseOpts{ | ||
Branch: branch.Name, | ||
Upstream: origParent.Head, | ||
Upstream: origUpstream, | ||
Onto: newUpstreamCommitHash, | ||
}) | ||
if err != nil { | ||
|
@@ -248,6 +257,16 @@ func syncBranchRebase( | |
// Note that we've introduced B into the history of stacked-2, but | ||
// not C or D since those commits come after M. | ||
newUpstreamCommitHash := origParentBranch.MergeCommit | ||
var origUpstream string | ||
if origParent.Trunk { | ||
var err error | ||
origUpstream, err = repo.RevParse(&git.RevParse{Rev: "origin/" + origParent.Name}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my understanding, if i read the Is that an intended change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BranchState.Head is empty if Trunk = true. Hence this change. |
||
if err != nil { | ||
return nil, errors.WrapIff(err, "failed to get HEAD of %q", origParent.Name) | ||
} | ||
} else { | ||
origUpstream = origParent.Head | ||
} | ||
continuation := SyncBranchContinuation{ | ||
NewParentName: parentState.Name, | ||
} | ||
|
@@ -260,7 +279,7 @@ func syncBranchRebase( | |
} | ||
rebase, err := repo.RebaseParse(git.RebaseOpts{ | ||
Branch: branch.Name, | ||
Upstream: origParent.Head, | ||
Upstream: origUpstream, | ||
Onto: newUpstreamCommitHash, | ||
}) | ||
if err != nil { | ||
|
@@ -305,6 +324,18 @@ func syncBranchRebase( | |
" of parent branch ", colors.UserInput(parentState.Name), | ||
"\n", | ||
) | ||
var origUpstream string | ||
if origParent.Trunk { | ||
// This can happen if the branch is originally a stack root and reparented to | ||
// another branch (and became non-stack-root). | ||
var err error | ||
origUpstream, err = repo.RevParse(&git.RevParse{Rev: "origin/" + origParent.Name}) | ||
if err != nil { | ||
return nil, errors.WrapIff(err, "failed to get HEAD of %q", origParent.Name) | ||
} | ||
} else { | ||
origUpstream = origParent.Head | ||
} | ||
// We need to use `rebase --onto` here and be very careful about how we | ||
// determine the commits that are being rebased on top of parentHead. | ||
// Suppose we have a history like | ||
|
@@ -339,7 +370,7 @@ func syncBranchRebase( | |
} | ||
rebase, err := repo.RebaseParse(git.RebaseOpts{ | ||
Branch: branch.Name, | ||
Upstream: origParent.Head, | ||
Upstream: origUpstream, | ||
Onto: parentHead, | ||
}) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not do a revparse here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newUpstreamCommitHash
is either a result of the revparse or the merge commit which is close to the original upstream.