From 2e08c17a8e90ef2d2f96f1ab5950f30aa1e7f496 Mon Sep 17 00:00:00 2001 From: David E Jones Date: Fri, 4 Aug 2023 09:25:29 -0500 Subject: [PATCH] In root build.gradle change gitStatusAll task to be more tolerant of repos with no master branch --- build.gradle | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 3b591d4c6..6f522ca5b 100644 --- a/build.gradle +++ b/build.gradle @@ -421,9 +421,18 @@ task gitStatusAll { def upstreamAhead = curGrgit.log { range curGrgit.resolve.toCommit('refs/remotes/upstream/master'), curGrgit.resolve.toCommit('refs/remotes/origin/master') } if (upstreamAhead) logger.lifecycle("- origin/master ${upstreamAhead.size()} commits ahead of upstream/master") } - def unpushed = curGrgit.log { range curGrgit.resolve.toCommit('refs/remotes/origin/master'), curGrgit.resolve.toCommit('HEAD') } - if (unpushed) logger.lifecycle("--- ${unpushed.size()} commits unpushed (ahead of origin/master)") - for (Commit commit in unpushed) logger.lifecycle(" - ${commit.getAbbreviatedId(8)} - ${commit.shortMessage}") + try { + def masterLatest = curGrgit.resolve.toCommit('refs/remotes/origin/master') + if (masterLatest == null) { + logger.error("No origin/master branch exists, can't determine unpushed commits") + } else { + def unpushed = curGrgit.log { range masterLatest, curGrgit.resolve.toCommit('HEAD') } + if (unpushed) logger.lifecycle("--- ${unpushed.size()} commits unpushed (ahead of origin/master)") + for (Commit commit in unpushed) logger.lifecycle(" - ${commit.getAbbreviatedId(8)} - ${commit.shortMessage}") + } + } catch (Exception e) { + logger.error("Error finding unpushed commits", e) + } def curStatus = curGrgit.status() if (curStatus.isClean()) logger.lifecycle("* nothing to commit, working directory clean") if (curStatus.staged.added || curStatus.staged.modified || curStatus.staged.removed) logger.lifecycle("--- Changes to be committed::")