From 78f480987544001cbb4459a6901929d49a7b7e8c Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 22 Apr 2025 19:04:40 +0800 Subject: [PATCH] fix: no changes were displayed when try to amend a commit without parent (branch first commit) (#1231) Signed-off-by: leo --- src/Commands/QueryStagedChangesWithAmend.cs | 4 ++-- src/ViewModels/WorkingCopy.cs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Commands/QueryStagedChangesWithAmend.cs b/src/Commands/QueryStagedChangesWithAmend.cs index cfea5e35..93dcdb37 100644 --- a/src/Commands/QueryStagedChangesWithAmend.cs +++ b/src/Commands/QueryStagedChangesWithAmend.cs @@ -11,11 +11,11 @@ namespace SourceGit.Commands [GeneratedRegex(@"^:[\d]{6} ([\d]{6}) ([0-9a-f]{40}) [0-9a-f]{40} R\d{0,6}\t(.*\t.*)$")] private static partial Regex REG_FORMAT2(); - public QueryStagedChangesWithAmend(string repo) + public QueryStagedChangesWithAmend(string repo, string parent) { WorkingDirectory = repo; Context = repo; - Args = "diff-index --cached -M HEAD^"; + Args = $"diff-index --cached -M {parent}"; } public List Result() diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index ef6f0996..906248eb 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1524,7 +1524,10 @@ namespace SourceGit.ViewModels private List GetStagedChanges() { if (_useAmend) - return new Commands.QueryStagedChangesWithAmend(_repo.FullPath).Result(); + { + var head = new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").Result(); + return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : "HEAD^").Result(); + } var rs = new List(); foreach (var c in _cached)