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

Staging a deleted file throws "Could not read file" #1042

Closed
cyanzhong opened this issue Feb 11, 2020 · 5 comments
Closed

Staging a deleted file throws "Could not read file" #1042

cyanzhong opened this issue Feb 11, 2020 · 5 comments

Comments

@cyanzhong
Copy link

Hey guys, thanks for working on this awesome project! I'm using it with Node.js, and it works pretty well.

The only confusing stuff to me is that I don't know how to add a deleted file to the staging area.

I'm trying to use git.add to accomplish this, but when the file is a deleted file (manually deleted in the file system), it throws a Could not read file "FILE NAME" exception.

Is there any way to do that? I suppose there must be something I missed, but I couldn't find it in the documentation site.

Thanks in advance.

@cyanzhong cyanzhong changed the title Staging a deleted file Staging a deleted file throws "Could not read file" Feb 11, 2020
@jcubic
Copy link
Contributor

jcubic commented Feb 11, 2020

In git Web terminal I've used this code:

if (!long_options.includes(/--cached/)) {
    git.remove({fs, dir, filepath}).then(() => fs.unlink(path_name));
} else {
    git.remove({fs, dir, filepath})
}

So you can use hack, create empty file in place of deleted file use git.remove and then unlink. Maybe git.remove should handle deleted files.

@cyanzhong
Copy link
Author

Thanks @jcubic for the workaround, I will try!

Regarding:

Maybe git.remove should handle deleted files

That sounds kind of different from my expectation, my thought is that "git.add" should handle it, because I'm "adding changes" to the staging area, no matter what the change type is (add/modify/delete)?

@billiegoose
Copy link
Member

my thought is that "git.add" should handle it, because I'm "adding changes" to the staging area, no matter what the change type is (add/modify/delete)?

Yeah. That's probably not a bad idea. Or maybe we could make two new commands and call them stage and unstage. That would be pretty intuitive.

But yes, the short answer / workaround for now is git.remove removes files from the staging area. Which is another way of saying "add a deleted file to the staging area" I suppose.

@cyanzhong
Copy link
Author

Thanks for replies! Closing as it's clear now.

@tmpmachine
Copy link
Contributor

tmpmachine commented Mar 20, 2024

I'm working on a case where I renamed a file which resulted in 1 untracked and 1 deleted file.

if (!long_options.includes(/--cached/)) {
    git.remove({fs, dir, filepath}).then(() => fs.unlink(path_name));
} else {
    git.remove({fs, dir, filepath})
}

So you can use hack, create empty file in place of deleted file use git.remove and then unlink. Maybe git.remove should handle deleted files.

It works but I'm still confused. I though git.remove() is for removing file from staging? But the new file is still in working directory, right? So, what there is to remove if the file is not even in staging? -- but okay, it's a hack.

Anyway, to add up, we can remove the deleted-and-staged file from staging by creating an empty file of the same name , add it to staging, then unlink the file. Still, a little weird, but the status matrix does match up with a local git repository.

await compoFile.TaskAddFile('style.css', '');
git.add({fs, dir:'/', filepath:'style.css'}).then(() => fs.promises.unlink('/style.css'));

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

No branches or pull requests

4 participants