diff --git a/src/Commands/CompareRevisions.cs b/src/Commands/CompareRevisions.cs index 860cd34a..c4674c8e 100644 --- a/src/Commands/CompareRevisions.cs +++ b/src/Commands/CompareRevisions.cs @@ -13,7 +13,9 @@ namespace SourceGit.Commands { WorkingDirectory = repo; Context = repo; - Args = $"diff --name-status {start} {end}"; + + var based = string.IsNullOrEmpty(start) ? "-R" : start; + Args = $"diff --name-status {based} {end}"; } public List Result() diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 6a5dcc74..38436fe3 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -6,7 +6,7 @@ using Avalonia.Media; namespace SourceGit.Models { - public class Commit: IObjectId + public class Commit { public static double OpacityForNotMerged { diff --git a/src/Models/CompareTargetWorktree.cs b/src/Models/CompareTargetWorktree.cs new file mode 100644 index 00000000..6505f408 --- /dev/null +++ b/src/Models/CompareTargetWorktree.cs @@ -0,0 +1,6 @@ +namespace SourceGit.Models +{ + public class CompareTargetWorktree + { + } +} diff --git a/src/Models/IObjectId.cs b/src/Models/IObjectId.cs deleted file mode 100644 index a812f871..00000000 --- a/src/Models/IObjectId.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SourceGit.Models -{ - public interface IObjectId - { - string SHA { get; } - } -} diff --git a/src/Models/Object.cs b/src/Models/Object.cs index c929b30c..119177ee 100644 --- a/src/Models/Object.cs +++ b/src/Models/Object.cs @@ -9,7 +9,7 @@ Commit, } - public class Object: IObjectId + public class Object { public string SHA { get; set; } public ObjectType Type { get; set; } diff --git a/src/Resources/Locales/en_US.axaml b/src/Resources/Locales/en_US.axaml index 8172242e..9efcc0e1 100644 --- a/src/Resources/Locales/en_US.axaml +++ b/src/Resources/Locales/en_US.axaml @@ -189,7 +189,7 @@ Increase Number of Visible Lines SELECT FILE TO VIEW CHANGES Show hidden symbols - Reverse Commits + Swap Open In Merge Tool Discard Changes All local changes in working copy. diff --git a/src/Resources/Locales/zh_CN.axaml b/src/Resources/Locales/zh_CN.axaml index 11015a88..cc4512cf 100644 --- a/src/Resources/Locales/zh_CN.axaml +++ b/src/Resources/Locales/zh_CN.axaml @@ -192,7 +192,7 @@ 增加可见的行数 请选择需要对比的文件 显示隐藏符号 - 反向提交 + 交换比对双方 使用外部比对工具查看 放弃更改确认 所有本地址未提交的修改。 diff --git a/src/Resources/Locales/zh_TW.axaml b/src/Resources/Locales/zh_TW.axaml index da6d0a9d..a5a68398 100644 --- a/src/Resources/Locales/zh_TW.axaml +++ b/src/Resources/Locales/zh_TW.axaml @@ -192,7 +192,7 @@ 增加可見的行數 請選擇需要對比的檔案 顯示隱藏符號 - 反向提交 + 交換比對雙方 使用外部比對工具檢視 放棄更改確認 所有本地址未提交的修改。 diff --git a/src/ViewModels/RevisionCompare.cs b/src/ViewModels/RevisionCompare.cs index d9940752..5f008bad 100644 --- a/src/ViewModels/RevisionCompare.cs +++ b/src/ViewModels/RevisionCompare.cs @@ -2,29 +2,26 @@ using System.Collections.Generic; using System.IO; using System.Threading.Tasks; + using Avalonia.Controls; using Avalonia.Threading; + using CommunityToolkit.Mvvm.ComponentModel; namespace SourceGit.ViewModels { - public sealed class CompareTargetWorktree : Models.IObjectId - { - public string SHA => string.Empty; - } - public class RevisionCompare : ObservableObject { - public Models.IObjectId StartPoint + public object StartPoint { - get; - private set; + get => _startPoint; + private set => SetProperty(ref _startPoint, value); } - public Models.IObjectId EndPoint + public object EndPoint { - get; - private set; + get => _endPoint; + private set => SetProperty(ref _endPoint, value); } public List VisibleChanges @@ -41,9 +38,14 @@ namespace SourceGit.ViewModels if (SetProperty(ref _selectedChanges, value)) { if (value != null && value.Count == 1) - DiffContext = new DiffContext(_repo, new Models.DiffOption(StartPoint.SHA, EndPoint?.SHA ?? string.Empty, value[0]), _diffContext); + { + var option = new Models.DiffOption(GetSHA(_startPoint), GetSHA(_endPoint), value[0]); + DiffContext = new DiffContext(_repo, option, _diffContext); + } else + { DiffContext = null; + } } } } @@ -69,16 +71,8 @@ namespace SourceGit.ViewModels public RevisionCompare(string repo, Models.Commit startPoint, Models.Commit endPoint) { _repo = repo; - StartPoint = startPoint; - - if (endPoint == null) - { - EndPoint = new CompareTargetWorktree(); - } - else - { - EndPoint = endPoint; - } + _startPoint = (object)startPoint ?? new Models.CompareTargetWorktree(); + _endPoint = (object)endPoint ?? new Models.CompareTargetWorktree(); Task.Run(Refresh); } @@ -86,6 +80,8 @@ namespace SourceGit.ViewModels public void Cleanup() { _repo = null; + _startPoint = null; + _endPoint = null; if (_changes != null) _changes.Clear(); if (_visibleChanges != null) @@ -102,6 +98,12 @@ namespace SourceGit.ViewModels repo?.NavigateToCommit(commitSHA); } + public void Swap() + { + (StartPoint, EndPoint) = (_endPoint, _startPoint); + Task.Run(Refresh); + } + public void ClearSearchFilter() { SearchFilter = string.Empty; @@ -120,7 +122,7 @@ namespace SourceGit.ViewModels diffWithMerger.Icon = App.CreateMenuIcon("Icons.OpenWith"); diffWithMerger.Click += (_, ev) => { - var opt = new Models.DiffOption(StartPoint.SHA, EndPoint?.SHA ?? string.Empty, change); + var opt = new Models.DiffOption(GetSHA(_startPoint), GetSHA(_endPoint), change); var toolType = Preference.Instance.ExternalMergeToolType; var toolPath = Preference.Instance.ExternalMergeToolPath; @@ -191,7 +193,7 @@ namespace SourceGit.ViewModels private void Refresh() { - _changes = new Commands.CompareRevisions(_repo, StartPoint.SHA, EndPoint?.SHA ?? string.Empty).Result(); + _changes = new Commands.CompareRevisions(_repo, GetSHA(_startPoint), GetSHA(_endPoint)).Result(); var visible = _changes; if (!string.IsNullOrWhiteSpace(_searchFilter)) @@ -207,14 +209,14 @@ namespace SourceGit.ViewModels Dispatcher.UIThread.Invoke(() => VisibleChanges = visible); } - public void Swap() + private string GetSHA(object obj) { - (StartPoint, EndPoint) = (EndPoint, StartPoint); - OnPropertyChanged(string.Empty); - Task.Run(Refresh); + return obj is Models.Commit commit ? commit.SHA : string.Empty; } private string _repo; + private object _startPoint = null; + private object _endPoint = null; private List _changes = null; private List _visibleChanges = null; private List _selectedChanges = null; diff --git a/src/Views/RevisionCompare.axaml b/src/Views/RevisionCompare.axaml index e25342bd..bb101ae3 100644 --- a/src/Views/RevisionCompare.axaml +++ b/src/Views/RevisionCompare.axaml @@ -10,16 +10,12 @@ x:Class="SourceGit.Views.RevisionCompare" x:DataType="vm:RevisionCompare" Background="{DynamicResource Brush.Window}"> - - + + - + @@ -32,8 +28,8 @@ - + + @@ -41,7 +37,9 @@ + + @@ -51,17 +49,12 @@ - + @@ -72,6 +65,7 @@ +