Skip to content

Commit 78f4809

Browse files
committed
fix: no changes were displayed when try to amend a commit without parent (branch first commit) (#1231)
Signed-off-by: leo <[email protected]>
1 parent 87ebe37 commit 78f4809

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Commands/QueryStagedChangesWithAmend.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ public partial class QueryStagedChangesWithAmend : Command
1111
[GeneratedRegex(@"^:[\d]{6} ([\d]{6}) ([0-9a-f]{40}) [0-9a-f]{40} R\d{0,6}\t(.*\t.*)$")]
1212
private static partial Regex REG_FORMAT2();
1313

14-
public QueryStagedChangesWithAmend(string repo)
14+
public QueryStagedChangesWithAmend(string repo, string parent)
1515
{
1616
WorkingDirectory = repo;
1717
Context = repo;
18-
Args = "diff-index --cached -M HEAD^";
18+
Args = $"diff-index --cached -M {parent}";
1919
}
2020

2121
public List<Models.Change> Result()

src/ViewModels/WorkingCopy.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,10 @@ public ContextMenu CreateContextForOpenAI()
15241524
private List<Models.Change> GetStagedChanges()
15251525
{
15261526
if (_useAmend)
1527-
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath).Result();
1527+
{
1528+
var head = new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").Result();
1529+
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : "HEAD^").Result();
1530+
}
15281531

15291532
var rs = new List<Models.Change>();
15301533
foreach (var c in _cached)

0 commit comments

Comments
 (0)