Beispiel #1
0
 private void ButtonEntity(object sender, RoutedEventArgs e)
 {
     GitUnlocked = false;
     new Editor().Show();
     GitUnlocked = true;
     GitView.Refresh();
 }
Beispiel #2
0
 private void UpdateRepoDirDisplay()
 {
     Dispatcher.BeginInvoke(new Action(() =>
     {
         RepoDirDisplay.Text = RepoDir;
         GitView.Refresh();
     }));
 }
Beispiel #3
0
        private void CommitFlyoutOpenChanged(object sender, RoutedEventArgs e)
        {
            GitUnlocked = !CommitFlyout.IsOpen;

            if (GitUnlocked)
            {
                GitView.Refresh();
            }
        }
Beispiel #4
0
        private async void SyncClick(object sender, RoutedEventArgs e)
        {
            GitUnlocked = false;

            var author = Author.Load();

            if (!author.IsComplete)
            {
                AuthorInput.Reset();
                AuthorFlyout.IsOpen = true;
                return;
            }

            SyncFlyout.IsOpen = true;
            var status = SyncProgress;

            status.SetProgress(null);
            status.SetMessage("Preparing");

            try
            {
                await Task.Run(delegate
                {
                    using (var repo = new Repository(RepoDir))
                    {
                        if (repo.RetrieveStatus().Any(item => item.State != FileStatus.Ignored))
                        {
                            Dispatcher.Invoke(() => SyncFlyout.IsOpen = false);
                            MessageBox.Show(
                                "You have uncommitted work. " +
                                "Please commit your work before syncing.");
                            return;
                        }

                        status.SetMessage("Pulling repository");

                        var result = repo.Network.Pull(author.GetSignature(), new PullOptions
                        {
                            FetchOptions = new FetchOptions
                            {
                                CredentialsProvider = (a, b, c) => author.Credentials,
                                OnTransferProgress  = progress =>
                                {
                                    status.SetMessage(string.Format(
                                                          "Fetching repository ({0}/{1} objects)",
                                                          progress.ReceivedObjects,
                                                          progress.TotalObjects));
                                    status.SetProgress(
                                        progress.ReceivedObjects /
                                        (double)progress.TotalObjects);
                                    return(true);
                                }
                            },
                            MergeOptions = new MergeOptions
                            {
                                CommitOnSuccess    = true,
                                OnCheckoutProgress = (path, curr, total) =>
                                {
                                    if (curr == total)
                                    {
                                        status.SetMessage("Pull complete");
                                        status.SetProgress(null);
                                        return;
                                    }

                                    status.SetMessage(string.Format(
                                                          "Merging files ({0}/{1}) ({2})",
                                                          curr, total, path));
                                    status.SetProgress(curr / (double)total);
                                }
                            }
                        });

                        status.SetMessage("Preparing to send");
                        status.SetProgress(null);

                        if (result.Status == MergeStatus.Conflicts)
                        {
                            Dispatcher.Invoke(() => SyncFlyout.IsOpen = false);
                            MessageBox.Show(
                                "There were merge conflicts, please open the Visual Studio " +
                                "Team Explorer or GitExtensions to resolve them.");
                            return;
                        }

                        var options = new PushOptions
                        {
                            CredentialsProvider   = delegate { return(author.Credentials); },
                            OnPackBuilderProgress = (stage, curr, total) =>
                            {
                                if (total == 0)
                                {
                                    return(true);
                                }

                                status.SetMessage(string.Format(
                                                      "Packing objects ({0}/{1} objects)",
                                                      curr, total));
                                status.SetProgress(curr / (double)total);

                                // Slowing things down for the user :)
                                if (total - curr < 4)
                                {
                                    Thread.Sleep(500);
                                }
                                if (total == curr)
                                {
                                    Thread.Sleep(500);
                                }

                                return(true);
                            },
                            OnPushTransferProgress = (curr, total, bytes) =>
                            {
                                if (total == 0)
                                {
                                    return(true);
                                }

                                status.SetMessage(string.Format(
                                                      "Pushing to server ({0}/{1} objects)",
                                                      curr, total));
                                status.SetProgress(curr / (double)total);

                                // Slowing things down for the user :)
                                if (total - curr < 4)
                                {
                                    Thread.Sleep(500);
                                }
                                if (total == curr)
                                {
                                    Thread.Sleep(500);
                                }

                                return(true);
                            }
                        };

                        var branch = repo.Branches[repo.Head.TrackedBranch.UpstreamBranchCanonicalName];
                        repo.Network.Push(branch, options);
                    }
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("{0}: {1}", ex.GetType().Name, ex.Message));
            }

            GitUnlocked       = true;
            SyncFlyout.IsOpen = false;
            GitView.Refresh();
        }