From a249eed1ac3028123a04310afff791269b63bd4a Mon Sep 17 00:00:00 2001 From: Gadfly Date: Fri, 12 Apr 2024 21:38:36 +0800 Subject: [PATCH] feat: show git file mode change if exist --- src/Commands/Diff.cs | 17 +++++++++++++++++ src/Converters/ObjectConverters.cs | 13 +++++++++++++ src/Models/DiffResult.cs | 7 +++++++ src/Resources/Locales/en_US.axaml | 1 + src/Resources/Locales/zh_CN.axaml | 1 + src/ViewModels/DiffContext.cs | 13 +++++++++++++ src/Views/DiffView.axaml | 11 +++++++++-- 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Converters/ObjectConverters.cs diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index 090eba98..4984e3db 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text.RegularExpressions; +using SourceGit.Models; namespace SourceGit.Commands { @@ -46,6 +47,22 @@ namespace SourceGit.Commands protected override void OnReadline(string line) { + if (line.StartsWith("old mode ", StringComparison.Ordinal)) + { + _result.FileModeDiff ??= new FileModeDiff(); + + _result.FileModeDiff.Old = line.Substring(9); + return; + } + + if (line.StartsWith("new mode ", StringComparison.Ordinal)) + { + _result.FileModeDiff ??= new FileModeDiff(); + + _result.FileModeDiff.New = line.Substring(9); + return; + } + if (_result.IsBinary) return; diff --git a/src/Converters/ObjectConverters.cs b/src/Converters/ObjectConverters.cs new file mode 100644 index 00000000..8b11ef93 --- /dev/null +++ b/src/Converters/ObjectConverters.cs @@ -0,0 +1,13 @@ +using Avalonia.Data.Converters; + +namespace SourceGit.Converters +{ + public static class ObjectConverters + { + public static readonly FuncValueConverter IsNull = + new FuncValueConverter(v => v == null); + + public static readonly FuncValueConverter IsNotNull = + new FuncValueConverter(v => v != null); + } +} diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index 8cceced8..3325a841 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -576,11 +576,18 @@ namespace SourceGit.Models { } + public class FileModeDiff + { + public string Old { get; set; } = string.Empty; + public string New { get; set; } = string.Empty; + } + public class DiffResult { public bool IsBinary { get; set; } = false; public bool IsLFS { get; set; } = false; public TextDiff TextDiff { get; set; } = null; public LFSDiff LFSDiff { get; set; } = null; + public FileModeDiff FileModeDiff { get; set; } = null; } } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 870868ac..10d632f6 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -131,6 +131,7 @@ NEW OLD Copy + File Mode Changed : LFS OBJECT CHANGE Next Difference NO CHANGES OR ONLY EOL CHANGES diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 330961f9..ede3aa65 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -131,6 +131,7 @@ 当前大小 原始大小 复制 + 文件权限已变化 : LFS对象变更 下一个差异 没有变更或仅有换行符差异 diff --git a/src/ViewModels/DiffContext.cs b/src/ViewModels/DiffContext.cs index 17514656..19449cc9 100644 --- a/src/ViewModels/DiffContext.cs +++ b/src/ViewModels/DiffContext.cs @@ -7,6 +7,7 @@ using Avalonia.Media.Imaging; using Avalonia.Threading; using CommunityToolkit.Mvvm.ComponentModel; +using SourceGit.Models; namespace SourceGit.ViewModels { @@ -66,6 +67,12 @@ namespace SourceGit.ViewModels set => SetProperty(ref _syncScrollOffset, value); } + public Models.FileModeDiff FileModeDiff + { + get => _fileModeDiff; + set => SetProperty(ref _fileModeDiff, value); + } + public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null) { _repo = repo; @@ -86,6 +93,11 @@ namespace SourceGit.ViewModels var latest = new Commands.Diff(repo, option).Result(); var rs = null as object; + if (latest.FileModeDiff != null) + { + FileModeDiff = latest.FileModeDiff; + } + if (latest.TextDiff != null) { latest.TextDiff.File = _option.Path; @@ -180,5 +192,6 @@ namespace SourceGit.ViewModels private bool _isTextDiff = false; private object _content = null; private Vector _syncScrollOffset = Vector.Zero; + private Models.FileModeDiff _fileModeDiff = null; } } diff --git a/src/Views/DiffView.axaml b/src/Views/DiffView.axaml index 04fff7a9..571098c1 100644 --- a/src/Views/DiffView.axaml +++ b/src/Views/DiffView.axaml @@ -13,7 +13,7 @@ - + @@ -26,7 +26,14 @@ - + + + + + + + +