Skip to content

Commit af2898c

Browse files
committed
Print context ref if available
When specifying the expected fixed ref, we should print out the context ref in the log message if it's available. Example of new message: `Not migrating ref refs/heads/master, its fixed ref 831870a15a17cca4152ffde5c8a3ebc535c68ab0 did not match the expected fixed ref 711abb4fa89be8c77717e105e61eba5c20db4d81.` BUG=380307584 PiperOrigin-RevId: 743653731 Change-Id: I3d4ca751596b8307ed27b24ca739f927c3a80d43
1 parent 48f3794 commit af2898c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

java/com/google/copybara/Workflow.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.List;
6464
import java.util.Locale;
6565
import java.util.Map;
66+
import java.util.Optional;
6667
import java.util.Set;
6768
import java.util.concurrent.Callable;
6869
import java.util.function.Consumer;
@@ -344,7 +345,9 @@ private void validateExpectedFixedRef(O resolvedRef) throws EmptyChangeException
344345
throw new EmptyChangeException(
345346
String.format(
346347
"Not migrating ref %s, its fixed ref %s did not match the expected fixed ref %s.",
347-
resolvedRef.asString(), resolvedRef.fixedReference(), expectedFixedRef));
348+
Optional.ofNullable(resolvedRef.contextReference()).orElse(resolvedRef.asString()),
349+
resolvedRef.fixedReference(),
350+
expectedFixedRef));
348351
}
349352
}
350353

javatests/com/google/copybara/WorkflowTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ public void expectedFixedRefDoesNotMatch() throws Exception {
400400
assertThat(e)
401401
.hasMessageThat()
402402
.contains(
403-
"Not migrating ref 0, its fixed ref beaver did not match the expected fixed ref"
403+
"Not migrating ref HEAD, its fixed ref beaver did not match the expected fixed ref"
404404
+ " capybara.");
405405
}
406406

0 commit comments

Comments
 (0)