@@ -28,6 +28,9 @@ type FilePatch struct {
2828 Chunks Chunks
2929}
3030
31+ const SRC_PREFIX = "caf67b1d-c9b7-44ba-9b85-bd94727547af"
32+ const DST_PREFIX = "7dcfe536-96a9-49c5-8b86-7caa3d9e5e9c"
33+
3134func Diff (rootDir , baseRef string ) ([]FilePatch , error ) {
3235 var result []FilePatch
3336
@@ -40,7 +43,8 @@ func Diff(rootDir, baseRef string) ([]FilePatch, error) {
4043 "--first-parent" ,
4144 "--find-renames" ,
4245 "--break-rewrites" ,
43- "--no-prefix" ,
46+ "--src-prefix=" + SRC_PREFIX ,
47+ "--dst-prefix=" + DST_PREFIX ,
4448 "--no-color" ,
4549 baseRef ,
4650 "--" ,
@@ -113,20 +117,40 @@ func parseDiff(scanner *linescanner.Scanner) ([]FilePatch, error) {
113117}
114118
115119func parseDiffHeader (value string ) (string , string , error ) {
116- parts := strings . Split (value , " " )
117- fromPath , err := unquoteFilename (parts [ 2 ] )
120+ rawFromPath , rawToPath := splitPaths (value )
121+ fromPath , err := unquoteFilename (rawFromPath )
118122 if err != nil {
119123 return "" , "" , fmt .Errorf ("error parsing header 'from' path: %w" , err )
120124 }
121125
122- toPath , err := unquoteFilename (parts [ 3 ] )
126+ toPath , err := unquoteFilename (rawToPath )
123127 if err != nil {
124128 return "" , "" , fmt .Errorf ("error parsing header 'to' path: %w" , err )
125129 }
126130
127131 return fromPath , toPath , nil
128132}
129133
134+ func splitPaths (value string ) (fromPath string , toPath string ) {
135+ split1 := strings .Split (value , SRC_PREFIX )[1 ]
136+ split2 := strings .Split (split1 , DST_PREFIX )
137+
138+ fromPath = strings .TrimSpace (split2 [0 ])
139+ toPath = strings .TrimSpace (split2 [1 ])
140+
141+ // handle trailing whitespaces and missing quotation marks
142+ // e.g. `foo\\t.txt \"`
143+ if strings .Contains (fromPath , "\" " ) {
144+ fromPath = "\" " + strings .TrimSpace (strings .ReplaceAll (fromPath , "\" " , "" )) + "\" "
145+ }
146+
147+ if strings .Contains (toPath , "\" " ) {
148+ toPath = "\" " + strings .ReplaceAll (toPath , "\" " , "" ) + "\" "
149+ }
150+
151+ return fromPath , toPath
152+ }
153+
130154func parseChunkHeader (value string ) (Chunk , error ) {
131155 parts := strings .Split (value , " " )
132156
0 commit comments