Skip to content

Move Repository.Reset(paths) into Index #959

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

Merged
merged 1 commit into from
Feb 20, 2015
Merged

Move Repository.Reset(paths) into Index #959

merged 1 commit into from
Feb 20, 2015

Conversation

bording
Copy link
Member

@bording bording commented Feb 14, 2015

Here is what I have so far. It's just about finished, but I had some questions, so I figured I'd go ahead and open the PR for changes I made for #805.

The two things I have left to do are add messages to the Obsolete attributes, and update the relevant tests so they aren't getting deprecation warnings. However, I wasn't sure which methods I should be using for the messages and the tests. Should they be pointing to the new Repository.ResetPaths() methods or to Index.Reset() instead?

To add the ResetPaths() methods I had to update the IRepository interface also. While doing this, I did start to wonder about how useful these new methods actually were vs. just calling Index.Reset() directly. Are these really needed?

Something else that I noticed while working on this is that the version of the method that takes a committish string has a couple of things I wanted to comment on.

  • First, it's using optional parameters, and I know Remove default parameters from public API #952 is talking about removing them from the public API surface. I figured that was out of scope for this PR, so I left them as is.
  • Secondly, when this method was in RepositoryExtensions it was using a private LookUpCommit() method. I changed this to use the internal Repository.LookupCommit() instead after verifying that it appeared to do the same thing.
  • Lastly, why does this version of the method have its own IsBare check vs. relying on the one that's already in the Reset() it calls? Unless looking up the commit from the committish is really expensive, it seems like there isn't a good reason for the duplicate check.

@nulltoken
Copy link
Member

First, it's using optional parameters, and I know #952 is talking about removing them from the public API surface. I figured that was out of scope for this PR, so I left them as is.

👍

To add the ResetPaths() methods I had to update the IRepository interface also. While doing this, I did start to wonder about how useful these new methods actually were vs. just calling Index.Reset() directly. Are these really needed?

That makes a lot of sense. Let's drop them from IRepository and Repository. Going one step further, as the Index is now a lower level kind of Api, I think, we should rename those Index.Reset() methods as additional overloads of Index.Replace().

/// If set, the passed <paramref name="paths"/> will be treated as explicit paths.
/// Use these options to determine how unmatched explicit paths should be handled.
/// </param>
public virtual void Reset(string committish = "HEAD", IEnumerable<string> paths = null, ExplicitPathsOptions explicitPathsOptions = null)
Copy link
Member

Choose a reason for hiding this comment

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

Let's drop this overload. Defaulting to HEAD in the Index type makes little sense, now. The user will have to pass in a previously selected commit.

Copy link
Member

Choose a reason for hiding this comment

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

This should also resolve the duplicate call to IsBare 😉

@bording
Copy link
Member Author

bording commented Feb 16, 2015

Ok, I'll go ahead and dump the Repository.ResetPaths() stuff and change the Index.Reset() methods to additional Index.Replace() overloads.

One potential issue I see with dumping the committish overload is that since it's the one with all the optional parameters, that is the overload that most of the tests are currently using. There are a lot of calls to Repository.Reset() with no arguments in the tests.

@bording
Copy link
Member Author

bording commented Feb 17, 2015

One thing I noticed while changing the Reset() methods to Replace() overloads, the existing Replace() doesn't have the IsBare check like the old Reset() does.

I couldn't see a reason why one of them would need the check and the other wouldn't, but maybe I've overlooked something?

@nulltoken
Copy link
Member

I couldn't see a reason why one of them would need the check and the other wouldn't, but maybe I've overlooked something?

You're right. It's indeed missing. Could you please add it in a separate commit?

@nulltoken
Copy link
Member

There are a lot of calls to Repository.Reset() with no arguments in the tests.

@bording I must be missing something obvious. I only find 7 calls to it in the tests. Are we talking about the same method?

@bording
Copy link
Member Author

bording commented Feb 17, 2015

That's the one I as talking about. I suppose "lots" might have been overstating things a bit, but those calls would all need to be changed to work with one of the other overloads. I guess I was just wanting to make sure you were ok with all of those calls needing to be changed before actually going through with removing the method.

@nulltoken
Copy link
Member

