From 29441a8ae156113ebc50d8a655b3bf3a93c80db3 Mon Sep 17 00:00:00 2001 From: Robin Schneider Date: Wed, 7 Oct 2015 15:43:29 +0200 Subject: [PATCH] Get git commit hash even if the repo only points to a bare repo. * Used by https://github.com/debops/ansible-etherpad --- src/node/utils/Settings.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js index 2c2f90bf..e1825ef4 100644 --- a/src/node/utils/Settings.js +++ b/src/node/utils/Settings.js @@ -218,8 +218,14 @@ exports.getGitCommit = function() { try { var rootPath = path.resolve(npm.dir, '..'); - var ref = fs.readFileSync(rootPath + "/.git/HEAD", "utf-8"); - var refPath = rootPath + "/.git/" + ref.substring(5, ref.indexOf("\n")); + if (fs.lstatSync(rootPath + '/.git').isFile()) { + rootPath = fs.readFileSync(rootPath + '/.git', "utf8"); + rootPath = rootPath.split(' ').pop().trim(); + } else { + rootPath += '/.git'; + } + var ref = fs.readFileSync(rootPath + "/HEAD", "utf-8"); + var refPath = rootPath + "/" + ref.substring(5, ref.indexOf("\n")); version = fs.readFileSync(refPath, "utf-8"); version = version.substring(0, 7); }