christkv/node-git

Error with Repo.add: pathspec '*' did not match any files.

Closed this issue · 2 comments

Hello,

I am currently running an application in a folder with a subfolder called _docs, which is a git repository. I have ./_docs/.git open as a Repo with a file called test.md in ./_docs. I'm trying to run the following code from the current working directory (.):

new git.Repo('./_docs/.git', {}, function(err, repo) {
    repo.add('test.md', function(err){
        console.log(err);
    });
});

I get the following error:

Error: Command failed: fatal: pathspec 'test.md' did not match any files

This is the git command that gets run:

git --git-dir="....\_docs\.git" add "test.md"

I believe that you need to add the --work-tree parameter when doing git add using --git-dir (see http://stackoverflow.com/questions/1386291/git-git-dir-not-working-as-expected for more info)., but there is currently no way to pass this argument. There's no way to pass in the --work-tree argument using Git.prototype.call_git. A hack would be to pass in the --work-tree though the command arg but you replace all underscores with dashes.

Any chance there is another way to do this?

Hi,

An another solution could be to use the JS implementation from GitIndex (lib/git/git_index) and add to the index a file from a buffer, but I think it's more designed for a bare repository and your modifications looks legit.

Vincent

This can be fixed with Pull Request #32 by passing --work-tree as an argument to the git binary.