feature<SubTree>: supports git subtree feature

This commit is contained in:
leo 2021-06-07 11:47:16 +08:00
parent 6b602e70c5
commit 130b5a66ab
22 changed files with 784 additions and 10 deletions

View file

@ -0,0 +1,86 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.AddSubTree"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.AddSubTree.Source}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="0" Grid.Column="1"
x:Name="txtSource"
Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Source" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:GitURL/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.AddSubTree.Branch}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtRef"
Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Ref" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:Required/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.AddSubTree.Prefix}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="2" Grid.Column="1"
x:Name="txtPrefix"
Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Prefix" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:RelativePath/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<CheckBox
Grid.Row="3" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkSquash"
IsChecked="True"
Content="{StaticResource Text.AddSubTree.Squash}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,57 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 添加子树面板
/// </summary>
public partial class AddSubTree : Controls.PopupWidget {
private Models.Repository repo = null;
public string Source { get; set; }
public string Ref { get; set; }
public string Prefix { get; set; }
public AddSubTree(Models.Repository repo) {
this.repo = repo;
InitializeComponent();
}
public override string GetTitle() {
return App.Text("AddSubTree");
}
public override Task<bool> Start() {
txtSource.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtSource)) return null;
txtPrefix.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtPrefix)) return null;
txtRef.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtRef)) return null;
var squash = chkSquash.IsChecked == true;
if (repo.SubTrees.FindIndex(x => x.Prefix == Prefix) >= 0) {
Models.Exception.Raise($"Subtree add failed. Prefix({Prefix}) already exists!");
return null;
}
return Task.Run(() => {
Models.Watcher.SetEnabled(repo.Path, false);
var succ = new Commands.SubTree(repo.Path).Add(Prefix, Source, Ref, squash, UpdateProgress);
if (succ) {
repo.SubTrees.Add(new Models.SubTree() {
Prefix = Prefix,
Remote = Source,
});
Models.Preference.Save();
Models.Watcher.Get(repo.Path)?.RefreshSubTrees();
}
Models.Watcher.SetEnabled(repo.Path, true);
return succ;
});
}
}
}

View file

@ -53,7 +53,7 @@
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Path" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:SubmodulePath/>
<validations:RelativePath/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>

View file

@ -0,0 +1,54 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.EditSubTree"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.EditSubTree.Prefix}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.EditSubTree.Source}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="1" Grid.Column="1"
x:Name="txtSource"
Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Source" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:GitURL/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,34 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 编辑子树
/// </summary>
public partial class EditSubTree : Controls.PopupWidget {
private Models.Repository repo;
private Models.SubTree subtree;
public string Source {
get { return subtree.Remote; }
set { subtree.Remote = value; }
}
public EditSubTree(Models.Repository repo, string prefix) {
this.repo = repo;
this.subtree = repo.SubTrees.Find(x => x.Prefix == prefix);
InitializeComponent();
txtPrefix.Text = prefix;
}
public override string GetTitle() {
return App.Text("EditSubTree");
}
public override Task<bool> Start() {
txtSource.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtSource)) return null;
return Task.Run(() => true);
}
}
}

View file

