Skip to content

Commit

Permalink
Merge pull request #23 from ubisoft/misc-fixes
Browse files Browse the repository at this point in the history
Misc fixes
  • Loading branch information
LaurentM-Ubi authored Aug 2, 2024
2 parents 7dea52d + 4a32ff9 commit 990050d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion GitTimelapseView.Core/Models/Commit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void UpdateInfo(ILogger logger)
var changes = repository.Diff.Compare<TreeChanges>(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));
}
}

Expand Down
6 changes: 3 additions & 3 deletions GitTimelapseView.Core/Models/FileChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 6 additions & 2 deletions GitTimelapseView.Core/Models/FileHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -112,7 +116,7 @@ private IReadOnlyList<FileCommitId> 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 }));
Expand Down
13 changes: 7 additions & 6 deletions GitTimelapseView/Actions/DiffFileChangeAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 990050d

Please sign in to comment.