Skip to content

Introduce basic merging #579

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

Closed
wants to merge 5 commits into from
Closed

Conversation

angusbjones
Copy link
Contributor

Hey not sure if this would be useful, I needed it for something I was doing and figured it could, at the least, be useful as a base for starting to get merging in. I'm not sure about how a caller should interact with the merging stuff, so I just did a mix of how I would want to use it/how similar stuff is done. Please feel free to tear me apart because I screwed up somewhere, very new to libgit2sharp + git/github.

<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a dedicated x86 target?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, a cherry-pick casualty.

@ethomson
Copy link
Member

ethomson commented Dec 5, 2013

This is very exciting to see! I'm excited to see merge in libgit2#.


repo.MergeOnto(repo.Branches["FirstBranch"].Tip);

repo.Commit("Merge First+Second");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some assertions here?

Maybe:

  • Number of parents of the merge commit
  • Ensuring the Commit.Tree contains the expected files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In. I'm thinking there should probably be some tests related to the merge result if it's felt that its necessary?

@nulltoken
Copy link
Member

@CrumblyCake Wow! Nice one!

@ethomson Thanks for jumping in, MergeMaster™ ❤️

@nulltoken
Copy link
Member

On a slightly sadder note, it looks like Travis isn't as happy as we're are.

Native stacktrace:
    /usr/bin/mono() [0x4916ba]
    /usr/bin/mono() [0x4e0d4f]
    /usr/bin/mono() [0x41bc77]
    /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0) [0x7fb12ca7fcb0]
    /home/travis/build/libgit2/libgit2sharp/libgit2/build/libgit2-98eaf39.so(git_merge+0x3d4) [0x7fb120356204]
    [0x41221333]
Debug info from gdb:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
./build.libgit2sharp.sh: line 26:  5350 Aborted                 xbuild CI-build.msbuild /t:Deploy

@ethomson
Copy link
Member

ethomson commented Dec 5, 2013

I suspect it will pass after some of the recommended signature cleanups.

On Thu, Dec 5, 2013 at 11:54 AM, nulltoken [email protected] wrote:

On a slightly sadder note, it looks like Travis isn't as happy as we're
are.

Native stacktrace:
/usr/bin/mono() [0x4916ba]
/usr/bin/mono() [0x4e0d4f]
/usr/bin/mono() [0x41bc77]
/lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0) [0x7fb12ca7fcb0]
/home/travis/build/libgit2/libgit2sharp/libgit2/build/libgit2-98eaf39.so(git_merge+0x3d4) [0x7fb120356204]
[0x41221333]

Debug info from gdb:

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries

used by your application.

./build.libgit2sharp.sh: line 26: 5350 Aborted xbuild CI-build.msbuild /t:Deploy


Reply to this email directly or view it on GitHubhttps://github.com//pull/579#issuecomment-29915021
.

@@ -1,6 +1,7 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this using necessary? if so, maybe sort it with the other System.* statements?

@dahlbyk
Copy link
Member

dahlbyk commented Dec 5, 2013

Please feel free to tear me apart

No worries there... Welcome to the party!