@ -0,0 +1,76 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.SubTreePull"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.SubTreePullOrPush.Prefix}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.SubTreePullOrPush.Source}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="1" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock x:Name="txtSource" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.SubTreePullOrPush.Branch}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="2" Grid.Column="1"
x:Name="txtBranch"
Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Branch" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:Required/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
<CheckBox
Grid.Row="3" Grid.Column="1"
Margin="0,4,0,0"
x:Name="chkSquash"
IsChecked="True"
Content="{StaticResource Text.SubTreePullOrPush.Squash}"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,43 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 拉取
/// </summary>
public partial class SubTreePull : Controls.PopupWidget {
private string repo;
private Models.SubTree subtree;
public string Branch {
get { return subtree.Branch; }
set { subtree.Branch = value; }
}
public SubTreePull(string repo, Models.SubTree subtree) {
this.repo = repo;
this.subtree = subtree;
InitializeComponent();
txtPrefix.Text = subtree.Prefix;
txtSource.Text = subtree.Remote;
}
public override string GetTitle() {
return App.Text("SubTreePullOrPush.Pull");
}
public override Task<bool> Start() {
txtBranch.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtBranch)) return null;
var squash = chkSquash.IsChecked == true;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.SubTree(repo).Pull(subtree.Prefix, subtree.Remote, Branch, squash, UpdateProgress);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,68 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.SubTreePush"
x:Name="me"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
xmlns:validations="clr-namespace:SourceGit.Views.Validations"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.SubTreePullOrPush.Prefix}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.SubTreePullOrPush.Source}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="1" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.Remote}"/>
<TextBlock x:Name="txtSource" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="2" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.SubTreePullOrPush.Branch}"
HorizontalAlignment="Right"/>
<controls:TextEdit
Grid.Row="2" Grid.Column="1"
x:Name="txtBranch"
Height="24">
<controls:TextEdit.Text>
<Binding ElementName="me" Path="Branch" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay">
<Binding.ValidationRules>
<validations:Required/>
</Binding.ValidationRules>
</Binding>
</controls:TextEdit.Text>
</controls:TextEdit>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,41 @@
using System.Threading.Tasks;
using System.Windows.Controls;
namespace SourceGit.Views.Popups {
/// <summary>
/// 推送
/// </summary>
public partial class SubTreePush : Controls.PopupWidget {
private string repo;
private Models.SubTree subtree;
public string Branch {
get { return subtree.Branch; }
set { subtree.Branch = value; }
}
public SubTreePush(string repo, Models.SubTree subtree) {
this.repo = repo;
this.subtree = subtree;
InitializeComponent();
txtPrefix.Text = subtree.Prefix;
txtSource.Text = subtree.Remote;
}
public override string GetTitle() {
return App.Text("SubTreePullOrPush.Push");
}
public override Task<bool> Start() {
txtBranch.GetBindingExpression(TextBox.TextProperty).UpdateSource();
if (Validation.GetHasError(txtBranch)) return null;
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
new Commands.SubTree(repo).Push(subtree.Prefix, subtree.Remote, Branch, UpdateProgress);
Models.Watcher.SetEnabled(repo, true);
return true;
});
}
}
}

View file

@ -0,0 +1,40 @@
<controls:PopupWidget
x:Class="SourceGit.Views.Popups.UnlinkSubTree"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="32"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Row="0" Grid.Column="0"
Margin="0,0,8,0"
Text="{StaticResource Text.UnlinkSubTree.Prefix}"
HorizontalAlignment="Right"/>
<StackPanel
Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
VerticalAlignment="Center">
<Path Width="14" Height="14" Data="{StaticResource Icon.SubTree}"/>
<TextBlock x:Name="txtPrefix" Margin="8,0,0,0"/>
</StackPanel>
<TextBlock
Grid.Row="1" Grid.Column="1"
Margin="0,0,8,0"
Text="{StaticResource Text.UnlinkSubTree.Tips}"
HorizontalAlignment="Left"/>
</Grid>
</controls:PopupWidget>

View file

@ -0,0 +1,34 @@
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
/// <summary>
/// 删除子树
/// </summary>
public partial class UnlinkSubTree : Controls.PopupWidget {
private Models.Repository repo;
private string prefix;
public UnlinkSubTree(Models.Repository repo, string prefix) {
this.repo = repo;
this.prefix = prefix;
InitializeComponent();
txtPrefix.Text = prefix;
}
public override string GetTitle() {
return App.Text("UnlinkSubTree");
}
public override Task<bool> Start() {
return Task.Run(() => {
var idx = repo.SubTrees.FindIndex(x => x.Prefix == prefix);
if (idx >= 0) {
repo.SubTrees.RemoveAt(idx);
Models.Preference.Save();
Models.Watcher.Get(repo.Path)?.RefreshSubTrees();
}
return true;
});
}
}
}