From 70ffe9ac7178bf17ca3c3d1885bedbfa624fa3d2 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Thu, 29 May 2025 15:39:44 +0800 Subject: [PATCH] fix: rename change diff --- src/ViewModels/FileHistories.cs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/FileHistories.cs b/src/ViewModels/FileHistories.cs index ae6776ff..2d1defd6 100644 --- a/src/ViewModels/FileHistories.cs +++ b/src/ViewModels/FileHistories.cs @@ -153,8 +153,24 @@ namespace SourceGit.ViewModels { var revisionFilePath = new Commands.QueryFilePathInRevision(_repo.FullPath, _revision.SHA, _file).Result(); - var option = new Models.DiffOption(_revision, revisionFilePath); - ViewContent = new DiffContext(_repo.FullPath, option, _viewContent as DiffContext); + if (_revision.Parents.Count > 0) + { + var parentSHA = _revision.Parents[0]; + var changes = new Commands.CompareRevisions(_repo.FullPath, parentSHA, _revision.SHA).Result(); + foreach (var change in changes) + { + if ((change.WorkTree == Models.ChangeState.Renamed || change.Index == Models.ChangeState.Renamed) + && change.Path == revisionFilePath) + { + var option = new Models.DiffOption(parentSHA, _revision.SHA, change); + ViewContent = new DiffContext(_repo.FullPath, option, _viewContent as DiffContext); + return; + } + } + } + + var defaultOption = new Models.DiffOption(_revision, revisionFilePath); + ViewContent = new DiffContext(_repo.FullPath, defaultOption, _viewContent as DiffContext); } [GeneratedRegex(@"^version https://git-lfs.github.com/spec/v\d+\r?\noid sha256:([0-9a-f]+)\r?\nsize (\d+)[\r\n]*$")]