Skip to content

Commit 1a94a62

Browse files
committed
Export of internal change
1 parent ae0153a commit 1a94a62

File tree

5 files changed

+158
-67
lines changed

5 files changed

+158
-67
lines changed

docs/reference.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ version_selector | `latestVersionSelector`<br><p>Select a custom version (tag)to
21312131

21322132
Creates changes in a new pull request in the destination.
21332133

2134-
`gitHubPrDestination git.github_pr_destination(url, destination_ref="master", pr_branch=None, title=None, body=None, integrates=None, api_checker=None, update_description=False)`
2134+
`gitHubPrDestination git.github_pr_destination(url, destination_ref="master", push_to_fork=False, fork_url=None, pr_branch=None, title=None, body=None, integrates=None, api_checker=None, update_description=False)`
21352135

21362136

21372137
#### Parameters:
@@ -2140,6 +2140,8 @@ Parameter | Description
21402140
--------- | -----------
21412141
url | `string`<br><p>Url of the GitHub project. For example "https://github.com/google/copybara'"</p>
21422142
destination_ref | `string`<br><p>Destination reference for the change. By default 'master'</p>
2143+
push_to_fork | `boolean`<br><p>Indicates that the result of the change should be pushed to the current user's personal fork. The PullRequest will still be created on the upstream project.</p>
2144+
fork_url | `string`<br><p>TODO</p>
21432145
pr_branch | `string`<br><p>Customize the pull request branch. Any variable present in the message in the form of ${CONTEXT_REFERENCE} will be replaced by the corresponding stable reference (head, PR number, Gerrit change number, etc.).</p>
21442146
title | `string`<br><p>When creating (or updating if `update_description` is set) a pull request, use this title. By default it uses the change first line. This field accepts a template with labels. For example: `"Change ${CONTEXT_REFERENCE}"`</p>
21452147
body | `string`<br><p>When creating (or updating if `update_description` is set) a pull request, use this body. By default it uses the change summary. This field accepts a template with labels. For example: `"Change ${CONTEXT_REFERENCE}"`</p>

java/com/google/copybara/git/GitDestination.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ public static class WriterImpl<S extends WriterState>
195195
implements Writer<GitRevision> {
196196

197197
final boolean skipPush;
198-
private final String repoUrl;
198+
private final String fetchRepoUrl;
199+
private final String pushRepoUrl;
199200
private final String remoteFetch;
200201
private final String remotePush;
201202
@Nullable private final String tagNameTemplate;
@@ -218,18 +219,34 @@ public static class WriterImpl<S extends WriterState>
218219
private final int visitChangePageSize;
219220
private final boolean gitTagOverwrite;
220221

222+
@Deprecated
223+
WriterImpl(boolean skipPush, String repoUrl, String remoteFetch,
224+
String remotePush, String tagNameTemplate, String tagMsgTemplate,
225+
GeneralOptions generalOptions, WriteHook writeHook, S state,
226+
boolean nonFastForwardPush, Iterable<GitIntegrateChanges> integrates,
227+
boolean lastRevFirstParent, boolean ignoreIntegrationErrors, String localRepoPath,
228+
String committerName, String committerEmail, boolean rebase, int visitChangePageSize,
229+
boolean gitTagOverwrite) {
230+
this(
231+
skipPush, repoUrl, repoUrl, remoteFetch, remotePush, tagNameTemplate, tagMsgTemplate,
232+
generalOptions, writeHook, state, nonFastForwardPush, integrates, lastRevFirstParent,
233+
ignoreIntegrationErrors, localRepoPath, committerName, committerEmail, rebase,
234+
visitChangePageSize, gitTagOverwrite);
235+
}
236+
221237
/**
222238
* Create a new git.destination writer
223239
*/
224-
WriterImpl(boolean skipPush, String repoUrl, String remoteFetch,
240+
WriterImpl(boolean skipPush, String fetchRepoUrl, String pushRepoUrl, String remoteFetch,
225241
String remotePush, String tagNameTemplate, String tagMsgTemplate,
226242
GeneralOptions generalOptions, WriteHook writeHook, S state,
227243
boolean nonFastForwardPush, Iterable<GitIntegrateChanges> integrates,
228244
boolean lastRevFirstParent, boolean ignoreIntegrationErrors, String localRepoPath,
229245
String committerName, String committerEmail, boolean rebase, int visitChangePageSize,
230246
boolean gitTagOverwrite) {
231247
this.skipPush = skipPush;
232-
this.repoUrl = checkNotNull(repoUrl);
248+
this.fetchRepoUrl = checkNotNull(fetchRepoUrl);
249+
this.pushRepoUrl = checkNotNull(pushRepoUrl);
233250
this.remoteFetch = checkNotNull(remoteFetch);
234251
this.remotePush = checkNotNull(remotePush);
235252
this.tagNameTemplate = tagNameTemplate;
@@ -284,7 +301,7 @@ public void visitChanges(@Nullable GitRevision start, ChangesVisitor visitor)
284301
private void fetchIfNeeded(GitRepository repo, Console console)
285302
throws RepoException, ValidationException {
286303
if (!state.alreadyFetched) {
287-
GitRevision revision = fetchFromRemote(console, repo, repoUrl, remoteFetch);
304+
GitRevision revision = fetchFromRemote(console, repo, fetchRepoUrl, remoteFetch);
288305
if (revision != null) {
289306
repo.simpleCommand("branch", state.localBranch, revision.getSha1());
290307
}
@@ -344,7 +361,7 @@ private GitRevision getLocalBranchRevision(GitRepository gitRepository) throws R
344361
return null;
345362
}
346363
throw new RepoException(String.format("Could not find %s in %s and '%s' was not used",
347-
remoteFetch, repoUrl, GeneralOptions.FORCE));
364+
remoteFetch, fetchRepoUrl, GeneralOptions.FORCE));
348365
}
349366
}
350367