MergeFixture: Cleaned usings & removed unused method.
NativeMethods: Used suggested signature for git_merge.
Added ref+fetchhead git_merge_froms just in case they could be used in
future (Should I revert this, I'm not sure on your rules about unused
methods in a wrapper?)
Proxy: Split git_merge and git_merge_from_oid into separate methods and
used suggested signature. Fixed the result checking for boolean C calls
in is_uptodate and is_fastforward.
GitMergeResult: Renamed to MergeResult, put loading prop values in
constructor.
Repository: Replaced MergeOnto with Merge.
MergeResult: Fixed up bad reference + added FastForwardOid prop
Repository: Wrapped MergeHead and MergeResult handles in usings.
namespace LibGit2Sharp.Core
{
[Flags]
internal enum MergeFlags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethomson Can one combine those flags?

IOW, would GIT_MERGE_NO_FASTFORWARD | GIT_MERGE_FASTFORWARD_ONLY make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One cannot, it definitely doesn't make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But(!) my thinking is that this is a bitfield and we may have other options that could be combined later. You can't combine GIT_MERGE_NO_FASTFORWARD with GIT_MERGE_FASTFORWARD_ONLY but maybe you could combine it with something else like GIT_MERGE_DONT_WRITE_CRAPPY_METADATA_FILES or something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ethomson - This is not currently represented as a bit field in libgit2. If that is the intention of this type, should we update the libgit2 representation?

In addition, should there be a named default value (both here and in libgit2) - GIT_MERGE_DEFAULT = 0?

@nulltoken
Copy link
Member

@CrumblyCake Do you think you could also add a test putting under the light a failed merged when a conflict occur?

@ethomson Have we got actually all we need to actually resolve the merge and perform the merge commit?

@angusbjones
Copy link
Contributor Author

@nulltoken Will do for next commit, I've hit a few snags that I'll need some light shed on.
@ethomson Merging a binary file seems to actually merge the binary file (as in, <<<< Contents of first |||| Contents of second >>>>>>), should I write a test so this is replicate-able or put in an issue to the libgit2 project or what? I'm not to sure of the procedure for this scenario. Or is this expected and I have forgotten a flag to stop it?
Another issue seems to be that FastForwards don't appear to occur, the OID is generated and the flag is set in the merge result, but no changes are populated or staged, should I be calling a different method to git_merge?

Separately, while its possible (commenting on the CheckoutStrategy.GIT_CHECKOUT_USE_OURS indicates it and THEIRS are unimplemented but they work fine), the process to checkout ours/theirs on a conflict is a bit arduous when I was thinking it could just be something like CheckoutOurs(Conflict conflict) or Conflict.Ours.Checkout(). Would this be the place to put a method like this or should it be kept separate from the topic?

@ethomson
Copy link
Member

Merging a binary file seems to actually merge the binary file (as in, <<<< Contents of first |||| Contents of second >>>>>>), should I write a test so this is replicate-able or put in an issue to the libgit2 project or what?

Indeed, that looks like a bug. An oversight on my part. You're welcome to file an issue in libgit2 for this, unfortunately I will not be able to take a look at this today.

Another issue seems to be that FastForwards don't appear to occur, the OID is generated and the flag is set in the merge result, but no changes are populated or staged, should I be calling a different method to git_merge?

This is the expected behavior. A fast-forward is not a merge, so we stop and tell you that you are eligible to fast-forward to that commit. At that point you just do a checkout.

Separately, while its possible (commenting on the CheckoutStrategy.GIT_CHECKOUT_USE_OURS indicates it and THEIRS are unimplemented but they work fine), the process to checkout ours/theirs on a conflict is a bit arduous

I'm not certain, to be honest; @nulltoken would have a better sense of how you should identify a path to checkout and specify which version of a file to checkout.

@@ -1,5 +1,5 @@
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using LibGit2Sharp.Tests.TestHelpers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small style point: Normally, we have sorted the System using directives above all other directives. This default sorting behavior has changed in Visual Studio 2013.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, it just looks wrong to have System anywhere but sorted first. :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - at least there is a option to sort these first.

Put an implicit fast forward into the Merge method in Repository.cs,
cleaned up usings/comments, removed GitMergeHead and made other
suggested changes from github.
/// </summary>
/// <param name="commit">The commit to use as a reference for the changes that should be merged into HEAD.</param>
/// <returns>The result of the performed merge <see cref="MergeResult"/>.</returns>
public MergeResult Merge(Commit commit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about I would expect this method to return... If this method is going to handle the committing of the merge, then maybe callers of this method would only be interested in what happened as a result of this method call - for instance, maybe returning an enum type with possible values such as of UpToDate, NormalMerge, FastForwardMerge, and Conflict would be sufficient. Maybe there are other use cases as well...

At some point, I can see this method getting a MergeOptions parameter as well, to control behaviors such as the type of acceptable merges (Normal only, Fast Forward only), whether to actually commit the merge or not, etc... Not needed at this time, but might be nice in the future.

@jamill
Copy link
Member

jamill commented Dec 27, 2013

I think these changes are looking good, and I am very excited for this functionality to be included in LibGit2Sharp as well! Thanks!

namespace LibGit2Sharp.Core
{
[Flags]
internal enum MergeTreeFlags
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Most of the enums are of the form Git* (i.e. GitMergeTreeFlags) (although there are a couple of exceptions to this pattern).

@jamill
Copy link
Member

jamill commented Jan 8, 2014

@CrumblyCake - I have been thinking about merge a bit more and made a commit to capture some of my thoughts and things I wanted to try out at: e2523bb. How do you feel about the direction of those changes?

That series of commits were also rebased on top of latest vNext, in order to get some "fixes" for tests that have recently started to fail.

/cc @nulltoken

@nulltoken
Copy link
Member

@jamill Wow! Thanks a lot for giving a hand here!

@CrumblyCake How do you feel about @jamill's proposed changes?

@nulltoken
Copy link
Member

@ethomson Could you please glance at @jamill's spike, my dearest MergeMaster™?

@angusbjones
Copy link
Contributor Author

@jamill & @nulltoken -
I feel very good about them, everything looks to be a lot more readable as well as fitting better with the library, it also looks as if you cleared all the points you raised @jamill so thanks for that ;)
I'm sorry I didn't get to them sooner, my last 1.5 weeks have been a bit more eventful than my usual. There doesn't seem to be any branch against this commit, is there a way I can merge it so your indicated as the author?
The one thing I'd bring up is I liked your point at #579 (comment) (about checking if there is an operation running) and it doesn't appear to be in this commit, I understand why as there hasn't been a response to the comment yet so I figured I'd mention it again just in case it was missed? @ethomson @nulltoken

@jamill jamill mentioned this pull request Jan 15, 2014
@nulltoken
Copy link
Member

Closed as #608 has been merged

@nulltoken nulltoken closed this Jan 16, 2014
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.

7 participants