Skip to content

refactor: improve diff handling for EOL changes and enhance text diff… #1177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Commands/Diff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Diff(string repo, Models.DiffOption opt, int unified, bool ignoreWhitespa
if (ignoreWhitespace)
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --ignore-cr-at-eol --ignore-all-space --unified={unified} {opt}";
else
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --ignore-cr-at-eol --unified={unified} {opt}";
Args = $"-c core.autocrlf=false diff --no-ext-diff --patch --unified={unified} {opt}";
}

public Models.DiffResult Result()
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/de_DE.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">ALT</x:String>
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Kopieren</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">Dateimodus geändert</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignoriere Leerzeichenänderungen</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignoriere Leerzeichenänderungen und EOL</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJEKT ÄNDERUNG</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Nächste Änderung</x:String>
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">KEINE ÄNDERUNG ODER NUR ZEILEN-ENDE ÄNDERUNGEN</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copy</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">File Mode Changed</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">First Difference</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignore Whitespace Change</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignore Whitespace Change and EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">Last Difference</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS OBJECT CHANGE</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Next Difference</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/es_ES.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copiar</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">Modo de Archivo Cambiado</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">Primera Diferencia</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignorar Cambio de Espacios en Blanco</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignorar Cambio de Espacios en Blanco y EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">Última Diferencia</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">CAMBIO DE OBJETO LFS</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Siguiente Diferencia</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/fr_FR.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copier</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">Mode de fichier changé</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">Première différence</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignorer les changements d'espaces</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignorer les changements d'espaces et EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">Dernière différence</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">CHANGEMENT D'OBJET LFS</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Différence suivante</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/it_IT.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copia</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">Modalità File Modificata</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">Prima differenza</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignora Modifiche agli Spazi</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignora Modifiche agli Spazi e EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">Ultima differenza</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">MODIFICA OGGETTO LFS</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Differenza Successiva</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/ja_JP.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">コピー</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">ファイルモードが変更されました</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">先頭の差分</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">空白の変更を無視</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">空白の変更とEOLを無視</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">最後の差分</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFSオブジェクトの変更</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">次の差分</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/pt_BR.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<x:String x:Key="Text.Diff.Binary.Old" xml:space="preserve">ANTIGO</x:String>
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Copiar</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">Modo de Arquivo Alterado</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignorar mudanças de espaço em branco</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Ignorar mudanças de espaço em branco e EOL</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">MUDANÇA DE OBJETO LFS</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Próxima Diferença</x:String>
<x:String x:Key="Text.Diff.NoChange" xml:space="preserve">SEM MUDANÇAS OU APENAS MUDANÇAS DE EOL</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/ru_RU.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">Копировать</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">Режим файла изменён</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">Первое различие</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Игнорировать изменение пробелов</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">Игнорировать изменение пробелов и EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">Последнее различие</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">ИЗМЕНЕНИЕ ОБЪЕКТА LFS</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">Следующее различие</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/ta_IN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">நகல்</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">கோப்பு முறை மாற்றப்பட்டது</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">முதல் வேறுபாடு</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">வெள்ளைவெளி மாற்றத்தை புறக்கணி</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">வெள்ளைவெளி மாற்றத்தை மற்றும் EOL புறக்கணி</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">கடைசி வேறுபாடு</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">பெகோஅ பொருள் மாற்றம்</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">அடுத்த வேறுபாடு</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">复制</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">文件权限已变化</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">首个差异</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">忽略空白符号变化</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">忽略空白符号变化和EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">最后一个差异</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS对象变更</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">下一个差异</x:String>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
<x:String x:Key="Text.Diff.Copy" xml:space="preserve">複製</x:String>
<x:String x:Key="Text.Diff.FileModeChanged" xml:space="preserve">檔案權限已變更</x:String>
<x:String x:Key="Text.Diff.First" xml:space="preserve">第一個差異</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">忽略空白符號變化</x:String>
<x:String x:Key="Text.Diff.IgnoreWhitespace" xml:space="preserve">忽略空白符號變化和EOL</x:String>
<x:String x:Key="Text.Diff.Last" xml:space="preserve">最後一個差異</x:String>
<x:String x:Key="Text.Diff.LFS" xml:space="preserve">LFS 物件變更</x:String>
<x:String x:Key="Text.Diff.Next" xml:space="preserve">下一個差異</x:String>
Expand Down
45 changes: 44 additions & 1 deletion src/ViewModels/DiffContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,50 @@ private void LoadDiffContent()
}
else
{
rs = new Models.NoOrEOLChange();
// Check if old and new hashes differ but no text changes found
if (!string.IsNullOrEmpty(latest.OldHash) &&
!string.IsNullOrEmpty(latest.NewHash) &&
latest.OldHash != latest.NewHash)
{
// If hashes differ but no text diff found, it's likely an EOL change
// Create a text diff to show the file content
var textDiff = new Models.TextDiff()
{
Repo = _repo,
Option = _option,
File = _option.Path
};
// Query the file content to show
var fileContent = Commands.QueryFileContent.Run(_repo, "HEAD", _option.Path);
using var reader = new StreamReader(fileContent);
var line = string.Empty;
int lineNumber = 1;

while ((line = reader.ReadLine()) != null)
{
textDiff.Lines.Add(new Models.TextDiffLine(
Models.TextDiffLineType.Normal,
line,
lineNumber,
lineNumber));

lineNumber++;
}

if (textDiff.Lines.Count > 0)
{
textDiff.MaxLineNumber = lineNumber - 1;
rs = textDiff;
}
else
{
rs = new Models.NoOrEOLChange();
}
}
else
{
rs = new Models.NoOrEOLChange();
}
}

Dispatcher.UIThread.Post(() =>
Expand Down
1 change: 1 addition & 0 deletions src/Views/TextDiffView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
var val = ShowHiddenSymbols;
Options.ShowTabs = val;
Options.ShowSpaces = val;
Options.ShowEndOfLine = val;
}
else if (change.Property == TabWidthProperty)
{
Expand Down