Skip to content

Commit 4170f79

Browse files
committed
Forward null when parent cannot be found
Currently if I run a workflow where the parent commit cannot be found in the destination (with merge_import from [here](google@c54a5b9) off), I get an exception: ``` java.util.NoSuchElementException: No value present at java.base/java.util.Optional.get(Optional.java:148) at com.google.copybara.WorkflowMode$3.run(WorkflowMode.java:261) at com.google.copybara.Workflow.run(Workflow.java:288) at com.google.copybara.MigrateCmd.run(MigrateCmd.java:92) at com.google.copybara.MigrateCmd.run(MigrateCmd.java:69) at com.google.copybara.Main.runInternal(Main.java:241) at com.google.copybara.Main.run(Main.java:123) at com.google.copybara.Main.main(Main.java:102) ERROR: Unexpected error (please file a bug against copybara): No value present (java.util.NoSuchElementException: No value present) ``` I think the right thing to do here is convert the empty `Optional` to `null`? In which case I a legitimate error message instead of a crash: ``` ERROR: Cannot find matching parent commit in the destination. Use '--change-request-parent' flag to force a parent commit to use as baseline in the destination. ``` Definitely not 100% sure this fix is correct though, this is as much a bug report as it is a proposed fix. Topic: copybara-null-baseline
1 parent f7d7714 commit 4170f79

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

java/com/google/copybara/WorkflowMode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ <O extends Revision, D extends Revision> void run(WorkflowRunHelper<O, D> runHel
258258
runHelper,
259259
baseline,
260260
runHelper.workflowOptions().baselineForMergeImport == null
261-
? baseline.get().getOriginRevision()
261+
? baseline.map((Baseline<O> b) -> b.getOriginRevision()).orElse(null)
262262
: runHelper.originResolveLastRev(runHelper.workflowOptions().baselineForMergeImport));
263263
}},
264264
@DocField(

0 commit comments

Comments
 (0)