Skip to content

Commit

Permalink
Forward null when parent cannot be found
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aaron-skydio committed Mar 11, 2023
1 parent f7d7714 commit 4170f79
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion java/com/google/copybara/WorkflowMode.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ <O extends Revision, D extends Revision> void run(WorkflowRunHelper<O, D> runHel
runHelper,
baseline,
runHelper.workflowOptions().baselineForMergeImport == null
? baseline.get().getOriginRevision()
? baseline.map((Baseline<O> b) -> b.getOriginRevision()).orElse(null)
: runHelper.originResolveLastRev(runHelper.workflowOptions().baselineForMergeImport));
}},
@DocField(
Expand Down

0 comments on commit 4170f79

Please sign in to comment.