Index.Remove option to remove only from index but not from disk #270

Closed
yishaigalatzer opened this Issue Dec 11, 2012 · 8 comments

Comments

Projects
None yet
4 participants

Say the user added a file and committed it by mistake, he then wants to .gitignore it, and remove from index without actually removing the file from disk.

In Command Line I can do git rm -cached.

The only way I found to do it in libgit2sharp is to remove->commit->add the file back manually.

Any suggestions?

Member

jamill commented Dec 11, 2012

Would Index.Unstage(List<sting> paths) work here? That should remove the changes from the index while preserving the copy in the working directory.

The scenario is a bit different.

Imagine I did the first commit, mistakenly checking in all the files in the folder, before setting up .gitignore for the first time.

I now want to remove some files and folders from the index, but not delete them as they might be useful and needed. Git command line has this "git rm -cache" that is just removing from the index and not touching the files on disk.

The equivalent in current libgit2sharp will be to implement something like:
Copy file somewhere
stage for delete (index.remove)
commit
copy/move the files back

Member

nulltoken commented Dec 11, 2012

@yishaigalatzer @jamill

How about

  • Renaming the DiffTargets type to Targets and updating its doc it make it a more general purpose type
  • Changing the Index.Remove() signature and making it accept an optional Targets parameter?
Member

dahlbyk commented Dec 11, 2012

How about a bool indexOnly parameter? There are only three target combinations:

  1. Index + WD = default
  2. Index only = requested feature
  3. WD only = file system operation, not a git operation

We really just need to differentiate between 1 and 2...

Both suggestions are discoverable, I like the bool approach if there is never an expectation to ever support more options.

Member

nulltoken commented Dec 11, 2012

We really just need to differentiate between 1 and 2...

@dahlbyk You're right! How about rather exposing a removeFromWorkingDirectory bool instead?

public virtual void Remove(IEnumerable<string> paths, bool removeFromWorkingDirectory = true)
{
    // ....
}

I like the bool approach if there is never an expectation to ever support more options.

@yishaigalatzer I think @dahlbyk's analysis is pretty sound.

I general you should avoid default parameters on public APIs if possible. But I like the approach otherwise

Member

dahlbyk commented Dec 12, 2012

I general you should avoid default parameters on public APIs if possible.

See discussion: #223 (comment)

yorah added a commit to yorah/libgit2sharp that referenced this issue Apr 18, 2013

@yorah yorah referenced this issue Apr 18, 2013

Closed

Add a bunch of stuffs to Index.Remove() #398

4 of 4 tasks complete

yorah added a commit to yorah/libgit2sharp that referenced this issue Apr 19, 2013

yorah added a commit to yorah/libgit2sharp that referenced this issue Apr 22, 2013

yorah added a commit to yorah/libgit2sharp that referenced this issue Apr 23, 2013

yorah added a commit to yorah/libgit2sharp that referenced this issue Apr 23, 2013

@nulltoken nulltoken closed this in bdf2418 Apr 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment