@@ -195,7 +195,8 @@ public static class WriterImpl<S extends WriterState>
195
195
implements Writer <GitRevision > {
196
196
197
197
final boolean skipPush ;
198
- private final String repoUrl ;
198
+ private final String fetchRepoUrl ;
199
+ private final String pushRepoUrl ;
199
200
private final String remoteFetch ;
200
201
private final String remotePush ;
201
202
@ Nullable private final String tagNameTemplate ;
@@ -218,18 +219,75 @@ public static class WriterImpl<S extends WriterState>
218
219
private final int visitChangePageSize ;
219
220
private final boolean gitTagOverwrite ;
220
221
221
- /**
222
- * Create a new git.destination writer
223
- */
224
- WriterImpl (boolean skipPush , String repoUrl , String remoteFetch ,
225
- String remotePush , String tagNameTemplate , String tagMsgTemplate ,
226
- GeneralOptions generalOptions , WriteHook writeHook , S state ,
227
- boolean nonFastForwardPush , Iterable <GitIntegrateChanges > integrates ,
228
- boolean lastRevFirstParent , boolean ignoreIntegrationErrors , String localRepoPath ,
229
- String committerName , String committerEmail , boolean rebase , int visitChangePageSize ,
222
+ @ Deprecated
223
+ WriterImpl (
224
+ boolean skipPush ,
225
+ String repoUrl ,
226
+ String remoteFetch ,
227
+ String remotePush ,
228
+ String tagNameTemplate ,
229
+ String tagMsgTemplate ,
230
+ GeneralOptions generalOptions ,
231
+ WriteHook writeHook ,
232
+ S state ,
233
+ boolean nonFastForwardPush ,
234
+ Iterable <GitIntegrateChanges > integrates ,
235
+ boolean lastRevFirstParent ,
236
+ boolean ignoreIntegrationErrors ,
237
+ String localRepoPath ,
238
+ String committerName ,
239
+ String committerEmail ,
240
+ boolean rebase ,
241
+ int visitChangePageSize ,
242
+ boolean gitTagOverwrite ) {
243
+ this (
244
+ skipPush ,
245
+ repoUrl ,
246
+ repoUrl ,
247
+ remoteFetch ,
248
+ remotePush ,
249
+ tagNameTemplate ,
250
+ tagMsgTemplate ,
251
+ generalOptions ,
252
+ writeHook ,
253
+ state ,
254
+ nonFastForwardPush ,
255
+ integrates ,
256
+ lastRevFirstParent ,
257
+ ignoreIntegrationErrors ,
258
+ localRepoPath ,
259
+ committerName ,
260
+ committerEmail ,
261
+ rebase ,
262
+ visitChangePageSize ,
263
+ gitTagOverwrite );
264
+ }
265
+
266
+ /** Create a new git.destination writer */
267
+ WriterImpl (
268
+ boolean skipPush ,
269
+ String fetchRepoUrl ,
270
+ String pushRepoUrl ,
271
+ String remoteFetch ,
272
+ String remotePush ,
273
+ String tagNameTemplate ,
274
+ String tagMsgTemplate ,
275
+ GeneralOptions generalOptions ,
276
+ WriteHook writeHook ,
277
+ S state ,
278
+ boolean nonFastForwardPush ,
279
+ Iterable <GitIntegrateChanges > integrates ,
280
+ boolean lastRevFirstParent ,
281
+ boolean ignoreIntegrationErrors ,
282
+ String localRepoPath ,
283
+ String committerName ,
284
+ String committerEmail ,
285
+ boolean rebase ,
286
+ int visitChangePageSize ,
230
287
boolean gitTagOverwrite ) {
231
288
this .skipPush = skipPush ;
232
- this .repoUrl = checkNotNull (repoUrl );
289
+ this .fetchRepoUrl = checkNotNull (fetchRepoUrl );
290
+ this .pushRepoUrl = checkNotNull (pushRepoUrl );
233
291
this .remoteFetch = checkNotNull (remoteFetch );
234
292
this .remotePush = checkNotNull (remotePush );
235
293
this .tagNameTemplate = tagNameTemplate ;
@@ -251,6 +309,16 @@ public static class WriterImpl<S extends WriterState>
251
309
this .gitTagOverwrite = gitTagOverwrite ;
252
310
}
253
311
312
+ @ VisibleForTesting
313
+ String getFetchRepoUrl () {
314
+ return fetchRepoUrl ;
315
+ }
316
+
317
+ @ VisibleForTesting
318
+ String getPushRepoUrl () {
319
+ return pushRepoUrl ;
320
+ }
321
+
254
322
@ Override
255
323
public void visitChanges (@ Nullable GitRevision start , ChangesVisitor visitor )
256
324
throws RepoException , ValidationException {
@@ -284,7 +352,7 @@ public void visitChanges(@Nullable GitRevision start, ChangesVisitor visitor)
284
352
private void fetchIfNeeded (GitRepository repo , Console console )
285
353
throws RepoException , ValidationException {
286
354
if (!state .alreadyFetched ) {
287
- GitRevision revision = fetchFromRemote (console , repo , repoUrl , remoteFetch );
355
+ GitRevision revision = fetchFromRemote (console , repo , getFetchRepoUrl () , remoteFetch );
288
356
if (revision != null ) {
289
357
repo .simpleCommand ("branch" , state .localBranch , revision .getSha1 ());
290
358
}
@@ -343,8 +411,10 @@ private GitRevision getLocalBranchRevision(GitRepository gitRepository) throws R
343
411
if (force ) {
344
412
return null ;
345
413
}
346
- throw new RepoException (String .format ("Could not find %s in %s and '%s' was not used" ,
347
- remoteFetch , repoUrl , GeneralOptions .FORCE ));
414
+ throw new RepoException (
415
+ String .format (
416
+ "Could not find %s in %s and '%s' was not used" ,
417
+ remoteFetch , getFetchRepoUrl (), GeneralOptions .FORCE ));
348
418
}
349
419
}
350
420
@@ -436,7 +506,8 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
436
506
Glob destinationFiles , Console console )
437
507
throws ValidationException , RepoException , IOException {
438
508
logger .atInfo ().log (
439
- "Exporting from %s to: url=%s ref=%s" , transformResult .getPath (), repoUrl , remotePush );
509
+ "Exporting from %s to: url=%s ref=%s" ,
510
+ transformResult .getPath (), getPushRepoUrl (), remotePush );
440
511
String baseline = transformResult .getBaseline ();
441
512
442
513
GitRepository scratchClone = getRepository (console );
@@ -450,13 +521,13 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
450
521
451
522
if (state .firstWrite ) {
452
523
String reference = baseline != null ? baseline : state .localBranch ;
453
- configForPush (getRepository (console ), repoUrl , remotePush );
524
+ configForPush (getRepository (console ), getPushRepoUrl () , remotePush );
454
525
if (!force && localBranchRevision == null ) {
455
- throw new RepoException (String . format (
456
- "Cannot checkout '%s' from '%s'. Use '%s' if the destination is a new git repo or"
457
- + " you don't care about the destination current status" , reference ,
458
- repoUrl ,
459
- GeneralOptions .FORCE ));
526
+ throw new RepoException (
527
+ String . format (
528
+ "Cannot checkout '%s' from '%s'. Use '%s' if the destination is a new git repo or"
529
+ + " you don't care about the destination current status" ,
530
+ reference , getPushRepoUrl (), GeneralOptions .FORCE ));
460
531
}
461
532
if (localBranchRevision != null ) {
462
533
scratchClone .simpleCommand ("checkout" , "-f" , "-q" , reference );
@@ -468,7 +539,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
468
539
} else if (!skipPush ) {
469
540
// Should be a no-op, but an iterative migration could take several minutes between
470
541
// migrations so lets fetch the latest first.
471
- fetchFromRemote (console , scratchClone , repoUrl , remoteFetch );
542
+ fetchFromRemote (console , scratchClone , getFetchRepoUrl () , remoteFetch );
472
543
}
473
544
474
545
PathMatcher pathMatcher = destinationFiles .relativeTo (scratchClone .getWorkTree ());
@@ -505,7 +576,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
505
576
commitMessage );
506
577
507
578
// Don't remove. Used internally in test
508
- console .verboseFmt ("Integrates for %s: %s" , repoUrl , Iterables .size (integrates ));
579
+ console .verboseFmt ("Integrates for %s: %s" , getPushRepoUrl () , Iterables .size (integrates ));
509
580
510
581
for (GitIntegrateChanges integrate : integrates ) {
511
582
integrate .run (alternate , generalOptions , messageInfo ,
@@ -562,7 +633,7 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
562
633
console .info (DiffUtil .colorize (
563
634
console , scratchClone .simpleCommand ("show" , "HEAD" ).getStdout ()));
564
635
if (!console .promptConfirmation (
565
- String .format ("Proceed with push to %s %s?" , repoUrl , remotePush ))) {
636
+ String .format ("Proceed with push to %s %s?" , getPushRepoUrl () , remotePush ))) {
566
637
console .warn ("Migration aborted by user." );
567
638
throw new ChangeRejectedException (
568
639
"User aborted execution: did not confirm diff changes." );
@@ -588,24 +659,29 @@ public ImmutableList<DestinationEffect> write(TransformResult transformResult,
588
659
new DestinationEffect .DestinationRef (head .getSha1 (), "commit" , /*url=*/ null )));
589
660
}
590
661
String push = writeHook .getPushReference (getCompleteRef (remotePush ), transformResult );
591
- console .progress (String .format ("Git Destination: Pushing to %s %s" , repoUrl , push ));
662
+ console .progress (String .format ("Git Destination: Pushing to %s %s" , getPushRepoUrl () , push ));
592
663
checkCondition (!nonFastForwardPush
593
664
|| !Objects .equals (remoteFetch , remotePush ), "non fast-forward push is only"
594
665
+ " allowed when fetch != push" );
595
666
596
- String serverResponse = generalOptions .repoTask (
597
- "push" ,
598
- () -> scratchClone .push ()
599
- .withRefspecs (repoUrl ,
600
- tagName != null
601
- ? ImmutableList .of (scratchClone .createRefSpec (
602
- (nonFastForwardPush ? "+" : "" ) + "HEAD:" + push ),
603
- scratchClone .createRefSpec ((gitTagOverwrite ? "+" : "" )
604
- + tagName ))
605
- : ImmutableList .of (scratchClone .createRefSpec (
606
- (nonFastForwardPush ? "+" : "" ) + "HEAD:" + push )))
607
- .run ()
608
- );
667
+ String serverResponse =
668
+ generalOptions .repoTask (
669
+ "push" ,
670
+ () ->
671
+ scratchClone
672
+ .push ()
673
+ .withRefspecs (
674
+ getPushRepoUrl (),
675
+ tagName != null
676
+ ? ImmutableList .of (
677
+ scratchClone .createRefSpec (
678
+ (nonFastForwardPush ? "+" : "" ) + "HEAD:" + push ),
679
+ scratchClone .createRefSpec (
680
+ (gitTagOverwrite ? "+" : "" ) + tagName ))
681
+ : ImmutableList .of (
682
+ scratchClone .createRefSpec (
683
+ (nonFastForwardPush ? "+" : "" ) + "HEAD:" + push )))
684
+ .run ());
609
685
return writeHook .afterPush (serverResponse , messageInfo , head , originChanges );
610
686
}
611
687
@@ -661,11 +737,15 @@ public GitRepository getRepository(Console console) throws RepoException, Valida
661
737
private void updateLocalBranchToBaseline (GitRepository repo , String baseline )
662
738
throws RepoException {
663
739
if (baseline != null && !repo .refExists (baseline )) {
664
- throw new RepoException ("Cannot find baseline '" + baseline
665
- + (getLocalBranchRevision (repo ) != null
666
- ? "' from fetch reference '" + remoteFetch + "'"
667
- : "' and fetch reference '" + remoteFetch + "' itself" )
668
- + " in " + repoUrl + "." );
740
+ throw new RepoException (
741
+ "Cannot find baseline '"
742
+ + baseline
743
+ + (getLocalBranchRevision (repo ) != null
744
+ ? "' from fetch reference '" + remoteFetch + "'"
745
+ : "' and fetch reference '" + remoteFetch + "' itself" )
746
+ + " in "
747
+ + getFetchRepoUrl ()
748
+ + "." );
669
749
} else if (baseline != null ) {
670
750
// Update the local branch to use the baseline
671
751
repo .simpleCommand ("update-ref" , state .localBranch , baseline );
0 commit comments