@@ -370,14 +370,13 @@ func (err ErrSHAOrCommitIDNotProvided) Error() string {
370370
371371// handles the check for various issues for ChangeRepoFiles
372372func 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" {
375374 fromEntry , err := commit .GetTreeEntryByPath (file .Options .fromTreePath )
376375 if err != nil {
377376 return err
378377 }
379378 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
381380 if file .SHA != fromEntry .ID .String () {
382381 return pull_service.ErrSHADoesNotMatch {
383382 Path : file .Options .treePath ,
@@ -386,7 +385,7 @@ func handleCheckErrors(file *ChangeRepoFile, commit *git.Commit, opts *ChangeRep
386385 }
387386 }
388387 } 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
390389 // an error, but only if we aren't creating a new branch.
391390 if commit .ID .String () != opts .LastCommitID && opts .OldBranch == opts .NewBranch {
392391 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
404403 // haven't been made. We throw an error if one wasn't provided.
405404 return ErrSHAOrCommitIDNotProvided {}
406405 }
406+ // FIXME: legacy hacky approach, it shouldn't prepare the "Options" in the "check" function
407407 file .Options .executable = fromEntry .IsExecutable ()
408408 }
409409
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.
416414 treePathParts := strings .Split (file .Options .treePath , "/" )
417415 subTreePath := ""
418416 for index , part := range treePathParts {
@@ -449,7 +447,7 @@ func handleCheckErrors(file *ChangeRepoFile, commit *git.Commit, opts *ChangeRep
449447 Type : git .EntryModeTree ,
450448 }
451449 } 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
453451 return ErrRepoFileAlreadyExists {
454452 Path : file .Options .treePath ,
455453 }
@@ -501,7 +499,7 @@ func CreateUpdateRenameFile(ctx context.Context, t *TemporaryUploadRepository, f
501499 return err
502500 }
503501
504- // Add the object to the index
502+ // Add the object to the index, the "file.Options.executable" is set in handleCheckErrors by the caller (legacy hacky approach)
505503 if err = t .AddObjectToIndex (ctx , util .Iif (file .Options .executable , "100755" , "100644" ), writeObjectRet .ObjectHash , file .Options .treePath ); err != nil {
506504 return err
507505 }
0 commit comments