tvdstaaij / node-git-describe

Git describe information at runtime, with semver support
36 stars 5 forks source link

Unable to run #3

Closed beruic closed 8 years ago

beruic commented 8 years ago

I get the following every time I try to run var gitInfo = gitDescribeSync(__dirname);. I don't know if it has any significance, but I run it in my gulppfile.js.

The error is:

/home/jmk/Projekter/cordova/node_modules/git-describe/lib/git-describe.js:101
        output.semverString = output.semver.format();
                                           ^

TypeError: Cannot read property 'format' of null
  at self.parseDescription (/home/jmk/Projekter/cordova/node_modules/git-describe/lib/git-describe.js:101:44)
  at wrapper (/home/jmk/Projekter/cordova/node_modules/git-describe/node_modules/lodash/lodash.js:4710:19)
  at self.handleProcessResult (/home/jmk/Projekter/cordova/node_modules/git-describe/lib/git-describe.js:64:18)
  at wrapper (/home/jmk/Projekter/cordova/node_modules/git-describe/node_modules/lodash/lodash.js:4710:19)
  at self.gitDescribe (/home/jmk/Projekter/cordova/node_modules/git-describe/lib/git-describe.js:49:16)
  at wrapper (/home/jmk/Projekter/cordova/node_modules/git-describe/node_modules/lodash/lodash.js:4710:19)
  at Object.<anonymous> (/home/jmk/Projekter/cordova/gulpfile.js:7:15)
  at Module._compile (module.js:409:26)
  at Object.Module._extensions..js (module.js:416:10)
  at Module.load (module.js:343:32)
  at Function.Module._load (module.js:300:12)
  at Module.require (module.js:353:17)
  at require (internal/module.js:12:17)
  at Liftoff.handleArguments (/home/jmk/.node_modules/lib/node_modules/gulp/bin/gulp.js:116:3)
  at Liftoff.<anonymous> (/home/jmk/.node_modules/lib/node_modules/gulp/node_modules/liftoff/index.js:193:16)
  at module.exports (/home/jmk/.node_modules/lib/node_modules/gulp/node_modules/liftoff/node_modules/flagged-respawn/index.js:17:3)
  at Liftoff.<anonymous> (/home/jmk/.node_modules/lib/node_modules/gulp/node_modules/liftoff/index.js:185:9)
  at /home/jmk/.node_modules/lib/node_modules/gulp/node_modules/liftoff/index.js:159:9
  at /home/jmk/.node_modules/lib/node_modules/gulp/node_modules/v8flags/index.js:108:14
  at /home/jmk/.node_modules/lib/node_modules/gulp/node_modules/v8flags/index.js:36:12
  at /home/jmk/.node_modules/lib/node_modules/gulp/node_modules/v8flags/index.js:47:7
  at nextTickCallbackWith0Args (node.js:420:9)
  at process._tickCallback (node.js:349:13)
  at Function.Module.runMain (module.js:443:11)
  at startup (node.js:139:18)
  at node.js:968:3

Update: Contextual information:

OS:     Ubuntu 16.04
NodeJS: 4.4.7 and 6.3.1
tvdstaaij commented 8 years ago

Thank you for the report. After analyzing the stack trace I believe this happens when your latest tag is not a valid semver string. Is this the case in your repository?

Running from a gulpfile is perfectly fine. Although I originally wrote this with backend (micro)services in mind, I recently used it in the gulpfile of an Ionic/Cordova project too, in order to have the git describe information available from inside the app -- pretty useful to identify the exact version someone is running.

beruic commented 8 years ago

Yes. This is the case in our repository. The version is currently v2.5-138-g2565af. Why does semver make it fail?

tvdstaaij commented 8 years ago

Semver requires a third number, v2.5.0 is valid but v2.5 is not. As for why this causes node-git-describe to fail, this is simply an oversight on my part combined with a lack of test cases. My repositories always have semver tags, so I didn't run into this issue myself, but it should also work when the tag is not a valid semver of course.

I pushed a quick fix for this issue to git and npm. I'm also planning on doing some work on code quality improvements and test cases in the near future.

beruic commented 8 years ago

It works. Thanks a bunch :)