Skip to content

Commit 7f8372f

Browse files
authored
enhance: Handle file mode changes for new/deleted file (#1040)
1 parent 4c63c4c commit 7f8372f

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Commands/Diff.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ protected override void OnReadline(string line)
6868
return;
6969
}
7070

71+
if (line.StartsWith("deleted file mode ", StringComparison.Ordinal))
72+
{
73+
_result.OldMode = line.Substring(18);
74+
return;
75+
}
76+
77+
if (line.StartsWith("new file mode ", StringComparison.Ordinal))
78+
{
79+
_result.NewMode = line.Substring(14);
80+
return;
81+
}
82+
7183
if (_result.IsBinary)
7284
return;
7385

src/Models/DiffResult.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,18 @@ public class DiffResult
681681
public TextDiff TextDiff { get; set; } = null;
682682
public LFSDiff LFSDiff { get; set; } = null;
683683

684-
public string FileModeChange => string.IsNullOrEmpty(OldMode) ? string.Empty : $"{OldMode}{NewMode}";
684+
public string FileModeChange
685+
{
686+
get
687+
{
688+
if (string.IsNullOrEmpty(OldMode) && string.IsNullOrEmpty(NewMode))
689+
return string.Empty;
690+
691+
var oldDisplay = string.IsNullOrEmpty(OldMode) ? "0" : OldMode;
692+
var newDisplay = string.IsNullOrEmpty(NewMode) ? "0" : NewMode;
693+
694+
return $"{oldDisplay}{newDisplay}";
695+
}
696+
}
685697
}
686698
}

0 commit comments

Comments
 (0)