mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: simpfy the way to lock a worktree
This commit is contained in:
parent
8a8aabede3
commit
fa2c7c0e18
10 changed files with 25 additions and 125 deletions
|
@ -88,12 +88,9 @@ namespace SourceGit.Commands
|
|||
return Exec();
|
||||
}
|
||||
|
||||
public bool Lock(string fullpath, string reason)
|
||||
public bool Lock(string fullpath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(reason))
|
||||
Args = $"worktree lock \"{fullpath}\"";
|
||||
else
|
||||
Args = $"worktree lock --reason \"{reason}\" \"{fullpath}\"";
|
||||
return Exec();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<x:String x:Key="Text.About.SubTitle" xml:space="preserve">Opensource & Free Git GUI Client</x:String>
|
||||
<x:String x:Key="Text.AddWorktree" xml:space="preserve">Add Worktree</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Location" xml:space="preserve">Location:</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Location.Placeholder" xml:space="preserve">Path for this worktree. Relative path is supported.</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Name" xml:space="preserve">Branch Name:</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Name.Placeholder" xml:space="preserve">Optional. Default is the destination folder name.</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">Track Branch:</x:String>
|
||||
|
@ -311,10 +312,6 @@
|
|||
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">ERROR</x:String>
|
||||
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">NOTICE</x:String>
|
||||
<x:String x:Key="Text.Launcher.Menu" xml:space="preserve">Open Main Menu</x:String>
|
||||
<x:String x:Key="Text.LockWorktree" xml:space="preserve">Lock Worktree</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Reason" xml:space="preserve">Reason:</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Reason.Placeholder" xml:space="preserve">Optional, specify a reason for the lock.</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Target" xml:space="preserve">Target:</x:String>
|
||||
<x:String x:Key="Text.Merge" xml:space="preserve">Merge Branch</x:String>
|
||||
<x:String x:Key="Text.Merge.Into" xml:space="preserve">Into:</x:String>
|
||||
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">Merge Option:</x:String>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<x:String x:Key="Text.About.SubTitle" xml:space="preserve">开源免费的Git客户端</x:String>
|
||||
<x:String x:Key="Text.AddWorktree" xml:space="preserve">新增工作树</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Location" xml:space="preserve">工作树路径 :</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Location.Placeholder" xml:space="preserve">填写该工作树的路径。支持相对路径。</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Name" xml:space="preserve">自定义分支名 :</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Name.Placeholder" xml:space="preserve">选填。默认使用目标文件夹名称。</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">跟踪分支</x:String>
|
||||
|
@ -314,10 +315,6 @@
|
|||
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出错了</x:String>
|
||||
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系统提示</x:String>
|
||||
<x:String x:Key="Text.Launcher.Menu" xml:space="preserve">主菜单</x:String>
|
||||
<x:String x:Key="Text.LockWorktree" xml:space="preserve">锁定工作树</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Reason" xml:space="preserve">原因 :</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Reason.Placeholder" xml:space="preserve">选填,为此锁定操作描述原因。</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Target" xml:space="preserve">目标工作树 :</x:String>
|
||||
<x:String x:Key="Text.Merge" xml:space="preserve">合并分支</x:String>
|
||||
<x:String x:Key="Text.Merge.Into" xml:space="preserve">目标分支 :</x:String>
|
||||
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">合并方式 :</x:String>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<x:String x:Key="Text.About.SubTitle" xml:space="preserve">開源免費的Git客戶端</x:String>
|
||||
<x:String x:Key="Text.AddWorktree" xml:space="preserve">新增工作樹</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Location" xml:space="preserve">工作樹路徑 :</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Location.Placeholder" xml:space="preserve">填寫該工作樹的路徑。支援相對路徑。</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Name" xml:space="preserve">自定义分支名 :</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Name.Placeholder" xml:space="preserve">選填。 預設使用目標資料夾名稱。</x:String>
|
||||
<x:String x:Key="Text.AddWorktree.Tracking" xml:space="preserve">跟蹤分支</x:String>
|
||||
|
@ -314,10 +315,6 @@
|
|||
<x:String x:Key="Text.Launcher.Error" xml:space="preserve">出錯了</x:String>
|
||||
<x:String x:Key="Text.Launcher.Info" xml:space="preserve">系統提示</x:String>
|
||||
<x:String x:Key="Text.Launcher.Menu" xml:space="preserve">主選單</x:String>
|
||||
<x:String x:Key="Text.LockWorktree" xml:space="preserve">鎖定工作樹</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Reason" xml:space="preserve">原因 :</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Reason.Placeholder" xml:space="preserve">選填,為此鎖定操作描述原因。</x:String>
|
||||
<x:String x:Key="Text.LockWorktree.Target" xml:space="preserve">目標工作樹 :</x:String>
|
||||
<x:String x:Key="Text.Merge" xml:space="preserve">合併分支</x:String>
|
||||
<x:String x:Key="Text.Merge.Into" xml:space="preserve">目標分支 :</x:String>
|
||||
<x:String x:Key="Text.Merge.Mode" xml:space="preserve">合併方式 :</x:String>
|
||||
|
|
|
@ -13,10 +13,10 @@ namespace SourceGit.ViewModels
|
|||
|
||||
[Required(ErrorMessage = "Worktree path is required!")]
|
||||
[CustomValidation(typeof(AddWorktree), nameof(ValidateWorktreePath))]
|
||||
public string FullPath
|
||||
public string Path
|
||||
{
|
||||
get => _fullPath;
|
||||
set => SetProperty(ref _fullPath, value, true);
|
||||
get => _path;
|
||||
set => SetProperty(ref _path, value, true);
|
||||
}
|
||||
|
||||
[CustomValidation(typeof(AddWorktree), nameof(ValidateBranchName))]
|
||||
|
@ -63,9 +63,14 @@ namespace SourceGit.ViewModels
|
|||
View = new Views.AddWorktree() { DataContext = this };
|
||||
}
|
||||
|
||||
public static ValidationResult ValidateWorktreePath(string folder, ValidationContext _)
|
||||
public static ValidationResult ValidateWorktreePath(string path, ValidationContext ctx)
|
||||
{
|
||||
var info = new DirectoryInfo(folder);
|
||||
var creator = ctx.ObjectInstance as AddWorktree;
|
||||
if (creator == null)
|
||||
return new ValidationResult("Missing runtime context to create branch!");
|
||||
|
||||
var fullPath = System.IO.Path.IsPathRooted(path) ? path : System.IO.Path.Combine(creator._repo.FullPath, path);
|
||||
var info = new DirectoryInfo(fullPath);
|
||||
if (info.Exists)
|
||||
{
|
||||
var files = info.GetFiles();
|
||||
|
@ -108,14 +113,14 @@ namespace SourceGit.ViewModels
|
|||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = new Commands.Worktree(_repo.FullPath).Add(_fullPath, _customName, tracking, SetProgressDescription);
|
||||
var succ = new Commands.Worktree(_repo.FullPath).Add(_path, _customName, tracking, SetProgressDescription);
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return succ;
|
||||
});
|
||||
}
|
||||
|
||||
private Repository _repo = null;
|
||||
private string _fullPath = string.Empty;
|
||||
private string _path = string.Empty;
|
||||
private string _customName = string.Empty;
|
||||
private bool _setTrackingBranch = false;
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.ViewModels
|
||||
{
|
||||
public class LockWorktree : Popup
|
||||
{
|
||||
public Models.Worktree Target
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = null;
|
||||
|
||||
public string Reason
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = string.Empty;
|
||||
|
||||
public LockWorktree(Repository repo, Models.Worktree target)
|
||||
{
|
||||
_repo = repo;
|
||||
Target = target;
|
||||
View = new Views.LockWorktree() { DataContext = this };
|
||||
}
|
||||
|
||||
public override Task<bool> Sure()
|
||||
{
|
||||
_repo.SetWatcherEnabled(false);
|
||||
ProgressDescription = "Locking worktrees ...";
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var succ = new Commands.Worktree(_repo.FullPath).Lock(Target.FullPath, Reason);
|
||||
if (succ)
|
||||
Target.IsLocked = true;
|
||||
|
||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private Repository _repo = null;
|
||||
}
|
||||
}
|
|
@ -1731,8 +1731,11 @@ namespace SourceGit.ViewModels
|
|||
loc.Icon = App.CreateMenuIcon("Icons.Lock");
|
||||
loc.Click += (o, ev) =>
|
||||
{
|
||||
if (PopupHost.CanCreatePopup())
|
||||
PopupHost.ShowPopup(new LockWorktree(this, worktree));
|
||||
SetWatcherEnabled(false);
|
||||
var succ = new Commands.Worktree(_fullpath).Lock(worktree.FullPath);
|
||||
if (succ)
|
||||
worktree.IsLocked = true;
|
||||
SetWatcherEnabled(true);
|
||||
ev.Handled = true;
|
||||
};
|
||||
menu.Items.Add(loc);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<TextBlock FontSize="18"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.AddWorktree}"/>
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto" ColumnDefinitions="150,*">
|
||||
<Grid Margin="0,16,0,0" RowDefinitions="32,32,32,Auto" ColumnDefinitions="120,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0"
|
||||
|
@ -22,7 +22,8 @@
|
|||
x:Name="TxtLocation"
|
||||
Height="28"
|
||||
CornerRadius="3"
|
||||
Text="{Binding FullPath, Mode=TwoWay}">
|
||||
Text="{Binding Path, Mode=TwoWay}"
|
||||
Watermark="{DynamicResource Text.AddWorktree.Location.Placeholder}">
|
||||
<TextBox.InnerRightContent>
|
||||
<Button Classes="icon_button" Width="28" Height="28" Margin="4,0,0,0" Click="SelectLocation">
|
||||
<Path Data="{StaticResource Icons.Folder.Open}" Fill="{DynamicResource Brush.FG1}"/>
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:m="using:SourceGit.Models"
|
||||
xmlns:vm="using:SourceGit.ViewModels"
|
||||
xmlns:v="using:SourceGit.Views"
|
||||
xmlns:c="using:SourceGit.Converters"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="SourceGit.Views.LockWorktree"
|
||||
x:DataType="vm:LockWorktree">
|
||||
<StackPanel Orientation="Vertical" Margin="8,0,0,0">
|
||||
<TextBlock FontSize="18"
|
||||
Classes="bold"
|
||||
Text="{DynamicResource Text.LockWorktree}"/>
|
||||
<Grid Margin="8,16,0,0" RowDefinitions="32,32" ColumnDefinitions="120,*">
|
||||
<TextBlock Grid.Row="0" Grid.Column="0"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="8,0"
|
||||
Text="{DynamicResource Text.LockWorktree.Target}"/>
|
||||
<Grid Grid.Row="0" Grid.Column="1" ColumnDefinitions="Auto,*">
|
||||
<Path Grid.Column="0" Width="12" Height="12" Data="{StaticResource Icons.Worktree}"/>
|
||||
<TextBlock Grid.Column="1" Classes="monospace" Margin="8,0,0,0" TextTrimming="CharacterEllipsis">
|
||||
<Run Text="{Binding Target.FullPath}"/>
|
||||
<Run Text="{Binding Target.Name}" Foreground="{DynamicResource Brush.FG2}"/>
|
||||
</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<TextBlock Grid.Row="1" Grid.Column="0"
|
||||
HorizontalAlignment="Right"
|
||||
Margin="8,0"
|
||||
Text="{DynamicResource Text.LockWorktree.Reason}"/>
|
||||
<TextBox Grid.Row="1" Grid.Column="1"
|
||||
Height="26"
|
||||
CornerRadius="3"
|
||||
Text="{Binding Reason, Mode=TwoWay}"
|
||||
Watermark="{DynamicResource Text.LockWorktree.Reason.Placeholder}"
|
||||
v:AutoFocusBehaviour.IsEnabled="True"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</UserControl>
|
|
@ -1,12 +0,0 @@
|
|||
using Avalonia.Controls;
|
||||
|
||||
namespace SourceGit.Views
|
||||
{
|
||||
public partial class LockWorktree : UserControl
|
||||
{
|
||||
public LockWorktree()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue