using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace SourceGit.UI {
///
/// Merge branch dialog.
///
public partial class Merge : UserControl {
private Git.Repository repo = null;
///
/// Merge option.
///
public class Option {
public string Name { get; set; }
public string Desc { get; set; }
public string Arg { get; set; }
public Option(string n, string d, string a) {
Name = n;
Desc = d;
Arg = a;
}
}
///
/// Constructor.
///
/// Opened repository
/// Source branch to merge data from.
/// Target branch to merge into
public Merge(Git.Repository opened, string source, string dest) {
InitializeComponent();
repo = opened;
sourceBranch.Content = source;
targetBranch.Content = dest;
combOptions.ItemsSource = new Option[] {
new Option("Default", "Fast-forward if possible", ""),
new Option("No Fast-forward", "Always create a merge commit", "--no-ff"),
new Option("Squash", "Use '--squash'", "--squash"),
new Option("Don't commit", "Merge without commit", "--no-commit"),
};
combOptions.SelectedIndex = 0;
}
///
/// Display this dialog.
///
///
///
///
public static void Show(Git.Repository opened, string source, string dest) {
PopupManager.Show(new Merge(opened, source, dest));
}
///
/// Start merge directly(Fast-forward).
///
///
///
///
public static void StartDirectly(Git.Repository opened, string source, string dest) {
var merge = new Merge(opened, source, dest);
PopupManager.Show(merge);
PopupManager.Lock();
Task.Run(() => {
opened.Merge(source, "");
merge.Dispatcher.Invoke(() => {
PopupManager.Close(true);
});
});
}
///
/// Start merge
///
///
///
private async void Start(object sender, RoutedEventArgs e) {
PopupManager.Lock();
var branch = sourceBranch.Content as string;
var opt = combOptions.SelectedItem as Option;
await Task.Run(() => repo.Merge(branch, opt.Arg));
PopupManager.Close(true);
}
///
/// Cancel merge.
///
///
///
private void Cancel(object sender, RoutedEventArgs e) {
PopupManager.Close();
}
}
}