From f13b1ee9fedbb20e7a0f02a5df508d4c11da2431 Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 24 Aug 2023 19:05:38 +0800 Subject: [PATCH] feature: supports `update-index --[no]-assume-unchanged` --- src/Commands/AssumeUnchanged.cs | 60 +++++++++++ src/Resources/Icons.xaml | 2 + src/Resources/Locales/en_US.xaml | 6 ++ src/Resources/Locales/zh_CN.xaml | 6 ++ src/Views/AssumeUnchanged.xaml | 100 +++++++++++++++++++ src/Views/AssumeUnchanged.xaml.cs | 64 ++++++++++++ src/Views/Widgets/WorkingCopy.xaml | 14 ++- src/Views/Widgets/WorkingCopy.xaml.cs | 6 ++ src/Views/Widgets/WorkingCopyChanges.xaml.cs | 17 ++++ 9 files changed, 272 insertions(+), 3 deletions(-) create mode 100644 src/Commands/AssumeUnchanged.cs create mode 100644 src/Views/AssumeUnchanged.xaml create mode 100644 src/Views/AssumeUnchanged.xaml.cs diff --git a/src/Commands/AssumeUnchanged.cs b/src/Commands/AssumeUnchanged.cs new file mode 100644 index 00000000..9a0af3d9 --- /dev/null +++ b/src/Commands/AssumeUnchanged.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Text.RegularExpressions; + +namespace SourceGit.Commands { + /// + /// 查看、添加或移除忽略变更文件 + /// + public class AssumeUnchanged { + private string repo; + + class ViewCommand : Command { + private static readonly Regex REG = new Regex(@"^(\w)\s+(.+)$"); + private List outs = new List(); + + public ViewCommand(string repo) { + Cwd = repo; + Args = "ls-files -v"; + } + + public List Result() { + Exec(); + return outs; + } + + public override void OnReadline(string line) { + var match = REG.Match(line); + if (!match.Success) return; + + if (match.Groups[1].Value == "h") { + outs.Add(match.Groups[2].Value); + } + } + } + + class ModCommand : Command { + public ModCommand(string repo, string file, bool bAdd) { + var mode = bAdd ? "--assume-unchanged" : "--no-assume-unchanged"; + + Cwd = repo; + Args = $"update-index {mode} -- \"{file}\""; + } + } + + public AssumeUnchanged(string repo) { + this.repo = repo; + } + + public List View() { + return new ViewCommand(repo).Result(); + } + + public void Add(string file) { + new ModCommand(repo, file, true).Exec(); + } + + public void Remove(string file) { + new ModCommand(repo, file, false).Exec(); + } + } +} diff --git a/src/Resources/Icons.xaml b/src/Resources/Icons.xaml index a338d3dc..0ff07d04 100644 --- a/src/Resources/Icons.xaml +++ b/src/Resources/Icons.xaml @@ -70,4 +70,6 @@ M719 85 388 417l-209-165L87 299v427l92 47 210-164L720 939 939 850V171zM186 610V412l104 104zm526 55L514 512l198-153z M426.7 554.7v-85.3h341.3v85.3h-341.3m0 256v-85.3h170.7v85.3h-170.7m0-512V213.3h512v85.3H426.7M256 725.3h106.7L213.3 874.7 64 725.3H170.7V298.7H64L213.3 149.3 362.7 298.7H256v426.7z + M854 170c-189-189-495-189-684 0s-189 495 0 684 495 189 684 0 187-495 0-684zM213 706c-89-137-74-325 48-444 122-122 307-137 444-48L213 706zm106 105 493-493c89 137 74 325-48 444-120 122-307 137-444 48z + M469 235V107h85v128h-85zm-162-94 85 85-60 60-85-85 60-60zm469 60-85 85-60-60 85-85 60 60zm-549 183A85 85 0 01302 341H722a85 85 0 0174 42l131 225A85 85 0 01939 652V832a85 85 0 01-85 85H171a85 85 0 01-85-85v-180a85 85 0 0112-43l131-225zM722 427H302l-100 171h255l10 29a59 59 0 002 5c2 4 5 9 9 14 8 9 18 17 34 17 16 0 26-7 34-17a72 72 0 0011-18l0-0 10-29h255l-100-171zM853 683H624a155 155 0 01-12 17C593 722 560 747 512 747c-48 0-81-25-99-47a155 155 0 01-12-17H171v149h683v-149z \ No newline at end of file diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml index f5fc5d01..933f61d2 100644 --- a/src/Resources/Locales/en_US.xaml +++ b/src/Resources/Locales/en_US.xaml @@ -217,6 +217,7 @@ Discard {0} files... Stash {0} files... Save As Patch... + Assume unchaged Confirm To Delete Branch Branch : @@ -394,6 +395,7 @@ Changes UNSTAGED + VIEW ASSUME UNCHANGED STAGE STAGE ALL STAGED @@ -477,6 +479,10 @@ COMMITTER COMMITS + FILES ASSUME UNCHANGED + REMOVE + NO FILES ASSUMED AS UNCHANGED + SUN MON TUE diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml index d0999df0..fb46362b 100644 --- a/src/Resources/Locales/zh_CN.xaml +++ b/src/Resources/Locales/zh_CN.xaml @@ -216,6 +216,7 @@ 放弃 {0} 个文件的更改... 贮藏选中的 {0} 个文件... 另存为补丁... + 不跟踪此文件的更改 确定要删除此分支吗? 分支名 : @@ -393,6 +394,7 @@ 本地更改 未暂存 + 查看忽略变更文件 暂存选中 暂存所有 已暂存 @@ -476,6 +478,10 @@ 提交者 提交次数 + 不跟踪更改的文件 + 移除 + 没有不跟踪更改的文件 + 星期日 星期一 星期二 diff --git a/src/Views/AssumeUnchanged.xaml b/src/Views/AssumeUnchanged.xaml new file mode 100644 index 00000000..01d5413f --- /dev/null +++ b/src/Views/AssumeUnchanged.xaml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Views/AssumeUnchanged.xaml.cs b/src/Views/AssumeUnchanged.xaml.cs new file mode 100644 index 00000000..1336f0bb --- /dev/null +++ b/src/Views/AssumeUnchanged.xaml.cs @@ -0,0 +1,64 @@ +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace SourceGit.Views { + /// + /// 管理不跟踪变更的文件 + /// + public partial class AssumeUnchanged : Controls.Window { + private string repo = null; + + public ObservableCollection Files { get; set; } + + public AssumeUnchanged(string repo) { + this.repo = repo; + this.Files = new ObservableCollection(); + + InitializeComponent(); + + Task.Run(() => { + var unchanged = new Commands.AssumeUnchanged(repo).View(); + Dispatcher.Invoke(() => { + if (unchanged.Count > 0) { + foreach (var file in unchanged) Files.Add(file); + + mask.Visibility = Visibility.Collapsed; + list.Visibility = Visibility.Visible; + list.ItemsSource = Files; + } else { + list.Visibility = Visibility.Collapsed; + mask.Visibility = Visibility.Visible; + } + }); + }); + } + + private void OnQuit(object sender, RoutedEventArgs e) { + Close(); + } + + private void OnRequestBringIntoView(object sender, RequestBringIntoViewEventArgs e) { + e.Handled = true; + } + + private void Remove(object sender, RoutedEventArgs e) { + var btn = sender as Button; + if (btn == null) return; + + var file = btn.DataContext as string; + if (file == null) return; + + new Commands.AssumeUnchanged(repo).Remove(file); + Files.Remove(file); + + if (Files.Count == 0) { + list.Visibility = Visibility.Collapsed; + mask.Visibility = Visibility.Visible; + } + + e.Handled = true; + } + } +} diff --git a/src/Views/Widgets/WorkingCopy.xaml b/src/Views/Widgets/WorkingCopy.xaml index d53bfe1f..70bc5407 100644 --- a/src/Views/Widgets/WorkingCopy.xaml +++ b/src/Views/Widgets/WorkingCopy.xaml @@ -41,6 +41,7 @@ + - + { + new Commands.AssumeUnchanged(repo).Add(node.Path); + e.Handled = true; + }; + menu.Items.Add(assumeUnchanged); + var history = new MenuItem(); history.Header = App.Text("FileHistory"); history.Click += (o, e) => { @@ -622,6 +631,13 @@ namespace SourceGit.Views.Widgets { e.Handled = true; }; + var assumeUnchanged = new MenuItem(); + assumeUnchanged.Header = App.Text("FileCM.AssumeUnchanged"); + assumeUnchanged.Click += (o, e) => { + new Commands.AssumeUnchanged(repo).Add(change.Path); + e.Handled = true; + }; + menu.Items.Add(explore); menu.Items.Add(new Separator()); menu.Items.Add(stage); @@ -629,6 +645,7 @@ namespace SourceGit.Views.Widgets { menu.Items.Add(stash); menu.Items.Add(patch); menu.Items.Add(new Separator()); + menu.Items.Add(assumeUnchanged); menu.Items.Add(history); menu.Items.Add(new Separator()); menu.Items.Add(copyPath);