question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Running `git.add` on removed file throws an error

See original GitHub issue

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.

image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

2reactions
crutchcorncommented, Jul 3, 2020

Some notes for myself, as I continue to debug this:

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:

const git = require('isomorphic-git');
const fs = require('fs');
const http = require('isomorphic-git/http/web');
const fetch = require('node-fetch');
globalThis.fetch = fetch;

const path = require('path');
const currPath = path.resolve('./')


git.remove({fs, dir: currPath, filepath: 'package.json'}).then(() => console.log("DONE"))

// Once this is ran, it stages 'package.json'

git.resetIndex({fs, dir: currPath, filepath: 'package.json'}).then(() => console.log("DONE"))

// Once this is ran, it unstages 'package.json'

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:

remove - Remove a file from the git index (aka staging area)

add - Add a file to the git index (aka staging area)

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 ?

Edit: Another note is that statusMatrix behaves perfectly when dealing with removed files being marked as staged vs unstaged. I’d argue that this advocates even further for us handling the git add edgecase in the library

1reaction
jcubiccommented, Apr 4, 2022

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).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Staging Deleted files - git - Stack Overflow
First screenshot clearly shows that 2 files are deleted and not staged, second screenshot shows that when I type git rm "~$Box.SLDASM" ,...
Read more >
Recovering Deleted Files in GitHub - Rewind Backups
Learn how to recover deleted git files with the command line, the Github desktop app or web UI, or full backups and restores....
Read more >
How to Remove Local Untracked Files in Git Working Directory
We tell Git to track files using the git add and git commit commands. ... A simple git clean command with no options...
Read more >
git-checkout Documentation - Git
Prepare to work on top of <commit> , by detaching HEAD at it (see "DETACHED HEAD" section), and updating the index and the...
Read more >
Undo possibilities in Git - GitLab Docs
Undo staged local changes · Confirm that the file is staged (that you used git add <file> ) by running git status :...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found