jzaefferer/commitplease

Fail softer when not a git repo/no commits in git repo

Closed this issue · 2 comments

Currently, running a global commitplease executable from a directory that has no git repository causes:

{ Error: fatal: Not a git repository (or any of the parent directories): .git

    at ChildProcess.<anonymous> (/home/alex/.nvm/versions/node/v6.1.0/lib/node_modules/commitplease/node_modules/spawnback/index.js:31:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:492:12) code: 128 }

and running it when the repository has no commits also causes:

{ Error: fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

    at ChildProcess.<anonymous> (/home/alex/.nvm/versions/node/v6.1.0/lib/node_modules/commitplease/node_modules/spawnback/index.js:31:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:850:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:492:12) code: 128 }

I think that we should safeguard those cases and make commitplease either print some kind of a warning and process.exit(0) or even process.exit(0) without any warning.

If we want warnings in this case and also warnings with the "broad" profile (idea from here #83), maybe we need some logging framework as dependency?

Running commitplease outside of a .git folder is pretty pointless. Exiting with 0 silently runs the risk that a bad setup is hard to debug. I suggest we log a harmless warning to stdout and exit with 0.

@all3fox since you filed this issue and it seems like it should be fairly easy to address: Do you want to take care of this?