From 7f8372f6b57a15eda2e7ac1f8925e080891ff632 Mon Sep 17 00:00:00 2001 From: GadflyFang Date: Mon, 3 Mar 2025 10:38:58 +0800 Subject: [PATCH] enhance: Handle file mode changes for new/deleted file (#1040) --- src/Commands/Diff.cs | 12 ++++++++++++ src/Models/DiffResult.cs | 14 +++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Commands/Diff.cs b/src/Commands/Diff.cs index da971e58..8ae6350f 100644 --- a/src/Commands/Diff.cs +++ b/src/Commands/Diff.cs @@ -68,6 +68,18 @@ namespace SourceGit.Commands return; } + if (line.StartsWith("deleted file mode ", StringComparison.Ordinal)) + { + _result.OldMode = line.Substring(18); + return; + } + + if (line.StartsWith("new file mode ", StringComparison.Ordinal)) + { + _result.NewMode = line.Substring(14); + return; + } + if (_result.IsBinary) return; diff --git a/src/Models/DiffResult.cs b/src/Models/DiffResult.cs index e0ae82e0..88992e10 100644 --- a/src/Models/DiffResult.cs +++ b/src/Models/DiffResult.cs @@ -681,6 +681,18 @@ namespace SourceGit.Models public TextDiff TextDiff { get; set; } = null; public LFSDiff LFSDiff { get; set; } = null; - public string FileModeChange => string.IsNullOrEmpty(OldMode) ? string.Empty : $"{OldMode} → {NewMode}"; + public string FileModeChange + { + get + { + if (string.IsNullOrEmpty(OldMode) && string.IsNullOrEmpty(NewMode)) + return string.Empty; + + var oldDisplay = string.IsNullOrEmpty(OldMode) ? "0" : OldMode; + var newDisplay = string.IsNullOrEmpty(NewMode) ? "0" : NewMode; + + return $"{oldDisplay} → {newDisplay}"; + } + } } }