Skip to content

Add possibility to merge when head is unborn (empty repository) #633

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 2 commits into from

Conversation

pmiossec
Copy link

See libgit2/libgit2#2135 for more details

cc @nulltoken

CheckoutModifiers = CheckoutModifiers.None,
};

CheckoutTree(commit.Tree, null, checkoutOpts);
Copy link
Author

Choose a reason for hiding this comment

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

I don't know if I must do a CheckoutTree() before with the CheckoutModifiers.None or after but which need a CheckoutModifiers.Force. What do you think about that?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

The Head could be unborn for a different reason: when creating a new root in the repository.
Beside this, the index and the workdir may also be populated.

I'd go with the None option to err on the safe side, but I'm not the MergeMaster™.

Copy link
Member

Choose a reason for hiding this comment

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

I read libgit2/libgit2#2135, but I am not convinced that lg2 shouldn't handle this case. Instead of all of the bindings special casing and handling the unborn head case separately (and e.g. handling the fast-forward, non-fast forward allowed merge types), it would seem cleaner if lg2 could handle these scenarios and then the bindings can just act of the return from the git_merge_from_* functions.

Copy link
Member

Choose a reason for hiding this comment

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

Which checkout options to use depends on which version of git you want to pretend you called. Older versions do a forced checkout, but that's destructive in edge cases. Newer versions will refuse to update if there are local changes to files that exist in the target commit (which are all files, by definition), which is roughly what they do on a fast-forward merge; though the error message is slightly different, suggesting that the code paths aren't quite the same.

Copy link
Member

Choose a reason for hiding this comment

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

@pmiossec So, I think this is a really good start! However, git tend to make quite difficult to overwrite local changes, and so do we.

As seen before, creating an unborn branch is quite easy (just by making the HEAD point to a non existing branch). This state doesn't mean that it's safe to blindly merge.

Considering these, I think that in this scenario, the code should:

  • Ensure the Index is empty
  • Ensure a Diff between the workdir and the commit tree doesn't report any updated entries.

Performing those checks should ensure that the user won't loose any data, while still allowing your scenario.

Copy link
Author

Choose a reason for hiding this comment

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

@nulltoken what do you think about this last change?

@jamill
Copy link
Member

jamill commented Mar 3, 2014

@pmiossec - how eager are you for this change? If we were able to update the native bindings to handle this scenario as discussed in libgit2/libgit2#2135 fairly soon, would that work for you (in the next week or so)?

@pmiossec
Copy link
Author

pmiossec commented Mar 3, 2014

I could wait. Their is really no hurry! I just saw that the merge support
was added to libgit2sharp and wanted to test it to remove calls to git
command in git-tfs...
But it works for years like that so it's OK. One week or one more is no
problem ;-)

@jamill
Copy link
Member

jamill commented Apr 3, 2014

@pmiossec I think #643 is getting closer to completion. It should satisfy the requirements that you are looking for and includes tests that we can merge into an orphaned branch.

If that PR meets your requirements, we could close this PR in favor of that one.

@pmiossec
Copy link
Author

pmiossec commented Apr 3, 2014

@jamill I will test this PR, will see if it solve my cases and will tell you...

@pmiossec
Copy link
Author

pmiossec commented Apr 3, 2014

@jamill Ok. I have tested and it works well and solve my problems....

I close!

@pmiossec pmiossec closed this Apr 3, 2014
@jamill
Copy link
Member

jamill commented Apr 3, 2014

Thanks for trying this out!

@nulltoken nulltoken added this to the UnmergedOrDoNotRequireAFix milestone Apr 3, 2014
@nulltoken
Copy link
Member

Fixed by #643

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.

4 participants