Skip to content

Commit 345ad06

Browse files
committed
refactor: diff for staged file with --amend enabled (#1231)
Signed-off-by: leo <[email protected]>
1 parent 78f4809 commit 345ad06

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/Commands/QueryStagedChangesWithAmend.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public QueryStagedChangesWithAmend(string repo, string parent)
1616
WorkingDirectory = repo;
1717
Context = repo;
1818
Args = $"diff-index --cached -M {parent}";
19+
_parent = parent;
1920
}
2021

2122
public List<Models.Change> Result()
@@ -37,6 +38,7 @@ public QueryStagedChangesWithAmend(string repo, string parent)
3738
{
3839
FileMode = match.Groups[1].Value,
3940
ObjectHash = match.Groups[2].Value,
41+
ParentSHA = _parent,
4042
},
4143
};
4244
change.Set(Models.ChangeState.Renamed);
@@ -54,6 +56,7 @@ public QueryStagedChangesWithAmend(string repo, string parent)
5456
{
5557
FileMode = match.Groups[1].Value,
5658
ObjectHash = match.Groups[2].Value,
59+
ParentSHA = _parent,
5760
},
5861
};
5962

@@ -88,5 +91,7 @@ public QueryStagedChangesWithAmend(string repo, string parent)
8891

8992
return [];
9093
}
94+
95+
private string _parent = string.Empty;
9196
}
9297
}

src/Models/Change.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ChangeDataForAmend
2626
{
2727
public string FileMode { get; set; } = "";
2828
public string ObjectHash { get; set; } = "";
29+
public string ParentSHA { get; set; } = "";
2930
}
3031

3132
public class Change

src/Models/DiffOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public DiffOption(Change change, bool isUnstaged)
4040
else
4141
{
4242
if (change.DataForAmend != null)
43-
_extra = "--cached HEAD^";
43+
_extra = $"--cached {change.DataForAmend.ParentSHA}";
4444
else
4545
_extra = "--cached";
4646

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,8 +1526,8 @@ public ContextMenu CreateContextForOpenAI()
15261526
if (_useAmend)
15271527
{
15281528
var head = new Commands.QuerySingleCommit(_repo.FullPath, "HEAD").Result();
1529-
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : "HEAD^").Result();
1530-
}
1529+
return new Commands.QueryStagedChangesWithAmend(_repo.FullPath, head.Parents.Count == 0 ? "4b825dc642cb6eb9a060e54bf8d69288fbee4904" : $"{head.SHA}^").Result();
1530+
}
15311531

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

0 commit comments

Comments
 (0)