-
Notifications
You must be signed in to change notification settings - Fork 897
Initial Rebase implementation #964
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
Conversation
573bddf
to
36657cb
Compare
/// <summary> | ||
/// Access to Rebase functionality. | ||
/// </summary> | ||
Rebase RebaseOperation { get; } |
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.
How do you foresee to use this?
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.
Found it. Not sure I'm a fan of having the Rebase()
method in the main namespace and the other methods under RebaseOperation
. How about exposing a separate repo.Rebase
namespace (à la repo.Diff
)?
We could replace repo.Rebase()
with something like repo.Rebase.Start()
, Initiate()
, ...
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.
yes - that seems reasonable. Thinking about the larger picture, cherry-pick and revert both have a similar "sequenced" capability. If we put rebase in its own namespace, then we would we have repo.CherryPick.Start(...)
, and repo.Revert.Start(...)
? These (and Merge) all seem to be similar types of operations, would Merge also move into a repo.Merge.Start(...)
type of structure? One option is that we could do this, and then have extension methods to expose these on the repository object directly?
How does the code behave when
|
The code should throw an exception in these cases. There is already a test case that covers initiating a rebase while one is already started RebaseWhileAlreadyRebasingThrows(). I can add test coverage to assert we throw in the other case as well. |
|
/// <param name="committer"></param> | ||
/// <param name="options"></param> | ||
/// <returns>true if completed successfully, false if conflicts encountered.</returns> | ||
public virtual RebaseResult Start(Branch branch, Branch upstream, Branch onto, Signature committer, RebaseOptions options) |
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.
In the long run, I think it would be more flexible to take a commit rather than a branch, at least for the onto
argument. I often use rebase -i some_commit_id
to clean up before a push. This could be added as an overload later though.
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.
We probably don't want to take a bare commit here - these things end up influencing the messages that we produce in the reflog and the markers in the conflict files. Do we have the equivalent of an AnnotatedCommit
in libgit2sharp?
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.
Sorry, to expand on that a little bit more: I mean we probably shouldn't only take a commit id (but we should perhaps allow it). Although a Branch
is going to be convertible to a commit ID at some point, if you let libgit2 handle that conversion it will keep around the information of where that commit ID came from (as an "annotated commit"). Without that your conflict markers will look like:
<<<< ab1dc99f...
change on one side
===== ab1cdde
common ancestor
=====
change on the other side
>>>>> 9acca3a
Which is quite hard to read (I think) compared to having the branch names / etc.
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.
Could it just take GitAnnotatedCommitHandle
s as arguments? The branch args are getting converted into these anyways.
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.
Thanks @rcorre - GitAnnotatedCommitHandle is a lower level concept between lg2# and lg2 - it does not get exposed on the lg2# API. I agree with the idea that the API should be more flexible in the inputs it accepts (this is one of the items I had called out in my To Think About section in the PR description).
03a04d8
to
339a9c7
Compare
Rebased this PR. Ah, the irony... |
|
||
using (ThreadAffinity()) | ||
{ | ||
int result = NativeMethods.git_rebase_abort(rebase); |
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.
Shouldn't we Ensure
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.
We now Ensure
the result - thanks for pointing this out!
@Therzok I have some changes for moving more of the code into using the |
❤️ |
|
||
// Verify the chain of commits that resulted from the rebase. | ||
Commit expectedParent = expectedOntoCommit; | ||
foreach(CompletedRebaseStepInfo stepInfo in PostRebaseResults) |
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.
Nit: missing spaaaaace.
/// <summary> | ||
/// Command to execute, if any. | ||
/// </summary> | ||
public virtual string Exec { get; private set; } |
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.
Similarly do we need to expose this yet?
9a55a2c
to
3a03ef3
Compare
@nulltoken tests are green, rebased on top of vNext. |
@nulltoken - anything else here? 😄 |
LGTM! 🚀 🚢 🇮🇹 |
Initial Rebase implementation
@jamill 💯 |
Agreed. This is awesome - I am super excited to finally have rebase support. Oh the wonderful things we can bring to the world with this. 😃 |
Is it possible in git2sharp to rebase individual commits such as in this example http://blog.dennisrobinson.name/reorder-commits-with-git/ ? I am trying to do this in order to squash them into one commit which can then be cherrypicked. |
If you just need to squash, you'll have an easier time with:
|
Thanks for that, this is actually what I have done at the moment. However there can be additional commits mixed in that I don't want to merge which was why I was looking at rebase. Alternatively if I could cherrypick multiple commits it would avoid the need to merge them at all but it seems Git2Sharp only supports picking 1 at a time. |
I'm not sure that I understand what you mean. You can only ever cherry-pick one at a time - git (for example) will simply apply them in serial. (It doesn't create some strange multi-patch and try to apply them all at once). So you should be able to just call cherry-pick in a loop... |
Maybe referring to |
Thanks for that, I was considering using a loop but I can do However if I use |
Getting closer to completion
Includes:
Does not include:
TODO:
To Think About:
git_annotated_commit
concept in libgit2.Related issue: #714