From 246b2baeefcc2bc22f0f9fb6d2b237e349960258 Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Fri, 8 Feb 2019 02:07:00 +0200 Subject: [PATCH] Get sourcecodeVersion and sourcecodeDate only when .git is available It might not be when installing btc-rpc-explorer globally (npm install -g). Without this, running btc-rpc-explorer without .git resulted in: fatal: Not a git repository (or any parent up to mount point /home/user) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set). Unhandled Rejection at: Promise Promise { TypeError: Cannot read property 'all' of null at btc-rpc-explorer/app.js:334:35 --- app.js | 3 ++- views/layout.pug | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 3810c89..ec7f667 100755 --- a/app.js +++ b/app.js @@ -329,8 +329,9 @@ app.runOnStartup = function() { }); } - if (global.sourcecodeVersion == null) { + if (global.sourcecodeVersion == null && fs.existsSync('.git')) { simpleGit(".").log(["-n 1"], function(err, log) { + if (err) { return console.error('error accessing git repo:', err); } global.sourcecodeVersion = log.all[0].hash.substring(0, 10); global.sourcecodeDate = log.all[0].date.substring(0, "0000-00-00".length); }); diff --git a/views/layout.pug b/views/layout.pug index abe7702..0242370 100644 --- a/views/layout.pug +++ b/views/layout.pug @@ -124,10 +124,11 @@ html(lang="en") dd a(href="https://github.com/janoside/btc-rpc-explorer") github.com/janoside/btc-rpc-explorer - dt Running Version - dd - a(href=("https://github.com/janoside/btc-rpc-explorer/commit/" + sourcecodeVersion)) #{sourcecodeVersion} - span(style="color: #ccc;") (#{sourcecodeDate}) + if (sourcecodeVersion) + dt Running Version + dd + a(href=("https://github.com/janoside/btc-rpc-explorer/commit/" + sourcecodeVersion)) #{sourcecodeVersion} + span(style="color: #ccc;") (#{sourcecodeDate}) if (config.demoSite) dt Public Demos