Skip to content
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

Add Cherry-pick and Revert functionality to ObjectDatabase #1323

Merged

Conversation

@jkoritzinsky
Copy link

@jkoritzinsky jkoritzinsky commented May 31, 2016

This PR adds support for cherry-picking and reverting commits using the *_commit functions from libgit2 to allow cherry picking and reverting on a bare repository.

/// </summary>
public virtual MergeTreeStatus Status { get; private set; }
}
}

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

nit: can we end files with a trailing newline


namespace LibGit2Sharp
{
public class RevertTreeResult

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

Could you add a class comments for public classes?

}

/// <summary>
/// The resulting tree of the cherry-pick.

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

I think these comments have some left over text from the cherry-pick version :) Would you mind just updating them to refer to the revert action?

bool earlyStop;

using (var ourHandle = Proxy.git_object_lookup(repo.Handle, ours.Id, GitObjectType.Commit))
using (var cherryPickCommitHandle = Proxy.git_object_lookup(repo.Handle, revertCommit.Id, GitObjectType.Commit))

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

leftover variable name from cherryPick?

/// <param name="mainline">Which commit to consider the parent for the diff when cherry-picking a merge commit.</param>
/// <param name="options">The options for the merging in the cherry-pick operation.</param>
/// <returns>A result containing a <see cref="Tree"/> if the cherry-pick was successful and a list of <see cref="Conflict"/>s if it is not.</returns>
public virtual CherryPickTreeResult CherryPickCommit(Commit cherryPickCommit, Commit ours, int mainline, MergeOptions options)

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

Does ours work for cherry-pick? What would you think of cherryPickOnto instead of ours?

@@ -393,4 +395,4 @@
</Target>
-->
<ItemGroup />
</Project>
</Project>

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

A bit harder for generated files - but instead of fighting about the trailing newline, could you go back and add it here?

public void CanRevertInObjectDatabase()
{
// The branch name to perform the revert on,
// and the file whose contents we expect to be reverted.

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

Is the comment about the file still relevant?



// Checkout the revert branch.
Branch branch = Commands.Checkout(repo, revertBranchName);

This comment has been minimized.

@jamill

jamill Jun 1, 2016
Member

Do we need to checkout the branch in order to do this revert?

This comment has been minimized.

@jkoritzinsky

jkoritzinsky Jun 1, 2016
Author

We need to either checkout and do the revert on the checked out branch or generate a commit from the resulting tree after the first revert and apply that before the second revert. The code is much cleaner to check out the branch to perform the first revert on.

@jamill
Copy link
Member

@jamill jamill commented Jun 1, 2016

I think it would be better if both RevertTreeResult and CherryPickTreeResult contained a consistent status property... Either both use the MergeTreeStatus, or both use RevertTreeStatus and CherryPickTreeStatus respectively... (I think I would opt for the former? as I think the set of possibilities are the same?)

@jamill
Copy link
Member

@jamill jamill commented Jun 1, 2016

Thank you @jkoritzinsky for this very nice PR!

@ethomson
Copy link
Member

@ethomson ethomson commented Jun 28, 2016

This looks really good to me. One question: do we need separate *TreeResult classes? It seems like either we should use a single class for this, or that these should inherit from a base class.

@jkoritzinsky
Copy link
Author

@jkoritzinsky jkoritzinsky commented Jun 29, 2016

We can use a single class, but I am having trouble coming up with a good name. Do you have any suggestions?

@ethomson
Copy link
Member

@ethomson ethomson commented Jun 29, 2016

I, personally, would be okay with using MergeTreeResult, either completely, or just as the base class. But I can understand that this is perhaps a bit of a leaky abstraction. (It's not necessarily obvious that a cherry-pick or a revert is really a funny merge.)

@jamill
Copy link
Member

@jamill jamill commented Jun 29, 2016

I, personally, would be okay with using MergeTreeResult

👍

@jkoritzinsky
Copy link
Author

@jkoritzinsky jkoritzinsky commented Jun 29, 2016

I also like MergeTreeResult. I'll go change it to that.

@ethomson
Copy link
Member

@ethomson ethomson commented Jul 5, 2016

Great! Can you squash this and I'll merge it? Thanks!

… object database.

Added support for revert in a bare repository.

Updated CanRevertInObjectDatabase to not use a checkout and to just use commit refs.

Changed methods to use `MergeTreeResult` and fixed incorrect name in argument validation.
@jkoritzinsky jkoritzinsky force-pushed the jkoritzinsky:CherryPick-Revert-BareRepository branch from 9e324d7 to d59c673 Jul 5, 2016
@jkoritzinsky
Copy link
Author

@jkoritzinsky jkoritzinsky commented Jul 5, 2016

Squashed!

@ethomson ethomson merged commit 3b99abf into libgit2:master Jul 6, 2016
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.