I suppose "lots" might have been overstating things a bit

😄

I guess I was just wanting to make sure you were ok with all of those calls needing to be changed before actually going through with removing the method.

I think repo.Reset(repo.Head.Tip) would actually be a beneficial change (in the sense that it may be more explicit to the reader with regards to what is actually done).

@bording
Copy link
Member Author

bording commented Feb 18, 2015

Getting close to having everything done!

As part of removing the committish overload, I ended up having to add a bit more logic back into the deprecated RepositoryExtensions version to make sure the tests using that one passed.

I then went through and got the tests working without any warnings, though in the process I ended up with a test that is failing. ResetANewlyInitializedNonBareRepositoryThrows() isn't seeing the expected UnbornBranchException because the call to Replace() has a null argument now.

I haven't had time yet to think about the best way to resolve that, so I figured I'd go ahead and get what I had pushed up. Would it make sense to add an IsHeadUnborn check too?

I still need to add the IsBare (and anything else that gets added to resolve the above failing test) to the other Replace() overload.

I also noticed that there is some inconsistency in the xml doc comments (Index vs. staging area). Worth taking the time to clean that up?

@nulltoken
Copy link
Member

As part of removing the committish overload, I ended up having to add a bit more logic back into
the deprecated RepositoryExtensions version to make sure the tests using that one passed.

👍

I then went through and got the tests working without any warnings, though in the process I ended
up with a test that is failing. ResetANewlyInitializedNonBareRepositoryThrows() isn't seeing the
expected UnbornBranchException because the call to Replace() has a null argument now.

Just thinking out loud. Would it make sense to actually just drop this test as there wouldn't be any way to call Replace() without a proper Commit now?

Would it make sense to add an IsHeadUnborn check too?

I'm not sure. I don't see any issue with letting a user create an unborn branch and resetting the index from an existing commit. That may actually be a way to restart a "fresh" branch and dropping the commit history. Would that make sense?

I also noticed that there is some inconsistency in the xml doc comments (Index vs. staging area).
Worth taking the time to clean that up?

That would be super nice of you!

I still need to add the IsBare (and anything else that gets added to resolve the above failing test)
to the other Replace() overload.

You're doing a fantastic job ✨ Thanks a lot ‼️

@bording
Copy link
Member Author

bording commented Feb 19, 2015

I'm not sure. I don't see any issue with letting a user create an unborn branch and resetting the index >from an existing commit. That may actually be a way to restart a "fresh" branch and dropping the >commit history. Would that make sense?

That sounds reasonable enough to me. I can't see that being used terribly often, but it seems like allowing it should be ok. It appears to be possible from the command line!

I'll go ahead and drop that test then.

@bording
Copy link
Member Author

bording commented Feb 19, 2015

So it turns out the existing Replace() didn't need to have an IsBare check added after all because the Repository.Index property getter already has the check built in! 🎉

I updated the xml docs, but let me know if there is anything in there you'd prefer that I hadn't changed, and I'll revert it. I did end up going a bit beyond just changing 'staging area' to 'Index'.

Otherwise I think this is good to go now. Let me know and I'll squash it down and rebase to current vNext!

@nulltoken
Copy link
Member

Otherwise I think this is good to go now. Let me know and I'll squash it down and rebase to current vNext!

👍

Per issue #805, the Repository.Reset() methods and extensions that take paths
have been moved to Index. These methods have become additional Index.Replace()
overloads.

The old methods have been deprecated and have been changed to call the new
Index.Replace() methods instead.

The relevant tests have been updated to use the new methods. Tests that are no
longer needed have been removed.

Closes #805
@bording
Copy link
Member Author

bording commented Feb 20, 2015

Squashed and rebased!

@nulltoken nulltoken merged commit 605b623 into libgit2:vNext Feb 20, 2015
@nulltoken
Copy link
Member

....and merged! 💖

@nulltoken
Copy link
Member

Published in prerelease NuGet package LibGit2Sharp.0.22.0-pre20150220065928.nupkg

@bording bording deleted the moveRepositoryReset branch February 21, 2015 03:04
@nulltoken nulltoken added this to the v0.22 milestone Feb 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants