Skip to content

Commit a249eed

Browse files
committed
feat: show git file mode change if exist
1 parent 2d5e048 commit a249eed

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed

src/Commands/Diff.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text.RegularExpressions;
4+
using SourceGit.Models;
45

56
namespace SourceGit.Commands
67
{
@@ -46,6 +47,22 @@ public Models.DiffResult Result()
4647

4748
protected override void OnReadline(string line)
4849
{
50+
if (line.StartsWith("old mode ", StringComparison.Ordinal))
51+
{
52+
_result.FileModeDiff ??= new FileModeDiff();
53+
54+
_result.FileModeDiff.Old = line.Substring(9);
55+
return;
56+
}
57+
58+
if (line.StartsWith("new mode ", StringComparison.Ordinal))
59+
{
60+
_result.FileModeDiff ??= new FileModeDiff();
61+
62+
_result.FileModeDiff.New = line.Substring(9);
63+
return;
64+
}
65+
4966
if (_result.IsBinary)
5067
return;
5168

src/Converters/ObjectConverters.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Avalonia.Data.Converters;
2+
3+
namespace SourceGit.Converters
4+
{
5+
public static class ObjectConverters
6+
{
7+
public static readonly FuncValueConverter<object, bool> IsNull =
8+
new FuncValueConverter<object, bool>(v => v == null);
9+
10+
public static readonly FuncValueConverter<object, bool> IsNotNull =
11+
new FuncValueConverter<object, bool>(v => v != null);
12+
}
13+
}

src/Models/DiffResult.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,11 +576,18 @@ public class NoOrEOLChange
576576
{
577577
}
578578

579+
public class FileModeDiff
580+
{
581+
public string Old { get; set; } = string.Empty;
582+
public string New { get; set; } = string.Empty;
583+
}
584+
579585
public class DiffResult
580586
{
581587
public bool IsBinary { get; set; } = false;
582588
public bool IsLFS { get; set; } = false;
583589
public TextDiff TextDiff { get; set; } = null;
584590
public LFSDiff LFSDiff { get; set; } = null;
591+
public FileModeDiff FileModeDiff { get; set; } = null;
585592
}
586593
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">NEW</x:String>
132132
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">OLD</x:String>
133133
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copy</x:String>
134+
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed :</x:String>
134135
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJECT CHANGE</x:String>
135136
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Next Difference</x:String>
136137
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">NO CHANGES OR ONLY EOL CHANGES</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
<x:String x:Key="Text.Diff.Binary.New" xml:space="preserve">当前大小</x:String>
132132
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">原始大小</x:String>
133133
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">复制</x:String>
134+
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化 :</x:String>
134135
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS对象变更</x:String>
135136
<x:String x:Key="Text.Diff.Next" xml:space="preserve">下一个差异</x:String>
136137
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">没有变更或仅有换行符差异</x:String>

src/ViewModels/DiffContext.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Avalonia.Threading;
88

99
using CommunityToolkit.Mvvm.ComponentModel;
10+
using SourceGit.Models;
1011

1112
namespace SourceGit.ViewModels
1213
{
@@ -66,6 +67,12 @@ public Vector SyncScrollOffset
6667
set => SetProperty(ref _syncScrollOffset, value);
6768
}
6869

70+
public Models.FileModeDiff FileModeDiff
71+
{
72+
get => _fileModeDiff;
73+
set => SetProperty(ref _fileModeDiff, value);
74+
}
75+
6976
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
7077
{
7178
_repo = repo;
@@ -86,6 +93,11 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
8693
var latest = new Commands.Diff(repo, option).Result();
8794
var rs = null as object;
8895

96+
if (latest.FileModeDiff != null)
97+
{
98+
FileModeDiff = latest.FileModeDiff;
99+
}
100+
89101
if (latest.TextDiff != null)
90102
{
91103
latest.TextDiff.File = _option.Path;
@@ -180,5 +192,6 @@ private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
180192
private bool _isTextDiff = false;
181193
private object _content = null;
182194
private Vector _syncScrollOffset = Vector.Zero;
195+
private Models.FileModeDiff _fileModeDiff = null;
183196
}
184197
}

src/Views/DiffView.axaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<Grid RowDefinitions="26,*">
1414
<!-- Toolbar -->
1515
<Border Grid.Row="0" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
16-
<Grid ColumnDefinitions="Auto,*,Auto">
16+
<Grid ColumnDefinitions="Auto,Auto,*,Auto">
1717
<StackPanel Grid.Column="0" Orientation="Horizontal" IsVisible="{Binding IsOrgFilePathVisible}" VerticalAlignment="Center">
1818
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
1919
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding OrgFilePath, Converter={x:Static c:PathConverters.TruncateIfTooLong}}" FontSize="11"/>
@@ -26,7 +26,14 @@
2626
<Path Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{DynamicResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
2727
</StackPanel>
2828

29-
<StackPanel Grid.Column="2" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
29+
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" IsVisible="{Binding FileModeDiff, Converter={x:Static c:ObjectConverters.IsNotNull}}">
30+
<TextBlock Classes="monospace" Margin="8,0,0,0" Text="{DynamicResource Text.Diff.FileModeChanged}" FontSize="11"/>
31+
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.Old}" FontSize="11"/>
32+
<TextBlock Margin="4,0" Text=""/>
33+
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.New}" FontSize="11"/>
34+
</StackPanel>
35+
36+
<StackPanel Grid.Column="3" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
3037
<ToggleButton Classes="line_path"
3138
Width="32" Height="18"
3239
Background="Transparent"

0 commit comments

Comments
 (0)