2021-04-29 05:05:55 -07:00
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
|
|
namespace SourceGit.Views.Popups {
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 拉回
|
|
|
|
/// </summary>
|
|
|
|
public partial class Pull : Controls.PopupWidget {
|
|
|
|
private Models.Repository repo = null;
|
|
|
|
private Models.Branch prefered = null;
|
|
|
|
|
|
|
|
public Pull(Models.Repository repo, Models.Branch preferRemoteBranch) {
|
|
|
|
this.repo = repo;
|
|
|
|
this.prefered = preferRemoteBranch;
|
|
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
var current = repo.Branches.Find(x => x.IsCurrent);
|
2021-06-15 01:14:16 -07:00
|
|
|
if (current == null) return;
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
txtInto.Text = current.Name;
|
|
|
|
|
|
|
|
if (prefered == null && !string.IsNullOrEmpty(current.Upstream)) {
|
|
|
|
prefered = repo.Branches.Find(x => x.FullName == current.Upstream);
|
|
|
|
}
|
|
|
|
|
|
|
|
cmbRemotes.ItemsSource = repo.Remotes;
|
|
|
|
if (prefered != null) {
|
|
|
|
cmbRemotes.SelectedItem = repo.Remotes.Find(x => x.Name == prefered.Remote);
|
|
|
|
} else {
|
|
|
|
cmbRemotes.SelectedItem = repo.Remotes[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string GetTitle() {
|
|
|
|
return App.Text("Pull.Title");
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<bool> Start() {
|
|
|
|
var branch = cmbBranches.SelectedItem as Models.Branch;
|
|
|
|
if (branch == null) return null;
|
|
|
|
|
|
|
|
var rebase = chkUseRebase.IsChecked == true;
|
|
|
|
var autoStash = chkAutoStash.IsChecked == true;
|
|
|
|
|
|
|
|
return Task.Run(() => {
|
|
|
|
Models.Watcher.SetEnabled(repo.Path, false);
|
|
|
|
var succ = new Commands.Pull(repo.Path, branch.Remote, branch.Name, rebase, autoStash, UpdateProgress).Exec();
|
|
|
|
Models.Watcher.SetEnabled(repo.Path, true);
|
|
|
|
return succ;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnRemoteSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
|
|
|
var remote = cmbRemotes.SelectedItem as Models.Remote;
|
|
|
|
if (remote == null) return;
|
|
|
|
|
|
|
|
var branches = repo.Branches.Where(x => x.Remote == remote.Name).ToList();
|
|
|
|
cmbBranches.ItemsSource = branches;
|
|
|
|
|
2021-09-25 22:50:06 -07:00
|
|
|
if (branches.Count == 0) return;
|
|
|
|
|
2021-04-29 05:05:55 -07:00
|
|
|
if (prefered != null && remote.Name == prefered.Remote) {
|
|
|
|
cmbBranches.SelectedItem = branches.Find(x => x.FullName == prefered.FullName);
|
|
|
|
} else {
|
|
|
|
cmbBranches.SelectedItem = branches[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|