Skip to content

Conversation

jamill
Copy link
Member

@jamill jamill commented Dec 5, 2012

Fix to allow unstaging adds in an empty repository. This should resolve issue #257.

/cc @phkelley, @yishaigalatzer

@arrbee
Copy link
Member

arrbee commented Dec 5, 2012

Out of curiosity, is there a (maybe optional) behavior of the underlying git_reset() API in libgit2 that you would like to see that would make this case require less code in libgit2sharp?

@nulltoken
Copy link
Member

Out of curiosity, is there a (maybe optional) behavior of the underlying git_reset() API in libgit2 that you would like to see that would make this case require less code in libgit2sharp?

Yes. I'd like this very much. However, I'd prefer to have #257 fixed first with plain C# and decide what would be the nice options we'd like to see dealt with (Current implementation blindly assumes --ignore-unmatch) and make all of this covered with tests.

Then, if that's ok with you, I'll try to port it in libgit2.

@jamill
Copy link
Member Author

jamill commented Dec 10, 2012

@nulltoken - I looked at making Index.Unstage act more strictly, but decided against it - On second thought I am not sure how useful it is to only verify the file is part of the index. With your changes, we already verify an absolute path is part of the repository.

As it is, this PR is updated to include your changes (but is still tolerent to files not part of the index).

If you think that the strict option is still useful, I can add it back

Thoughts?

@nulltoken
Copy link
Member

If you think that the strict option is still useful, I can add it back

@jamill Hmm.. While working on #270, I just (re)discovered that trying to Index.Remove() a NonExistent/Removed file was not allowed. We have to make this coherent considering all of the operations.

Is it ok to stage/unstage/remove or even move a file which doesn't exist?

I would lean toward letting the user decide about whether the operation is lenient (ie. silently ignores unmatched pathspecs).


Below a proposal for an exhaustive ruleset regarding this. Please review it carefully as I may have had made mistakes:

Staging deals with moving the state of a file from the Working Directory toward the Index

Stage File exists in Index File exists in WD Ignore unmatched pathspec Result
01 Y Y Y Version in Index is replaced with version in Workdir
02 Y Y Version in Index is created from version in Workdir
03 Y Y Version in Index is removed
04 Y Does nothing
05 Y Y Version in Index is replaced with version in Workdir
06 Y Version in Index is created from version in Workdir
07 Y Version in Index is removed
08 Throws

Unstaging deals with moving the state of a file from the Head toward the Index. If the Head is orphaned (ie. the current Head "contains" no commit), then the file will be considered as "non existing is the Head"

Unstage File exists in Index File exists in Head Ignore unmatched pathspec Result
01 Y Y Y Version in Index is replaced with version in Head
02 Y Y Version in Index is removed
03 Y Y Version in Index is replaced with version in Head
04 Y Does nothing
05 Y Y Version in Index is replaced with version in Head
06 Y Version in Index is removed
07 Y Version in Index is replaced with version in Head
08 Throws

Removing deals with clearing an entry from the Index and, optionally, from the Working Directory as well

Remove File exists in Index File exists in WD Ignore unmatched pathspec Remove from WD as well Result
01 Y Y Y Y Both entries are removed from Index and Workdir
02 Y Y Y Entry in Index is Removed
03 Y Y Y ???
04 Y Y Does nothing
05 Y Y Y Entry in Index is removed
06 Y Y Entry in Index is removed
07 Y Y ???
08 Y Does Nothing
09 Y Y Y Both entries are removed from Index and Workdir
10 Y Y ???
11 Y Y Throws
12 Y Throws
13 Y Y Entry in Index is removed
14 Y Entry in Index is removed
15 Y Throws
16 Throws

Note: I haven't dealt with Move which is slightly more complicated. I'd rather make sure the behavior Remove is settled first.

/cc @dahlbyk, @yishaigalatzer

@yishaigalatzer
Copy link

Question: What is the expectation when an end user goes through the following process

  1. Have a file in the index (previously commited)
  2. Make changes and save (lets call it it file state 1)
  3. Stage
  4. Make more changes and save (call it file state 2)
  5. Commit

I'm expecting that file state 2 is the one captured in the repository, from reading the table above i'm not 100% clear that is the case.

@ethomson
Copy link
Member

It seems clear to me.

@nulltoken
Copy link
Member

@yishaigalatzer A Commit is made of the content of the Index. Staging is the process which updates the Index from the working directory. In other words, if nothing is staged, there's nothing to commit.

Considering your scenario, below are the state of the "three trees of git" after each of the step has been performed

  1. v0 of the file exists in the working directory. v0 of the file exists in the Index. v0 of the file exists in the Head
  2. v1 of the file exists in the working directory. v0 of the file exists in the Index. v0 of the file exists in the Head
  3. v1 of the file exists in the working directory. v1 of the file exists in the Index. v0 of the file exists in the Head
  4. v2 of the file exists in the working directory. v1 of the file exists in the Index. v0 of the file exists in the Head
  5. v2 of the file exists in the working directory. v1 of the file exists in the Index. v1 of the file exists in the Head

I'm expecting that file state 2 is the one captured in the repository, from reading the table above i'm not 100% clear that is the case.

If only file state 1 has been staged, only file state 1 will be committed.

@jamill
Copy link
Member Author

jamill commented Dec 12, 2012

@nulltoken

We have to make this coherent considering all of the operations.

Yes - I missed the behavior of the other operations, I completly agree. How would you feel about handling the API consistency in a seperate issue - I can open one and bring over your table. I would like to tackle unstaging adds on an empty repository first as there is not currently another workaround here (and, the fix is available now).

/cc @dahlbyk, @yishaigalatzer , @ethomson

@nulltoken
Copy link
Member

I would like to tackle unstaging adds on an empty repository first as there is not currently another workaround here (and, the fix is available now).

Sounds reasonable 😉 It's now merged.

How would you feel about handling the API consistency in a separate issue - I can open one and bring over your table.

👍

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.

6 participants