@@ -280,43 +280,19 @@ func (repo *Repository) GetPatch(base, head string, w io.Writer) error {
280
280
}
281
281
282
282
// GetFilesChangedBetween returns a list of all files that have been changed between the given commits
283
+ // If base is undefined empty SHA (zeros), it only returns the files changed in the head commit
283
284
func (repo * Repository ) GetFilesChangedBetween (base , head string ) ([]string , error ) {
284
- stdout , _ , err := NewCommand (repo .Ctx , "diff" , "--name-only" , "-z" ).AddDynamicArguments (base + ".." + head ).RunStdString (& RunOpts {Dir : repo .Path })
285
- if err != nil {
286
- return nil , err
287
- }
288
- split := strings .Split (stdout , "\000 " )
289
-
290
- // Because Git will always emit filenames with a terminal NUL ignore the last entry in the split - which will always be empty.
291
- if len (split ) > 0 {
292
- split = split [:len (split )- 1 ]
293
- }
294
-
295
- return split , err
296
- }
297
-
298
- // GetCommitFilesChanged get the changed file names of the specified commit
299
- func (repo * Repository ) GetCommitFilesChanged (commitID string ) ([]string , error ) {
300
- id , err := repo .ConvertToSHA1 (commitID )
301
- if err != nil {
302
- return nil , err
303
- }
304
- commit , err := repo .getCommit (id )
305
- if err != nil {
306
- return nil , err
307
- }
308
285
var stdout string
309
- if len (commit .Parents ) == 0 {
310
- // if the commit is the root commit, diff-tree cannot show the changed files
311
- // we need to use ls-tree in this case
312
- stdout , _ , err = NewCommand (repo .Ctx , "ls-tree" , "--name-only" , "-r" ).AddDynamicArguments (commitID ).RunStdString (& RunOpts {Dir : repo .Path })
286
+ var err error
287
+ if base == EmptySHA {
288
+ stdout , _ , err = NewCommand (repo .Ctx , "diff-tree" , "--name-only" , "--root" , "--no-commit-id" , "-r" , "-z" ).AddDynamicArguments (head ).RunStdString (& RunOpts {Dir : repo .Path })
313
289
} else {
314
- stdout , _ , err = NewCommand (repo .Ctx , "diff-tree " , "--no-commit-id" , "-- name-only" , "-r " ).AddDynamicArguments (commitID ).RunStdString (& RunOpts {Dir : repo .Path })
290
+ stdout , _ , err = NewCommand (repo .Ctx , "diff" , "--name-only" , "-z " ).AddDynamicArguments (base + ".." + head ).RunStdString (& RunOpts {Dir : repo .Path })
315
291
}
316
292
if err != nil {
317
293
return nil , err
318
294
}
319
- split := strings .Split (stdout , "\n " )
295
+ split := strings .Split (stdout , "\000 " )
320
296
321
297
// Because Git will always emit filenames with a terminal NUL ignore the last entry in the split - which will always be empty.
322
298
if len (split ) > 0 {
0 commit comments