-
Notifications
You must be signed in to change notification settings - Fork 897
Introduce Repository.MergeCommits
#990
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
/// <param name="theirs">The second tree</param> | ||
/// <param name="options">The <see cref="MergeTreeOptions"/> controlling the merge</param> | ||
/// <returns>The <see cref="Index"/> containing the merged trees and any conflicts</returns> | ||
public Index MergeCommits(Commit ours, Commit theirs, MergeTreeOptions 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.
Couldn't we move this to repo.ObjectDatabase
?
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.
Sure. Do you like ObjectDatabase.MergeCommits
?
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.
👍
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.
However, I'm not sure about the returned parameter type. I wonder if we should return a different type (an interface?).
How would this* index behave when being added/removed anything? Does git_index_write
behave nicely?
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.
Yeah, I think so as well. Anything that hits UpdatePhysicalIndex
is going to throw. I think perhaps something that wraps an index handle but is not an index might be appropriate. I think that you want to be able to:
- Get Conflicts
- Write it to a tree
...other things?
ReadOnlyIndex
?
@nulltoken did you have any thoughts on my question(s) about what to call this interface / concrete implementation and / or what additional things it should expose? |
How about something like MergeTreeResult ObjectDatabase.MergeTree(Commit one, Commit another, MergeTreeOptions options) Where |
850ee0e
to
edc7dc0
Compare
I have updated this with some changes. |
Neat! Could you please update the commit message of |
var master = repo.Branches["master"].Tip; | ||
|
||
var result = repo.ObjectDatabase.MergeCommits(master, master, null); | ||
Assert.Equal(MergeTreeStatus.Succeeded, result.Status); |
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.
Assert.NotNull(MergeTreeStatus.Tree);
Assert.Equal(0, MergeTreeStatus.Conflicts.Count());
edc7dc0
to
d70b2e0
Compare
Updated with your suggestions, @nulltoken |
71d12e4
to
853bd94
Compare
Oops, wrote that test sloppily. Updated. |
@ethomson Thanks for this. One final nitpick. b2b6139 commit message states
Could you please reword it so that it doesn't refer to the Index any longer? |
Provide an API to merge two commits and return the result. If successful, a new tree will be written to the object database that reflects the results of the merge. If the merge had conflicts, a ConflictCollection will be provided.
Introduce a MergeOptionsBase and a MergeAndCheckoutOptionsBase so that there's less duplication of the various options that go to merge-like things.
853bd94
to
534d4e7
Compare
Yeah, I updated that sloppily. Fixed. |
Introduce `Repository.MergeCommits`
Published as NuGet pre-release package |
This introduces
Repository.MergeCommits
which wrapsgit_merge_commits
and is suitable for taking two commits and getting the merge results as anIndex
. There's a handful of interesting details here:Repository
. This meant that they always went to the repository'sIndex
. I broke this and pass in theIndex
that they're supposed to pay attention to. This is probably the least contentious change.index
needs to be freed withgit_index_free
, I madeIndex
implementIDisposable
so that consumers ofRepository.MergeCommits
can just wrap that in ausing
. To prevent anybody from trying toDispose
theRepository.Index
, I only wired upDispose
for things that came from a merge.MergeOptions
,CherryPickOptions
andRevertOptions
to share a common base class. They were getting a little copy-pastey. I also pulled out thegit_merge_options
-like things into their own base class so thatMergeTreeOptions
could also take advantage.I suspect there's going to be something in here for everybody to hate! :) Other suggestions for how to implement these things are welcome.