@@ -370,14 +370,13 @@ func (err ErrSHAOrCommitIDNotProvided) Error() string {
370
370
371
371
// handles the check for various issues for ChangeRepoFiles
372
372
func handleCheckErrors (file * ChangeRepoFile , commit * git.Commit , opts * ChangeRepoFilesOptions ) error {
373
- // FIXME: should it also handle "rename" errors?
374
- if file .Operation == "update" || file .Operation == "delete" {
373
+ if file .Operation == "update" || file .Operation == "delete" || file .Operation == "rename" {
375
374
fromEntry , err := commit .GetTreeEntryByPath (file .Options .fromTreePath )
376
375
if err != nil {
377
376
return err
378
377
}
379
378
if file .SHA != "" {
380
- // If a SHA was given and the SHA given doesn't match the SHA of the fromTreePath, throw error
379
+ // If the SHA given doesn't match the SHA of the fromTreePath, throw error
381
380
if file .SHA != fromEntry .ID .String () {
382
381
return pull_service.ErrSHADoesNotMatch {
383
382
Path : file .Options .treePath ,
@@ -386,7 +385,7 @@ func handleCheckErrors(file *ChangeRepoFile, commit *git.Commit, opts *ChangeRep
386
385
}
387
386
}
388
387
} else if opts .LastCommitID != "" {
389
- // If a lastCommitID was given and it doesn't match the commitID of the head of the branch throw
388
+ // If a lastCommitID given doesn't match the branch head's commitID throw
390
389
// an error, but only if we aren't creating a new branch.
391
390
if commit .ID .String () != opts .LastCommitID && opts .OldBranch == opts .NewBranch {
392
391
if changed , err := commit .FileChangedSinceCommit (file .Options .treePath , opts .LastCommitID ); err != nil {
@@ -404,15 +403,14 @@ func handleCheckErrors(file *ChangeRepoFile, commit *git.Commit, opts *ChangeRep
404
403
// haven't been made. We throw an error if one wasn't provided.
405
404
return ErrSHAOrCommitIDNotProvided {}
406
405
}
406
+ // FIXME: legacy hacky approach, it shouldn't prepare the "Options" in the "check" function
407
407
file .Options .executable = fromEntry .IsExecutable ()
408
408
}
409
409
410
- // FIXME: should it also handle "rename" errors?
411
- if file .Operation == "create" || file .Operation == "update" {
412
- // For the path where this file will be created/updated, we need to make
413
- // sure no parts of the path are existing files or links except for the last
414
- // item in the path which is the file name, and that shouldn't exist IF it is
415
- // a new file OR is being moved to a new path.
410
+ if file .Operation == "create" || file .Operation == "update" || file .Operation == "rename" {
411
+ // For operation's target path, we need to make sure no parts of the path are existing files or links
412
+ // except for the last item in the path (which is the file name).
413
+ // And that shouldn't exist IF it is a new file OR is being moved to a new path.
416
414
treePathParts := strings .Split (file .Options .treePath , "/" )
417
415
subTreePath := ""
418
416
for index , part := range treePathParts {
@@ -449,7 +447,7 @@ func handleCheckErrors(file *ChangeRepoFile, commit *git.Commit, opts *ChangeRep
449
447
Type : git .EntryModeTree ,
450
448
}
451
449
} else if file .Options .fromTreePath != file .Options .treePath || file .Operation == "create" {
452
- // The entry shouldn't exist if we are creating new file or moving to a new path
450
+ // The entry shouldn't exist if we are creating the new file or moving to a new path
453
451
return ErrRepoFileAlreadyExists {
454
452
Path : file .Options .treePath ,
455
453
}
0 commit comments