git-rev-sync-js icon indicating copy to clipboard operation
git-rev-sync-js copied to clipboard

Use in empty git repository

Open daurnimator opened this issue 8 years ago • 6 comments

When used in an empty git repository I get:

Module build failed: Error: ENOENT: no such file or directory, open '/home/daurnimator/myproject/.git/packed-refs'
    at Object.fs.openSync (fs.js:663:18)
    at Object.fs.readFileSync (fs.js:568:33)
    at Object.long (/home/daurnimator/myproject/node_modules/git-rev-sync/index.js:109:31)

daurnimator avatar Nov 22 '17 03:11 daurnimator

yeah; that's a known issue that I haven't found a solid "fix" for yet -- do you have any ideas? if so, would you like to submit a PR?

kurttheviking avatar Feb 16 '18 05:02 kurttheviking

wrap in a try/catch and check for ENOENT?

daurnimator avatar Feb 16 '18 05:02 daurnimator

@daurnimator maybe; but what's expected? return null or an empty string?

kurttheviking avatar Feb 16 '18 06:02 kurttheviking

null I think? Probably same as if you're not in a git repository.

daurnimator avatar Feb 16 '18 23:02 daurnimator

https://github.com/NiceLabs/git-rev

Support empty-repository

septs avatar Feb 18 '20 00:02 septs

@kurttheviking I also believe this package should have a feature (or default) to return null instead of throwing the following errors (or any other error related to git not being fully initialized).

Error: [git-rev-sync] no git repository found
Error: ENOENT: no such file or directory

sunknudsen avatar Mar 15 '20 14:03 sunknudsen