@ -228,6 +228,9 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
// This is where we handle all the errors thrown by repofiles.CreateOrUpdateRepoFile
// This is where we handle all the errors thrown by repofiles.CreateOrUpdateRepoFile
if git . IsErrNotExist ( err ) {
if git . IsErrNotExist ( err ) {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_editing_no_longer_exists" , ctx . Repo . TreePath ) , tplEditFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_editing_no_longer_exists" , ctx . Repo . TreePath ) , tplEditFile , & form )
} else if models . IsErrLFSFileLocked ( err ) {
ctx . Data [ "Err_TreePath" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.upload_file_is_locked" , err . ( models . ErrLFSFileLocked ) . Path , err . ( models . ErrLFSFileLocked ) . UserName ) , tplEditFile , & form )
} else if models . IsErrFilenameInvalid ( err ) {
} else if models . IsErrFilenameInvalid ( err ) {
ctx . Data [ "Err_TreePath" ] = true
ctx . Data [ "Err_TreePath" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.filename_is_invalid" , form . TreePath ) , tplEditFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.filename_is_invalid" , form . TreePath ) , tplEditFile , & form )
@ -265,10 +268,12 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
} else {
} else {
ctx . Error ( 500 , err . Error ( ) )
ctx . Error ( 500 , err . Error ( ) )
}
}
} else if models . IsErrCommitIDDoesNotMatch ( err ) || models . IsErrMergePushOutOfDate ( err ) {
} else if models . IsErrCommitIDDoesNotMatch ( err ) {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_changed_while_editing" , ctx . Repo . RepoLink + "/compare/" + form . LastCommit + "..." + ctx . Repo . CommitID ) , tplEditFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_changed_while_editing" , ctx . Repo . RepoLink + "/compare/" + form . LastCommit + "..." + ctx . Repo . CommitID ) , tplEditFile , & form )
} else if models . IsErrPushRejected ( err ) {
} else if git . IsErrPushOutOfDate ( err ) {
errPushRej := err . ( models . ErrPushRejected )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_changed_while_editing" , ctx . Repo . RepoLink + "/compare/" + form . LastCommit + "..." + form . NewBranchName ) , tplEditFile , & form )
} else if git . IsErrPushRejected ( err ) {
errPushRej := err . ( * git . ErrPushRejected )
if len ( errPushRej . Message ) == 0 {
if len ( errPushRej . Message ) == 0 {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.push_rejected_no_message" ) , tplEditFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.push_rejected_no_message" ) , tplEditFile , & form )
} else {
} else {
@ -436,10 +441,10 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
} else {
} else {
ctx . Error ( 500 , err . Error ( ) )
ctx . Error ( 500 , err . Error ( ) )
}
}
} else if models . IsErrCommitIDDoesNotMatch ( err ) || models . IsErrMerge PushOutOfDate ( err ) {
} else if models . IsErrCommitIDDoesNotMatch ( err ) || git . IsErrPushOutOfDate ( err ) {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_changed_while_deleting" , ctx . Repo . RepoLink + "/compare/" + form . LastCommit + "..." + ctx . Repo . CommitID ) , tplDeleteFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_changed_while_deleting" , ctx . Repo . RepoLink + "/compare/" + form . LastCommit + "..." + ctx . Repo . CommitID ) , tplDeleteFile , & form )
} else if models . IsErrPushRejected ( err ) {
} else if git . IsErrPushRejected ( err ) {
errPushRej := err . ( models . ErrPushRejected )
errPushRej := err . ( * git . ErrPushRejected )
if len ( errPushRej . Message ) == 0 {
if len ( errPushRej . Message ) == 0 {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.push_rejected_no_message" ) , tplDeleteFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.push_rejected_no_message" ) , tplDeleteFile , & form )
} else {
} else {
@ -602,10 +607,48 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
Message : message ,
Message : message ,
Files : form . Files ,
Files : form . Files ,
} ) ; err != nil {
} ) ; err != nil {
ctx . Data [ "Err_TreePath" ] = true
if models . IsErrLFSFileLocked ( err ) {
if models . IsErrLFSFileLocked ( err ) {
ctx . Data [ "Err_TreePath" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.upload_file_is_locked" , err . ( models . ErrLFSFileLocked ) . Path , err . ( models . ErrLFSFileLocked ) . UserName ) , tplUploadFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.upload_file_is_locked" , err . ( models . ErrLFSFileLocked ) . Path , err . ( models . ErrLFSFileLocked ) . UserName ) , tplUploadFile , & form )
} else if models . IsErrFilenameInvalid ( err ) {
ctx . Data [ "Err_TreePath" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.filename_is_invalid" , form . TreePath ) , tplUploadFile , & form )
} else if models . IsErrFilePathInvalid ( err ) {
ctx . Data [ "Err_TreePath" ] = true
fileErr := err . ( models . ErrFilePathInvalid )
switch fileErr . Type {
case git . EntryModeSymlink :
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_is_a_symlink" , fileErr . Path ) , tplUploadFile , & form )
case git . EntryModeTree :
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.filename_is_a_directory" , fileErr . Path ) , tplUploadFile , & form )
case git . EntryModeBlob :
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.directory_is_a_file" , fileErr . Path ) , tplUploadFile , & form )
default :
ctx . Error ( 500 , err . Error ( ) )
}
} else if models . IsErrRepoFileAlreadyExists ( err ) {
ctx . Data [ "Err_TreePath" ] = true
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_already_exists" , form . TreePath ) , tplUploadFile , & form )
} else if git . IsErrBranchNotExist ( err ) {
branchErr := err . ( git . ErrBranchNotExist )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.branch_does_not_exist" , branchErr . Name ) , tplUploadFile , & form )
} else if models . IsErrBranchAlreadyExists ( err ) {
// For when a user specifies a new branch that already exists
ctx . Data [ "Err_NewBranchName" ] = true
branchErr := err . ( models . ErrBranchAlreadyExists )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.branch_already_exists" , branchErr . BranchName ) , tplUploadFile , & form )
} else if git . IsErrPushOutOfDate ( err ) {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.file_changed_while_editing" , ctx . Repo . RepoLink + "/compare/" + ctx . Repo . CommitID + "..." + form . NewBranchName ) , tplUploadFile , & form )
} else if git . IsErrPushRejected ( err ) {
errPushRej := err . ( * git . ErrPushRejected )
if len ( errPushRej . Message ) == 0 {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.push_rejected_no_message" ) , tplUploadFile , & form )
} else {
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.push_rejected" , utils . SanitizeFlashErrorString ( errPushRej . Message ) ) , tplUploadFile , & form )
}
} else {
} else {
// os.ErrNotExist - upload file missing in the intervening time?!
log . Error ( "Error during upload to repo: %-v to filepath: %s on %s from %s: %v" , ctx . Repo . Repository , form . TreePath , oldBranchName , form . NewBranchName , err )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.unable_to_upload_files" , form . TreePath , err ) , tplUploadFile , & form )
ctx . RenderWithErr ( ctx . Tr ( "repo.editor.unable_to_upload_files" , form . TreePath , err ) , tplUploadFile , & form )
}
}
return
return