@@ -239,7 +239,6 @@ List<string> DirectoryCopy(string sourceDirName, string destDirName, string[] fo
239
239
}
240
240
}
241
241
242
-
243
242
public void CopyBackChanges ( )
244
243
{
245
244
//Swapped from forward copy. Other logic can stay the same.
@@ -298,6 +297,7 @@ void DirectoryCopy(string sourceDirName, string destDirName)
298
297
}
299
298
}
300
299
}
300
+
301
301
public void CancelUpdate ( )
302
302
{
303
303
if ( _inProgress ) _cancellationPending = true ;
@@ -324,7 +324,6 @@ public bool LastOperationSuccess
324
324
}
325
325
}
326
326
327
-
328
327
public bool CancellationPending
329
328
{
330
329
get
@@ -380,13 +379,13 @@ private void UpdateTask(object stateInfo)
380
379
381
380
FetchOptions fetchOptions = new FetchOptions ( )
382
381
{
383
- TagFetchMode = TagFetchMode . All ,
382
+ /* TagFetchMode = TagFetchMode.All,
384
383
OnTransferProgress = new LibGit2Sharp.Handlers.TransferProgressHandler((progress) =>
385
384
{
386
385
_progressQueue.Enqueue(new Progress(((float)progress.ReceivedObjects) / progress.TotalObjects, "Fetching " + progress.ReceivedObjects + "/" + progress.TotalObjects + "(" + progress.ReceivedBytes + " bytes )"));
387
386
388
387
return _cancellationPending;
389
- } ) ,
388
+ }),*/
390
389
CredentialsProvider = ( credsUrl , user , supportedCredentials ) =>
391
390
{
392
391
state . CredentialManager . GetCredentials ( credsUrl , user , supportedCredentials , out var credentials , out string message ) ;
@@ -401,10 +400,10 @@ private void UpdateTask(object stateInfo)
401
400
//Repo exists we are doing a pull
402
401
using ( var repo = new LibGit2Sharp . Repository ( state . LocalDestination ) )
403
402
{
404
- _progressQueue . Enqueue ( new Progress ( 0 , "Nuking local changes. Checking out " + state . Branch ) ) ;
403
+ // _progressQueue.Enqueue(new Progress(0, "Nuking local changes. Checking out " + state.Branch));
405
404
406
- Branch branch = repo . Branches [ state . Branch ] ;
407
- Commands . Checkout ( repo , branch , new CheckoutOptions ( ) { CheckoutModifiers = CheckoutModifiers . Force , CheckoutNotifyFlags = CheckoutNotifyFlags . None } ) ;
405
+ // Branch branch = repo.Branches[state.Branch];
406
+ // Commands.Checkout(repo, branch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force, CheckoutNotifyFlags = CheckoutNotifyFlags.None});
408
407
409
408
// Credential information to fetch
410
409
PullOptions options = new PullOptions
@@ -414,7 +413,7 @@ private void UpdateTask(object stateInfo)
414
413
415
414
// User information to create a merge commit. Should not happen as we force checkout before pulling.
416
415
var signature = new LibGit2Sharp . Signature (
417
- new Identity ( "MergeNotAllowed " , "MergeNotAllowed@MergeMail .com" ) , DateTimeOffset . Now ) ;
416
+ new Identity ( "RepositoryManager " , "repositorymanager@mergemail .com" ) , DateTimeOffset . Now ) ;
418
417
419
418
try
420
419
{
@@ -428,6 +427,37 @@ private void UpdateTask(object stateInfo)
428
427
_progressQueue . Enqueue ( new Progress ( 0 , "Pull failed: " + e . Message ) ) ;
429
428
_lastOperationSuccess = false ;
430
429
}
430
+
431
+ /*try
432
+ {
433
+ var remote = repo.Network.Remotes["origin"];
434
+ var refSpecs = remote.FetchRefSpecs.Select(x => x.Specification);
435
+
436
+ _progressQueue.Enqueue(new Progress(0, "Fetching from " + remote.Name));
437
+
438
+ Commands.Fetch(repo, remote.Name, refSpecs, fetchOptions, "");
439
+
440
+ _progressQueue.Enqueue(new Progress(1, "Complete"));
441
+
442
+ try
443
+ {
444
+ Branch branch = repo.Branches["origin/" + state.Branch];
445
+ var signature = new Signature(new Identity("RepositoryManager", "Repositorymanager@Mergemail.com"), DateTimeOffset.Now);
446
+ repo.Merge(branch, signature);
447
+
448
+ _lastOperationSuccess = true;
449
+ }
450
+ catch (Exception e)
451
+ {
452
+ _progressQueue.Enqueue(new Progress(0, "Merge failed: " + e.Message));
453
+ _lastOperationSuccess = false;
454
+ }
455
+ }
456
+ catch (Exception e)
457
+ {
458
+ _progressQueue.Enqueue(new Progress(0, "Fetch failed: " + e.Message));
459
+ _lastOperationSuccess = false;
460
+ }*/
431
461
}
432
462
}
433
463
else
@@ -471,6 +501,20 @@ private void UpdateTask(object stateInfo)
471
501
}
472
502
}
473
503
504
+ if ( LastOperationSuccess )
505
+ {
506
+ _progressQueue . Enqueue ( new Progress ( 1 , "Downloading LFS files" ) ) ;
507
+ try
508
+ {
509
+ InstallAndPullLFS ( state . LocalDestination ) ;
510
+ }
511
+ catch ( Exception e )
512
+ {
513
+ _progressQueue . Enqueue ( new Progress ( 0 , "LFS Pull failed: " + e . Message ) ) ;
514
+ _lastOperationSuccess = false ;
515
+ }
516
+ }
517
+
474
518
//Once completed
475
519
_inProgress = false ;
476
520
_cancellationPending = false ;
@@ -486,5 +530,52 @@ public void OpenRepositoryDestination()
486
530
} ) ;
487
531
//Leave the process running. User should close it manually.
488
532
}
533
+
534
+ public void InstallAndPullLFS ( string path )
535
+ {
536
+ //Install lfs
537
+ ProcessStartInfo installStartInfo = new ProcessStartInfo
538
+ {
539
+ FileName = "git-lfs" ,
540
+ Arguments = "install" ,
541
+ WorkingDirectory = path ,
542
+ UseShellExecute = false ,
543
+ WindowStyle = ProcessWindowStyle . Hidden ,
544
+ CreateNoWindow = true ,
545
+ RedirectStandardInput = true ,
546
+ RedirectStandardOutput = true ,
547
+ RedirectStandardError = true
548
+ } ;
549
+
550
+ Process installProcess = new Process
551
+ {
552
+ StartInfo = installStartInfo
553
+ } ;
554
+
555
+ installProcess . Start ( ) ;
556
+ installProcess . WaitForExit ( ) ;
557
+
558
+ //Now pull lfs
559
+ ProcessStartInfo pullStartInfo = new ProcessStartInfo
560
+ {
561
+ FileName = "git-lfs" ,
562
+ Arguments = "pull" ,
563
+ WorkingDirectory = path ,
564
+ UseShellExecute = false ,
565
+ WindowStyle = ProcessWindowStyle . Hidden ,
566
+ CreateNoWindow = true ,
567
+ RedirectStandardInput = true ,
568
+ RedirectStandardOutput = true ,
569
+ RedirectStandardError = true
570
+ } ;
571
+
572
+ Process pullProcess = new Process
573
+ {
574
+ StartInfo = pullStartInfo
575
+ } ;
576
+
577
+ pullProcess . Start ( ) ;
578
+ pullProcess . WaitForExit ( ) ;
579
+ }
489
580
}
490
581
}
0 commit comments