isomorphic-git: Running `git.add` on removed file throws an error
I am using the React Native example and have noticed issues with trying to run git.add
to a file that’s been removed. Instead of adding it to the staged
files that’ve been changed, I get a NotFoundError
.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 18 (17 by maintainers)
Commits related to this issue
- fix: use git add again to avoid troubles https://github.com/isomorphic-git/isomorphic-git/issues/1099#issuecomment-1087582082 — committed to tiddly-gittly/git-sync-js by linonetwo 2 years ago
Some notes for myself, as I continue to debug this:
git add package.json
totally removes it from theindex
filegit reset HEAD package.json
will unstage the deleted file without undeleting that fileindex
fileresetIndex
function inisomorphic-git
remove
function inisomorphic-git
And, sure enough… When I run the relevant commands, they act the way I would “”“expect”“” them to, now understanding the Git implementation a bit better:
So I guess here’s my question: Should this edgecase be handed by
isomorphic-git
or by the clients?The commands are techincally correct in their behavior, but the documentation for these commands infer that they would otherwise handle these edgecases:
As far as I see it, we should either update the documentation for these two commands and add a reference to this particular issue, or we should update the code for these commands and invisibly handle these edgecases. I’d be happy to make a PR to solve this problem and write tests confirming their behavior change if you’d like to go down the “handle edgecase” route. What do you think @wmhilton ?
You can see how I’ve implemented git add in my Git Web Terminal: https://github.com/jcubic/git/blob/gh-pages/js/main.js#L884
The issue with my code is that it doesn’t support
git add .
but it would be easy to add you only need to list all files like (the first branch in 889) but it should use the same code as in else that allow deleting all commands (here there is only delete a single file).But if I already delete the file using fs.delete, do I still need
git.delete({ dir, filepath: '.', fs });
to delete it?And I think since file is already deleted by 3rd party program, use a glob pattern library won’t be able to find the deleted file…
Maybe using dugite is the better choise for circumstance where file will gets deleted?
How to commit all delete-file?
This seems not able to add all deletion. Running
git add .
in terminal actually add those chagnes.@Nils-Kolvenbach you’ve convinced me that I should just open a PR instead of waiting for further discussion. It’s clear from the documentation (and our confusion) that this is a bug, not a feature.
In the meantime, you can sidestep this issue by using:
To stage a deleted file and:
To unstage a deleted file. I’m doing this for my app (https://github.com/crutchcorn/GitShark/) and it works perfectly.
I’ll make a notice when the PR is made live