Beispiel #1
0
        public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default)
        {
            var dialog = new MessageBox(
                string.Format("Reset"),
                DialogBoxButton.Ok | DialogBoxButton.Cancel,
                "We will (hard) reset the current checked out branch to its corresponding remote tip");

            if (mainThread.Invoke(() => dialog.ShowDialog()) == true)
            {
                foreach (var(config, repository, index) in repositories.Select((config, index) => (config, config.Repository, index)))
                {
                    repository.Fetch(credentials, prune: true);

                    if (repository.GetBranch(config.TargetBranchRemote) is Branch targetBranchRemote)
                    {
                        repository.Reset(ResetMode.Hard, targetBranchRemote.Tip);

                        eventStream.Push(Status.Create(
                                             (index + 1) / (float)repositories.Count(),
                                             "Resetting {0} to {1}...", repository.GetName(), targetBranchRemote.FriendlyName));
                    }
                }

                eventStream.Push(Status.Succeeded());

                mainThread.Invoke(() => view.Refresh());
            }

            return(Task.CompletedTask);
        }
Beispiel #2
0
        public Task ExecuteAsync(CancellationToken cancellation = default)
        {
            var entries = view.MarkedEntries.ToList();

            if (entries.Any())
            {
                var dialog = new MessageBox(
                    string.Format("Ignore Commits"),
                    DialogBoxButton.Ok | DialogBoxButton.Cancel,
                    string.Format("We will ignore and add the selected {0} commit(s) into the {1} file", entries.Count(), Constants.NoCherryPick));

                if (mainThread.Invoke(() => dialog.ShowDialog()) == true)
                {
                    // Create the file if it does not exist
                    var ignoreCommitsLines = File.Exists(Constants.NoCherryPick) ?
                                             File.ReadAllLines(Constants.NoCherryPick).ToList() : new List <string>();

                    // Iterate marked entries by repository
                    foreach (var selectedEntry in entries.GroupBy(x => x.Config))
                    {
                        // This is how it looks the ignore in the config file
                        //
                        // [repository "$(RepoName)"]
                        //     ignore = $(CommitUrl)
                        //
                        var repoSection = $"[repository \"{selectedEntry.Key.Repository.GetName()}\"]";
                        var ignores     = selectedEntry.Select(commitEntry =>
                                                               $"\tignore = {selectedEntry.Key.Repository.GetRepoUrl() + $"/commit/{commitEntry.Commit.Sha}"}");

                        // Search if the section already exists in the file
                        var existingRepoSection = ignoreCommitsLines.FirstOrDefault(x =>
                                                                                    string.Compare(x, repoSection, CultureInfo.CurrentCulture, System.Globalization.CompareOptions.IgnoreSymbols) == 0);

                        if (string.IsNullOrEmpty(existingRepoSection))
                        {
                            ignoreCommitsLines.Add(repoSection);
                        }
                        else
                        {
                            repoSection = existingRepoSection;
                        }

                        // Insert the new ignores
                        ignoreCommitsLines.InsertRange(ignoreCommitsLines.IndexOf(repoSection) + 1, ignores);

                        // Update the CherryPickConfig
                        selectedEntry.Key.IgnoreCommits = selectedEntry.Key.IgnoreCommits.Concat(ignores);
                    }

                    // And write the ignored commits
                    File.WriteAllLines(Constants.NoCherryPick, ignoreCommitsLines);

                    mainThread.Invoke(() => view.Refresh());
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #3
0
        public Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default)
        {
            var dirtyRepositories = repositories
                                    .Select(config => (
                                                config,
                                                targetBranch: config.Repository.GetBranch(config.TargetBranch),
                                                targetBranchRemote: config.Repository.GetBranch(config.TargetBranchRemote)))
                                    .Where(x => x.targetBranch != null && x.targetBranch.Tip != x.targetBranchRemote?.Tip)
                                    .Select(x => (x.config.Repository.GetName(), x.config.TargetBranchRemote + $"-merge-{x.targetBranch.Tip.GetShortSha()}"));

            if (dirtyRepositories.Any())
            {
                var dialog = new PushDialog(dirtyRepositories.ToArray());

                if (mainThread.Invoke(() => dialog.ShowDialog()) == true)
                {
                    foreach (var branch in dialog.Branches)
                    {
                        if (branch.BranchName?.Contains('/') == true && repositories.FirstOrDefault(x => x.Repository.GetName() == branch.Repo) is CherryPickConfig config)
                        {
                            var repository = config.Repository;
                            var remoteName = branch.BranchName.Substring(0, branch.BranchName.IndexOf('/'));

                            if (repository.Network.Remotes.FirstOrDefault(x => x.Name == remoteName) is Remote remote)
                            {
                                var targetBranchName = branch.BranchName.Substring(remoteName.Length + 1);

                                // Push
                                config.Repository.Network.Push(
                                    repository.Network.Remotes.Single(x => x.Name == "origin"),
                                    $"refs/heads/{repository.Head.FriendlyName}:refs/heads/{targetBranchName}",
                                    new PushOptions {
                                    CredentialsProvider = credentials
                                });

                                eventStream.Push(Status.Create("Pushed changes to {0}", $"{repository.GetRepoUrl()}/tree/{targetBranchName}"));

                                Process.Start("cmd", $"/c start {repository.GetRepoUrl()}/compare/{config.TargetBranch}...{targetBranchName}");

                                mainThread.Invoke(() => view.Refresh());
                            }
                            else
                            {
                                mainThread.Invoke(() => new MessageBox("Error", "Remote '{0}' not found for '{1}'", remoteName, branch.BranchName).ShowDialog());
                            }
                        }
                    }
                }
            }

            return(Task.CompletedTask);
        }
Beispiel #4
0
        public Task ExecuteAsync(CancellationToken cancellation = default)
        {
            foreach (var(config, index) in repositories.Select((config, index) => (config, index)))
            {
                eventStream.Push(Status.Create((index + 1) / (float)repositories.Count(), "Fetching {0}...", config.Repository.GetName()));

                config.Repository.Fetch(credentials, prune: true);
            }
            ;

            eventStream.Push(Status.Succeeded());

            mainThread.Invoke(() => view.Refresh());

            return(Task.CompletedTask);
        }
        public async Task ExecuteAsync(object?parameter = null, CancellationToken cancellation = default)
        {
            foreach (var repositoryEntries in view.MarkedEntries.GroupBy(x => x.Config).Where(x => x.Any()))
            {
                var config     = repositoryEntries.Key;
                var repository = config.Repository;

                var dialog = new MessageBox(
                    string.Format("{0} ({1} -> {2})", config.Repository.GetName(), config.BaseBranch, config.TargetBranch),
                    DialogBoxButton.Ok | DialogBoxButton.Cancel,
                    string.Format("We will cherry pick the selected {0} commit(s) into the following branch: {1}", repositoryEntries.Count(), config.TargetBranch));

                if (mainThread.Invoke(() => dialog.ShowDialog()) == true)
                {
                    var targetBranch = repository.SwitchToTargetBranch(config);

                    var count = 0;
                    foreach (var entry in repositoryEntries.Reverse())
                    {
                        var result = repository.CherryPick(entry.Commit, repository.Config.BuildSignature(DateTimeOffset.Now));

                        if (result.Status == CherryPickStatus.Conflicts)
                        {
                            await commandService.RunAsync(WellKnownCommands.ResolveConflicts, cancellation : cancellation);

                            if (repository.Index.Conflicts.Any())
                            {
                                repository.Reset(ResetMode.Hard);
                                throw new InvalidOperationException(string.Format("Unable to cherry pick {0}", entry.Commit.MessageShort));
                            }
                            else
                            {
                                // TODO: auto-commit, keep moving
                            }

                            eventStream.Push(Status.Create(++count / (float)repositoryEntries.Count(), "Cherry picking {0} {1}", entry.Commit.GetShortSha(), entry.Commit.MessageShort));
                        }
                        else
                        {
                            eventStream.Push(Status.Create(++count / (float)repositoryEntries.Count(), "Cherry picking {0} {1}", entry.Commit.GetShortSha(), entry.Commit.MessageShort));
                        }
                    }

                    mainThread.Invoke(() => view.Refresh());
                }
            }
        }
Beispiel #6
0
        public Task ExecuteAsync(CancellationToken cancellation = default)
        {
            if (config != null)
            {
                var dialog = new InputBox(
                    "Select Branch",
                    "Cherry pick from:",
                    config.Repository.Branches.Select(x => x.FriendlyName).ToArray())
                {
                    Text = config.BaseBranch ?? string.Empty
                };

                if (mainThread.Invoke(() => dialog.ShowDialog()) == true)
                {
                    config.BaseBranch = dialog.Text;
                    view.Refresh(false);
                }
            }

            return(Task.CompletedTask);
        }