@@ -11,20 +11,29 @@ public partial class QueryStagedChangesWithAmend : Command
1111 [ GeneratedRegex ( @"^:[\d]{6} ([\d]{6}) ([0-9a-f]{4,64}) [0-9a-f]{4,64} ([RC])\d{0,6}\t(.*\t.*)$" ) ]
1212 private static partial Regex REG_FORMAT2 ( ) ;
1313
14- public QueryStagedChangesWithAmend ( string repo , string parent )
14+ public QueryStagedChangesWithAmend ( string repo )
1515 {
1616 WorkingDirectory = repo ;
1717 Context = repo ;
18- Args = $ "diff-index --cached -M { parent } ";
19- _parent = parent ;
2018 }
2119
2220 public List < Models . Change > GetResult ( )
2321 {
22+ Args = "show --no-show-signature --format=\" %H %P\" -s HEAD" ;
2423 var rs = ReadToEnd ( ) ;
2524 if ( ! rs . IsSuccess )
2625 return [ ] ;
2726
27+ var shas = rs . StdOut . Trim ( ) . Split ( ' ' , StringSplitOptions . RemoveEmptyEntries ) ;
28+ if ( shas . Length == 0 )
29+ return [ ] ;
30+
31+ var parent = shas . Length > 1 ? shas [ 1 ] : Models . EmptyTreeHash . Guess ( shas [ 0 ] ) ;
32+ Args = $ "diff-index --cached -M { parent } ";
33+ rs = ReadToEnd ( ) ;
34+ if ( ! rs . IsSuccess )
35+ return [ ] ;
36+
2837 var changes = new List < Models . Change > ( ) ;
2938 var lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
3039 foreach ( var line in lines )
@@ -39,7 +48,7 @@ public QueryStagedChangesWithAmend(string repo, string parent)
3948 {
4049 FileMode = match . Groups [ 1 ] . Value ,
4150 ObjectHash = match . Groups [ 2 ] . Value ,
42- ParentSHA = _parent ,
51+ ParentSHA = parent ,
4352 } ,
4453 } ;
4554 var type = match . Groups [ 3 ] . Value ;
@@ -58,7 +67,7 @@ public QueryStagedChangesWithAmend(string repo, string parent)
5867 {
5968 FileMode = match . Groups [ 1 ] . Value ,
6069 ObjectHash = match . Groups [ 2 ] . Value ,
61- ParentSHA = _parent ,
70+ ParentSHA = parent ,
6271 } ,
6372 } ;
6473
@@ -84,7 +93,5 @@ public QueryStagedChangesWithAmend(string repo, string parent)
8493
8594 return changes ;
8695 }
87-
88- private readonly string _parent ;
8996 }
9097}
0 commit comments