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

Checkout options for conflicts #3296

Merged
merged 3 commits into from
Oct 3, 2018
Merged

Conversation

bk2204
Copy link
Member

@bk2204 bk2204 commented Oct 1, 2018

When there's a conflict, it can be difficult to access the various stages of the conflict to view in a suitable diff tool. Add the --base, --ours, and --theirs options to allow checking out the various stages of a conflict into different paths for easier comparison with various tools.

This fixes #3258.

@bk2204 bk2204 added the review label Oct 1, 2018
Copy link
Contributor

@ttaylorr ttaylorr left a comment

Choose a reason for hiding this comment

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

Hey, @bk2204 -- this is looking great. I think that the code is all very good, but I left a few higher level points for your consideration below:

singleCheckout.Close()
}

func whichCheckout() (stage int, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about returning a named version of int, perhaps like:

type CheckoutStage int

const (
        CheckoutStageUnknown CheckoutStage = iota
        CheckoutStageBase
        CheckoutStageOurs
        CheckoutStageTheirs
)

Potentially this could type definition could also go in package git. It looks like there is a facility from cobra that provides us a way to do this sort of "assign a value to this location in memory based not on its type" via func Var(). I think we'd have to definite an implementation of type Value interface, but that seems doable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that would be nicer. I was looking for something like Var().

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I don't think Var does what we want. I remember looking at it, and now that I'm looking again, it seems to require an argument, which we aren't passing in this case. What we really need is a flag type that sets a variable to have a specific value, which I don't think cobra has.

commands/pull.go Outdated
// RunToPath checks out the pointer specified by p to the given path and returns
// a boolean indicating whether it was successful. It does not perform any sort
// of sanity checking or add the path to the index.
func (c *singleCheckout) RunToPath(p *lfs.WrappedPointer, path string) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if as a preparatory patch (or series) you might want to change the return type from bool to error. It may not be wise, since I believe that the implementation below already handles the error (i.e., sends the appropriate pkt-line, or similar), but I'm not sure.

It might be useful for callers to have the information, anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

This commit is new, so I can make it error instead of bool. The only reason I had to make it not return nothing is because we need to return early in Run in certain cases.


## DESCRIPTION

This command is deprecated, and should be replaced with `git checkout`.
This command is deprecated when used without `--to`, and should be replaced with
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it makes sense to continue to mark this command as deprecated in this case? I'm also not immediately sure what the behavior of git checkout is when given a --{ours,theirs,base} flag, and whether or not upstream runs the process filter.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I wasn't really sure how to go about that deprecation notice. Removing it is fine with me.

bk2204 added 3 commits October 2, 2018 13:57
Git can store multiple different versions of a file in the index.
Normally, index stage 0 is the only version provided, but if there's a
conflict, there can be three additional stages.  Since we'll be working
with these stages in a future commit, add constants for them to the git
package.
When there's a conflict with a file in Git LFS, it's difficult to get
the LFS contents of the conflicted files so that they can be run through
an appropriate diff tool.  To make this easier, teach git lfs checkout
the --base, --theirs, and --ours flags to check out the base, theirs,
and ours outputs to a given path (specified with --to).

Be sure not to print a deprecation message in this case, since this is
not a deprecated use.

Note that we use three different variables for the base, theirs, and
ours flags because Cobra doesn't offer a command mode option that can
parse all of the flags into one variable.
Document the --to, --base, --ours, and --theirs options to git lfs
checkout.  Since we're adding new functionality that isn't available by
other means, stop saying the command is deprecated.
@bk2204 bk2204 force-pushed the checkout-conflict branch from d52a27e to 35ba22d Compare October 2, 2018 15:22
Copy link
Contributor

@ttaylorr ttaylorr left a comment

Choose a reason for hiding this comment

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

Thanks for looking at my feedback! I think that this is ready to go.

@bk2204 bk2204 merged commit b8f9b11 into git-lfs:master Oct 3, 2018
@bk2204 bk2204 deleted the checkout-conflict branch October 3, 2018 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: teach 'git lfs checkout' --{theirs,ours,base}
2 participants