From 4a32ff9873dbc8cab23bba53733d8e683e172106 Mon Sep 17 00:00:00 2001 From: Julien Richard Date: Fri, 2 Aug 2024 10:25:34 +0200 Subject: [PATCH] Misc fixes --- GitTimelapseView.Core/Models/Commit.cs | 2 +- GitTimelapseView.Core/Models/FileChange.cs | 6 +++--- GitTimelapseView.Core/Models/FileHistory.cs | 8 ++++++-- GitTimelapseView/Actions/DiffFileChangeAction.cs | 13 +++++++------ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/GitTimelapseView.Core/Models/Commit.cs b/GitTimelapseView.Core/Models/Commit.cs index 40ab123..8007157 100644 --- a/GitTimelapseView.Core/Models/Commit.cs +++ b/GitTimelapseView.Core/Models/Commit.cs @@ -64,7 +64,7 @@ public void UpdateInfo(ILogger logger) var changes = repository.Diff.Compare(parents.FirstOrDefault()?.Tree, commit?.Tree); foreach (var change in changes) { - _fileChanges.Add(new FileChange(this, change)); + _fileChanges.Add(new FileChange(this, change, repository.Info.WorkingDirectory)); } } diff --git a/GitTimelapseView.Core/Models/FileChange.cs b/GitTimelapseView.Core/Models/FileChange.cs index 57991f6..5bcbc8e 100644 --- a/GitTimelapseView.Core/Models/FileChange.cs +++ b/GitTimelapseView.Core/Models/FileChange.cs @@ -7,12 +7,12 @@ namespace GitTimelapseView.Core.Models { public sealed class FileChange { - public FileChange(Commit commit, TreeEntryChanges change) + public FileChange(Commit commit, TreeEntryChanges change, string workingDirectory) { Commit = commit; ChangeKind = change.Status; - Path = change.Path; - OldPath = change.OldPath; + Path = string.IsNullOrEmpty(change.Path) ? string.Empty : System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDirectory, change.Path)); + OldPath = string.IsNullOrEmpty(change.OldPath) ? string.Empty : System.IO.Path.GetFullPath(System.IO.Path.Combine(workingDirectory, change.OldPath)); Name = System.IO.Path.GetFileName(Path); } diff --git a/GitTimelapseView.Core/Models/FileHistory.cs b/GitTimelapseView.Core/Models/FileHistory.cs index f063a16..048cfa8 100644 --- a/GitTimelapseView.Core/Models/FileHistory.cs +++ b/GitTimelapseView.Core/Models/FileHistory.cs @@ -20,7 +20,11 @@ public FileHistory(string filePath) FilePath = filePath; try { - GitRootPath = Repository.Discover(filePath).Replace(@".git\", string.Empty, StringComparison.Ordinal); + var repositoryPath = Repository.Discover(filePath); + if (repositoryPath.Contains("\\.git\\modules\\", StringComparison.OrdinalIgnoreCase)) + GitRootPath = repositoryPath; + else + GitRootPath = repositoryPath.Replace(@".git\", string.Empty, StringComparison.Ordinal); } catch (Exception) { @@ -112,7 +116,7 @@ private IReadOnlyList GetFileCommitIDs(ILogger logger) if (commitIDs.Count > 1 && !isFirstTime) { - commitIDs.RemoveAt(0); + commitIDs.RemoveAt(commitIDs.Count - 1); } commitIDs.AddRange(result.Select(x => new FileCommitId { Commit = x, FilePath = filePath })); diff --git a/GitTimelapseView/Actions/DiffFileChangeAction.cs b/GitTimelapseView/Actions/DiffFileChangeAction.cs index 6198b16..28d1433 100644 --- a/GitTimelapseView/Actions/DiffFileChangeAction.cs +++ b/GitTimelapseView/Actions/DiffFileChangeAction.cs @@ -25,15 +25,16 @@ public DiffFileChangeAction(FileChange fileChange, string commitId) public override Task ExecuteAsync(IActionContext context) { - context.TrackingProperties["Path"] = _fileChange.Path; + var oldPath = _fileChange.OldPath; + var path = _fileChange.Path; + + context.TrackingProperties["Path"] = path; context.TrackingProperties["CommitId"] = _commitId; - context.LogInformation($"Diffing '{_fileChange.Path}' with commit '{_commitId}'"); - var oldPath = string.IsNullOrEmpty(_fileChange.OldPath) ? string.Empty : Path.GetFullPath(Path.Combine(_fileChange.Commit.FileHistory.GitRootPath, _fileChange.OldPath)); - var path = string.IsNullOrEmpty(_fileChange.Path) ? string.Empty : Path.GetFullPath(Path.Combine(_fileChange.Commit.FileHistory.GitRootPath, _fileChange.Path)); + context.LogInformation($"Diffing '{path}' with commit '{_commitId}'"); - var errorMessage = $"Could not launch difftool on {_fileChange.Path} for commit {_commitId}"; - var args = path.Equals(oldPath, System.StringComparison.OrdinalIgnoreCase) ? $"difftool -y {_commitId}^ {_commitId} {path}".Trim(' ') : $"difftool -y {_commitId}^ {_commitId} {oldPath} {path}".Trim(' '); + var errorMessage = $"Could not launch difftool on {path} for commit {_commitId}"; + var args = path.Equals(oldPath, StringComparison.OrdinalIgnoreCase) ? $"difftool -y {_commitId}^ {_commitId} {path}".Trim(' ') : $"difftool -y {_commitId}^ {_commitId} {oldPath} {path}".Trim(' '); GitHelpers.RunGitCommand(_fileChange.Commit.FileHistory.GitRootPath, args, context, errorMessage); return Task.CompletedTask;