UnprocessedCommitWalker: check for ZERO_ID before parsing
For a created branch commitSha1TransactionEnd is set to ZERO_ID, but
we check that first after we are trying to parse RevCommit from it.
Set transactionEnd to null if commitSha1TransactionEnd is equal to
ZERO_ID.
Solves: Jira GER-1611
Change-Id: I921752bd8140c0e8ff6e2a5829baac3e3554ccfc
diff --git a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/UnprocessedCommitsWalker.java b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/UnprocessedCommitsWalker.java
index 75e6427..aad049f 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/UnprocessedCommitsWalker.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/eventseiffel/parsing/UnprocessedCommitsWalker.java
@@ -261,9 +261,10 @@
super(eventKey, eventHub, repoManager);
checkState(eventKey.type().equals(SCS), "EventKey must have type SCS for ScsWalker.");
this.transactionEnd =
- commitSha1TransactionEnd != null
- ? rw.parseCommit(ObjectId.fromString(commitSha1TransactionEnd))
- : null;
+ (commitSha1TransactionEnd == null
+ || ObjectId.fromString(commitSha1TransactionEnd).equals(ObjectId.zeroId()))
+ ? null
+ : rw.parseCommit(ObjectId.fromString(commitSha1TransactionEnd));
this.submitter = submitter;
this.submittedAt = submittedAt;
this.hasScsEventFlag = rw.newFlag("HAS_SCS_EVENT");
@@ -295,7 +296,6 @@
}
}
if (transactionEnd != null
- && !transactionEnd.equals(ObjectId.zeroId())
&& eventHub.getExistingId(eventKey.copy(transactionEnd)).isEmpty()) {
rw.resetRetain(RevFlag.UNINTERESTING, hasScsEventFlag);
transactionEnd.remove(RevFlag.UNINTERESTING);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/listeners/GerritEventListenersIT.java b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/listeners/GerritEventListenersIT.java
index 2c14fa1..f3cede7 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/listeners/GerritEventListenersIT.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/eventseiffel/listeners/GerritEventListenersIT.java
@@ -25,6 +25,8 @@
import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.TestPlugin;
import com.google.gerrit.entities.RefNames;
+import com.google.gerrit.extensions.api.projects.BranchInfo;
+import com.google.gerrit.extensions.api.projects.BranchInput;
import com.google.gerrit.extensions.events.GitReferenceUpdatedListener;
import com.google.gerrit.extensions.events.RevisionCreatedListener;
import com.google.gerrit.extensions.registration.DynamicSet;
@@ -190,6 +192,18 @@
assertCdLinks(parentEventId, cdEvent.links);
}
+ @Test
+ public void eventsCreatedForNewbornBranch() throws Exception {
+ BranchInfo info =
+ gApi.projects().name(project.get()).branch("new-branch").create(new BranchInput()).get();
+ SourceChangeEventKey scc =
+ SourceChangeEventKey.sccKey(project.get(), "new-branch", info.revision);
+ EiffelEvent sccEvent = publisher.getPublished(scc);
+ assertNotNull("New branch should result in SCC event", sccEvent);
+ EiffelEvent scsEvent = publisher.getPublished(scc.copy(SCS));
+ assertNotNull("New branch should result in SCS event", scsEvent);
+ }
+
private PushOneCommit.Result createMetaConfigChange()
throws GitAPIException, InvalidRemoteException, TransportException, Exception {
RevCommit head = getHead(repo(), "HEAD");