enhance: Handle file mode changes for new/deleted file (#1040)

This commit is contained in:
GadflyFang 2025-03-03 10:38:58 +08:00 committed by GitHub
parent 4c63c4c90d
commit 7f8372f6b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View file

@ -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;

View file

@ -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}";
}
}
}
}