@@ -436,7 +453,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
436453
Glob destinationFiles, Console console)
437454
throws ValidationException, RepoException, IOException {
438455
logger.atInfo().log(
439-
"Exporting from %s to: url=%s ref=%s", transformResult.getPath(), repoUrl, remotePush);
456+
"Exporting from %s to: url=%s ref=%s", transformResult.getPath(), pushRepoUrl, remotePush);
440457
String baseline = transformResult.getBaseline();
441458

442459
GitRepository scratchClone = getRepository(console);
@@ -450,12 +467,12 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
450467

451468
if (state.firstWrite) {
452469
String reference = baseline != null ? baseline : state.localBranch;
453-
configForPush(getRepository(console), repoUrl, remotePush);
470+
configForPush(getRepository(console), pushRepoUrl, remotePush);
454471
if (!force && localBranchRevision == null) {
455472
throw new RepoException(String.format(
456473
"Cannot checkout '%s' from '%s'. Use '%s' if the destination is a new git repo or"
457474
+ " you don't care about the destination current status", reference,
458-
repoUrl,
475+
pushRepoUrl,
459476
GeneralOptions.FORCE));
460477
}
461478
if (localBranchRevision != null) {
@@ -468,7 +485,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
468485
} else if (!skipPush) {
469486
// Should be a no-op, but an iterative migration could take several minutes between
470487
// migrations so lets fetch the latest first.
471-
fetchFromRemote(console, scratchClone, repoUrl, remoteFetch);
488+
fetchFromRemote(console, scratchClone, fetchRepoUrl, remoteFetch);
472489
}
473490

474491
PathMatcher pathMatcher = destinationFiles.relativeTo(scratchClone.getWorkTree());
@@ -505,7 +522,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
505522
commitMessage);
506523

507524
// Don't remove. Used internally in test
508-
console.verboseFmt("Integrates for %s: %s", repoUrl, Iterables.size(integrates));
525+
console.verboseFmt("Integrates for %s: %s", pushRepoUrl, Iterables.size(integrates));
509526

510527
for (GitIntegrateChanges integrate : integrates) {
511528
integrate.run(alternate, generalOptions, messageInfo,
@@ -562,7 +579,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
562579
console.info(DiffUtil.colorize(
563580
console, scratchClone.simpleCommand("show", "HEAD").getStdout()));
564581
if (!console.promptConfirmation(
565-
String.format("Proceed with push to %s %s?", repoUrl, remotePush))) {
582+
String.format("Proceed with push to %s %s?", pushRepoUrl, remotePush))) {
566583
console.warn("Migration aborted by user.");
567584
throw new ChangeRejectedException(
568585
"User aborted execution: did not confirm diff changes.");
@@ -588,15 +605,15 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
588605
new DestinationEffect.DestinationRef(head.getSha1(), "commit", /*url=*/ null)));
589606
}
590607
String push = writeHook.getPushReference(getCompleteRef(remotePush), transformResult);
591-
console.progress(String.format("Git Destination: Pushing to %s %s", repoUrl, push));
608+
console.progress(String.format("Git Destination: Pushing to %s %s", pushRepoUrl, push));
592609
checkCondition(!nonFastForwardPush
593610
|| !Objects.equals(remoteFetch, remotePush), "non fast-forward push is only"
594611
+ " allowed when fetch != push");
595612

596613
String serverResponse = generalOptions.repoTask(
597614
"push",
598615
() -> scratchClone.push()
599-
.withRefspecs(repoUrl,
616+
.withRefspecs(pushRepoUrl,
600617
tagName != null
601618
? ImmutableList.of(scratchClone.createRefSpec(
602619
(nonFastForwardPush ? "+" : "") + "HEAD:" + push),
@@ -665,7 +682,7 @@ private void updateLocalBranchToBaseline(GitRepository repo, String baseline)
665682
+ (getLocalBranchRevision(repo) != null
666683
? "' from fetch reference '" + remoteFetch + "'"
667684
: "' and fetch reference '" + remoteFetch + "' itself")
668-
+ " in " + repoUrl + ".");
685+
+ " in " + fetchRepoUrl + ".");
669686
} else if (baseline != null) {
670687
// Update the local branch to use the baseline
671688
repo.simpleCommand("update-ref", state.localBranch, baseline);

0 commit comments

Comments
 (0)