From 6ba12d259c309c73abd35390a810a801f34eb330 Mon Sep 17 00:00:00 2001 From: Yannic Bonenberger Date: Wed, 8 Mar 2023 12:36:46 +0100 Subject: [PATCH] [github_pr_destination] Don't require context reference if `pr_branch` is set This will allow copybara to succeed for the following origin: ``` git.origin( url = "https://github.com/google/copybara.git", ref = "b0f6c6bbb5828c95b2b1409b4e491865d969f679", ) ``` --- .../copybara/git/GitHubPrDestination.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/java/com/google/copybara/git/GitHubPrDestination.java b/java/com/google/copybara/git/GitHubPrDestination.java index 1fac88bee..acc592ade 100644 --- a/java/com/google/copybara/git/GitHubPrDestination.java +++ b/java/com/google/copybara/git/GitHubPrDestination.java @@ -337,14 +337,18 @@ private String getPullRequestBranchName( return gitHubDestinationOptions.destinationPrBranch; } String contextReference = changeRevision.contextReference(); - // We could do more magic here with the change identity. But this is already complex so we - // require a group identity either provided by the origin or the workflow (Will be implemented - // later. - checkCondition(contextReference != null, - "git.github_pr_destination is incompatible with the current origin. Origin has to be" - + " able to provide the contextReference or use '%s' flag", - GitHubDestinationOptions.GITHUB_DESTINATION_PR_BRANCH); - String branchNameFromUser = getCustomBranchName(contextReference); + + String branchNameFromUser = prBranch; + if (branchNameFromUser == null) { + // We could do more magic here with the change identity. But this is already complex so we + // require a group identity either provided by the origin or the workflow (Will be implemented + // later. + checkCondition(contextReference != null, + "git.github_pr_destination is incompatible with the current origin. Origin has to be" + + " able to provide the contextReference or use '%s' flag", + GitHubDestinationOptions.GITHUB_DESTINATION_PR_BRANCH); + branchNameFromUser = getCustomBranchName(contextReference); + } String branchName = branchNameFromUser != null ? branchNameFromUser