Skip to content

Commit 1bb4d55

Browse files
authored
Merge pull request #69 from gadfly3173/feat/diff-file-mode
feat: show git file mode change if exist
2 parents a042945 + 54c9552 commit 1bb4d55

File tree

6 files changed

+55
-6
lines changed

6 files changed

+55
-6
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/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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44

55
using Avalonia;
6+
using Avalonia.Media;
67
using Avalonia.Media.Imaging;
78
using Avalonia.Threading;
89

@@ -66,6 +67,14 @@ 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+
76+
public TextTrimming PathTrimming { get; } = new TextLeadingPrefixTrimming("...", 20);
77+
6978
public DiffContext(string repo, Models.DiffOption option, DiffContext previous = null)
7079
{
7180
_repo = repo;
@@ -86,6 +95,11 @@ public DiffContext(string repo, Models.DiffOption option, DiffContext previous =
8695
var latest = new Commands.Diff(repo, option).Result();
8796
var rs = null as object;
8897

98+
if (latest.FileModeDiff != null)
99+
{
100+
FileModeDiff = latest.FileModeDiff;
101+
}
102+
89103
if (latest.TextDiff != null)
90104
{
91105
latest.TextDiff.File = _option.Path;
@@ -180,5 +194,6 @@ private Bitmap BitmapFromRevisionFile(string repo, string revision, string file)
180194
private bool _isTextDiff = false;
181195
private object _content = null;
182196
private Vector _syncScrollOffset = Vector.Zero;
197+
private Models.FileModeDiff _fileModeDiff = null;
183198
}
184199
}

src/Views/DiffView.axaml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@
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"/>
2020
<TextBlock Margin="8,0,0,0" Text=""/>
2121
</StackPanel>
2222

23-
<StackPanel Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center">
24-
<Path Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
25-
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath, Converter={x:Static c:PathConverters.TruncateIfTooLong}}" FontSize="11"/>
26-
<Path Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{DynamicResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
23+
<DockPanel Grid.Column="1" VerticalAlignment="Center">
24+
<Path DockPanel.Dock="Left" Width="12" Height="12" Data="{StaticResource Icons.File}" Margin="8,0,0,0"/>
25+
<TextBlock Classes="monospace" Margin="4,0,0,0" Text="{Binding FilePath}"
26+
TextTrimming="{Binding PathTrimming}" TextWrapping="NoWrap" HorizontalAlignment="Stretch" ToolTip.Tip="{Binding FilePath}" FontSize="11"/>
27+
<Path DockPanel.Dock="Right" Classes="rotating" Width="10" Height="10" Margin="8,0" Data="{StaticResource Icons.Loading}" IsVisible="{Binding IsLoading}"/>
28+
</DockPanel>
29+
30+
<StackPanel Grid.Column="2" Orientation="Horizontal" VerticalAlignment="Center" IsVisible="{Binding FileModeDiff, Converter={x:Static ObjectConverters.IsNotNull}}">
31+
<TextBlock Classes="monospace" Margin="8,0,0,0" Text="{DynamicResource Text.Diff.FileModeChanged}" FontSize="11"/>
32+
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.Old}" FontSize="11"/>
33+
<TextBlock Margin="4,0" Text=""/>
34+
<TextBlock Classes="monospace" Text="{Binding FileModeDiff.New}" FontSize="11"/>
2735
</StackPanel>
2836

29-
<StackPanel Grid.Column="2" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
37+
<StackPanel Grid.Column="3" Margin="32,0,0,0" Orientation="Horizontal" VerticalAlignment="Center">
3038
<ToggleButton Classes="line_path"
3139
Width="32" Height="18"
3240
Background="Transparent"

0 commit comments

Comments
 (0)