From 22c16112dfa478605a61baee27126829c3584eb1 Mon Sep 17 00:00:00 2001 From: Richard Moore Date: Tue, 14 May 2019 21:23:27 -0400 Subject: [PATCH] Add admin support for pacakges with no history from the package gitHead. --- admin/git.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/admin/git.js b/admin/git.js index 0582ad16b..186431c64 100644 --- a/admin/git.js +++ b/admin/git.js @@ -143,10 +143,23 @@ async function getDiff(filename, tag, nameOnly) { if (tag == null) { tag = "HEAD"; } let cmd = [ "diff", "--name-only", tag, "--", filename ] if (!nameOnly) { cmd.splice(1, 1); } - let result = await git(cmd); - result = result.trim(); - if (result === "") { return [ ]; } - return result.split("\n"); + try { + let result = await git(cmd); + result = result.trim(); + if (result === "") { return [ ]; } + return result.split("\n"); + } catch (error) { + // This tag does not exist, so compare against beginning of time + // This happens when there is a new history (like an orphan branch) + if (error.stderr.trim().match(/^fatal: bad object/)) { + console.log("Could not find history; showing all"); + let cmd = [ "rev-list", "--max-parents=0", "HEAD" ]; + let tag = await git(cmd); + return getDiff(filename, tag.trim(), nameOnly); + } + + throw error; + } } async function getUntracked(filename) {