From 2512e906232b2beabbce0e7adb3164cfdffe04a0 Mon Sep 17 00:00:00 2001 From: Ketan Padegaonkar Date: Thu, 2 Aug 2018 12:53:21 +0530 Subject: [PATCH] Fallback to detecting latest revision if revisions-since call fails This usually happens when an attempt is made to force-push, and in the meanwhile, the flyweight folder is deleted. The plugin tends to perform a `git log last-commit..HEAD` and the `last-commit` is no longer in the git object database, thereby rendering the plugin useless. A workaround is to ask that the old commit be force-pushed (hopefully whoever pushed the old commit still has it in their reflog) --- pom.xml | 2 +- .../in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 92b5fb1..dcb12fd 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 in.ashwanthkumar gocd-github-pr-material - 1.3.4 + 1.3.5 UTF-8 diff --git a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java index 02cd59f..6b63885 100644 --- a/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java +++ b/src/main/java/in/ashwanthkumar/gocd/github/GitHubPRBuildPlugin.java @@ -311,7 +311,12 @@ GoPluginApiResponse handleLatestRevisionSince(GoPluginApiRequest goPluginApiRequ String latestSHA = newerRevisions.get(branch); if(StringUtils.isNotEmpty(lastKnownSHA)) { git.resetHard(latestSHA); - List allRevisionsSince = git.getRevisionsSince(lastKnownSHA); + List allRevisionsSince; + try { + allRevisionsSince = git.getRevisionsSince(lastKnownSHA); + } catch (Exception e) { + allRevisionsSince = Collections.singletonList(git.getLatestRevision()); + } List> changesSinceLastCommit = Lists.map(allRevisionsSince, new Function>() { @Override public Map apply(Revision revision) {