protected override async Task OnBranchSelection(string command) { var branch = CurrentRepository.GetBranchInfo(includeRemote: false) .FirstOrDefault(x => string.Equals(x.Name,command,StringComparison.OrdinalIgnoreCase)); var switchInfo = new SwitchBranchInfo() { BranchInfo = branch, Switch = true, Repository = CurrentRepository }; await GitCommandWrappers.SwitchCommand(switchInfo); }
internal SwitchBranchInfo Show() { window = new Window { Title = "Switch (checkout) branch", Content = this, WindowStartupLocation = WindowStartupLocation.CenterScreen, ResizeMode = System.Windows.ResizeMode.NoResize, Width = 350, Height = 200 }; _branches.Clear(); var branches = repository.GetBranchInfo(forceReload:true); branches = branches.OrderBy(x => x.IsRemote).ThenBy(x => x.FullName).ToList();//.Select(r => r.FullName); ; foreach (var gitBranchInfo in branches) { _branches.Add(gitBranchInfo); } comboBranches.ItemsSource = branches; comboBranches.Items.Refresh(); comboBranches.DisplayMemberPath = "FullName"; comboBranches.SelectedValuePath = "CanonicalName"; comboBranches.SelectedValue = repository.CurrentBranchInfo.CanonicalName; _pickerResult = new SwitchBranchInfo(); _pickerResult.Repository = repository; if (window.ShowDialog() == true) { return _pickerResult; } else { return new SwitchBranchInfo(); } }
internal static async Task<GitActionResult<GitBranchInfo>> SwitchCommand(SwitchBranchInfo result) { if (!result.CreateBranch && !result.Switch) { return new GitActionResult<GitBranchInfo>() { ErrorMessage = "No Branch Operation", Succeeded = false }; } GitActionResult<GitBranchInfo> branchResult = new GitActionResult<GitBranchInfo>(); bool inError = false; var branch = result.BranchInfo; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Branch Operation Started"); if (result.CreateBranch) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Creating Branch"); await TaskScheduler.Default; branchResult = result.Repository.CreateBranch(result.BranchName); if (branchResult.Succeeded) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Branch: ' " + branchResult.Item.Name + "' Created"); branch = branchResult.Item; } else { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); inError = true; SolutionExtensions.WriteMessageToOutputPane(branchResult.ErrorMessage); } } if (result.Switch && !inError) { if (branch != null) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Switching Branch"); await TaskScheduler.Default; if (branch.IsRemote) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Creating Local Branch"); var createResult = result.Repository.CreateBranch(branch.Name.Remove(0,branch.RemoteName.Length +1),branch.Sha); if (!createResult.Succeeded) { return createResult; } result.Repository.SetRemoteBranch(createResult.Item,branch.RemoteName); branchResult = result.Repository.Checkout(createResult.Item); } else { branchResult = result.Repository.Checkout(branch); } if (!branchResult.Succeeded) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); inError = true; SolutionExtensions.WriteMessageToOutputPane(branchResult.ErrorMessage); } } } if (!inError) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Branch Operation Complete"); } return branchResult; }
internal static async Task <GitActionResult <GitBranchInfo> > SwitchCommand(SwitchBranchInfo result) { if (!result.CreateBranch && !result.Switch) { return(new GitActionResult <GitBranchInfo>() { ErrorMessage = "No Branch Operation", Succeeded = false }); } GitActionResult <GitBranchInfo> branchResult = new GitActionResult <GitBranchInfo>(); bool inError = false; var branch = result.BranchInfo; await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Branch Operation Started"); if (result.CreateBranch) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Creating Branch"); await TaskScheduler.Default; branchResult = result.Repository.CreateBranch(result.BranchName); if (branchResult.Succeeded) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Branch: ' " + branchResult.Item.Name + "' Created"); branch = branchResult.Item; } else { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); inError = true; SolutionExtensions.WriteMessageToOutputPane(branchResult.ErrorMessage); } } if (result.Switch && !inError) { if (branch != null) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Switching Branch"); await TaskScheduler.Default; if (branch.IsRemote) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Creating Local Branch"); var createResult = result.Repository.CreateBranch(branch.Name.Remove(0, branch.RemoteName.Length + 1), branch.Sha); if (!createResult.Succeeded) { return(createResult); } result.Repository.SetRemoteBranch(createResult.Item, branch.RemoteName); branchResult = result.Repository.Checkout(createResult.Item); } else { branchResult = result.Repository.Checkout(branch); } if (!branchResult.Succeeded) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); inError = true; SolutionExtensions.WriteMessageToOutputPane(branchResult.ErrorMessage); } } } if (!inError) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); SolutionExtensions.WriteMessageToOutputPane("Branch Operation Complete"); } return(branchResult); }