Skip to content

Commit

Permalink
In root build.gradle change gitStatusAll task to be more tolerant of …
Browse files Browse the repository at this point in the history
…repos with no master branch
  • Loading branch information
jonesde committed Aug 4, 2023
1 parent e9e7a13 commit 2e08c17
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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::")
Expand Down

0 comments on commit 2e08c17

Please sign in to comment.