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

Cannot git_reset_default on a deleted file #2260

Closed
joshaber opened this issue Apr 9, 2014 · 6 comments
Closed

Cannot git_reset_default on a deleted file #2260

joshaber opened this issue Apr 9, 2014 · 6 comments
Labels

Comments

@joshaber
Copy link
Member

joshaber commented Apr 9, 2014

  1. Rename main.m to something else.
  2. Stage both the old and new file name.
  3. Note that git.git shows it as a rename.
  4. Call git_reset_default with the old name.
  5. Get an error:
code: -3, description: "Index does not contain main.m"
@joshaber joshaber added the bug label Apr 9, 2014
@ethomson
Copy link
Member

ethomson commented Apr 9, 2014

Eek. Is there some mechanism by which git core will support this workflow, or are you suggesting that libgit2 should be able to do better? Running rename detection during git_reset seems particularly costly.

@jspahrsummers
Copy link
Contributor

Is the error simply that staged deletions can't be reset?

@joshaber
Copy link
Member Author

joshaber commented Apr 9, 2014

@jspahrsummers Yep, I bet that's it.

git_reset_default calls git_index_conflict_remove which fails when the file name doesn't exist in the index.

@joshaber joshaber changed the title Cannot git_reset_default on a renamed file Cannot git_reset_default on a deleted file Apr 9, 2014
@arrbee
Copy link
Member

arrbee commented Apr 21, 2014

Hmm, so this is kind of an interesting case. I don't think rename detection is required for this to work correctly.

The problem is that git_reset_default runs a reversed git_diff_tree_to_index to find the changes in the index using the pathspec which actually successfully finds the deleted main.m file (as an ADDED file, because the diff is reversed), but then it unconditionally runs git_index_conflict_remove on the deleted file which fails with a GIT_ENOTFOUND because the file in question has been removed from the index.

I think the correct behavior is to ignore GIT_ENOTFOUND from git_index_conflict_remove, at least if the delta has status GIT_DELTA_ADDED (and maybe for all cases).

@carlosmn
Copy link
Member

carlosmn commented Sep 2, 2014

Did this get fixed with the PR?

@ethomson
Copy link
Member

I think #2286 fixed this, feel free to reopen if there's still a problem here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants