Skip to content

delete_file

delete_file(
    repository_name: RepositoryName,
    branch_name: BranchName,
    file_path: Path,
    parent_commit_id: CommitId,
    *,
    config_overrides: Optional[CodeCommitClientConfig] = None,
    keep_empty_folders: Optional[KeepEmptyFolders] = None,
    commit_message: Optional[Message] = None,
    name: Optional[Name] = None,
    email: Optional[Email] = None,
) -> DeleteFileOutput

Deletes a specified file from a specified branch. A commit is created on the branch that contains the revision. The file still exists in the commits earlier to the commit that contains the deletion.

Parameters:

  • repository_name (RepositoryName) –

    The name of the repository that contains the file to delete.

  • branch_name (BranchName) –

    The name of the branch where the commit that deletes the file is made.

  • file_path (Path) –

    The fully qualified path to the file that to be deleted, including the full name and extension of that file. For example, /examples/file.md is a fully qualified path to a file named file.md in a folder named examples.

  • parent_commit_id (CommitId) –

    The ID of the commit that is the tip of the branch where you want to create the commit that deletes the file. This must be the HEAD commit for the branch. The commit that deletes the file is created from this commit ID.

  • keep_empty_folders (Optional[KeepEmptyFolders], default: None ) –

    If a file is the only object in the folder or directory, specifies whether to delete the folder or directory that contains the file. By default, empty folders are deleted. This includes empty folders that are part of the directory structure. For example, if the path to a file is dir1/dir2/dir3/dir4, and dir2 and dir3 are empty, deleting the last file in dir4 also deletes the empty folders dir4, dir3, and dir2.

  • commit_message (Optional[Message], default: None ) –

    The commit message you want to include as part of deleting the file. Commit messages are limited to 256 KB. If no message is specified, a default message is used.

  • name (Optional[Name], default: None ) –

    The name of the author of the commit that deletes the file. If no name is specified, the user's ARN is used as the author name and committer name.

  • email (Optional[Email], default: None ) –

    The email address for the commit that deletes the file. If no email address is specified, the email address is left blank.

Raises:

Source code in docs_src/capo_codecommit/_services/code_commit.py
def delete_file(
    self,
    repository_name: "capo_codecommit.types.repository_name.RepositoryName",
    branch_name: "capo_codecommit.types.branch_name.BranchName",
    file_path: "capo_codecommit.types.path.Path",
    parent_commit_id: "capo_codecommit.types.commit_id.CommitId",
    *,
    config_overrides: Optional[CodeCommitClientConfig] = None,
    keep_empty_folders: Optional[
        "capo_codecommit.types.keep_empty_folders.KeepEmptyFolders"
    ] = None,
    commit_message: Optional["capo_codecommit.types.message.Message"] = None,
    name: Optional["capo_codecommit.types.name.Name"] = None,
    email: Optional["capo_codecommit.types.email.Email"] = None,
) -> "capo_codecommit.types.delete_file_output.DeleteFileOutput":
    """<p>Deletes a specified file from a specified branch. A commit is created on the branch that contains the revision. The file still exists in the commits earlier to the commit that contains the deletion.</p>

    Args:
        repository_name: <p>The name of the repository that contains the file to delete.</p>
        branch_name: <p>The name of the branch where the commit that deletes the file is made.</p>
        file_path: <p>The fully qualified path to the file that to be deleted, including the full name and extension of that file. For example, /examples/file.md is a fully qualified path to a file named file.md in a folder named examples.</p>
        parent_commit_id: <p>The ID of the commit that is the tip of the branch where you want to create the commit that deletes the file. This must be the HEAD commit for the branch. The commit that deletes the file is created from this commit ID.</p>
        keep_empty_folders: <p>If a file is the only object in the folder or directory, specifies whether to delete the folder or directory that contains the file. By default, empty folders are deleted. This includes empty folders that are part of the directory structure. For example, if the path to a file is dir1/dir2/dir3/dir4, and dir2 and dir3 are empty, deleting the last file in dir4 also deletes the empty folders dir4, dir3, and dir2.</p>
        commit_message: <p>The commit message you want to include as part of deleting the file. Commit messages are limited to 256 KB. If no message is specified, a default message is used.</p>
        name: <p>The name of the author of the commit that deletes the file. If no name is specified, the user's ARN is used as the author name and committer name.</p>
        email: <p>The email address for the commit that deletes the file. If no email address is specified, the email address is left blank.</p>

    Raises:
        capo_codecommit.errors.branch_does_not_exist_exception.BranchDoesNotExistException: <p>The specified branch does not exist.</p>
        capo_codecommit.errors.branch_name_is_tag_name_exception.BranchNameIsTagNameException: <p>The specified branch name is not valid because it is a tag name. Enter the name of a branch in the repository. For a list of valid branch names, use <a>ListBranches</a>.</p>
        capo_codecommit.errors.branch_name_required_exception.BranchNameRequiredException: <p>A branch name is required, but was not specified.</p>
        capo_codecommit.errors.commit_message_length_exceeded_exception.CommitMessageLengthExceededException: <p>The commit message is too long. Provide a shorter string. </p>
        capo_codecommit.errors.encryption_integrity_checks_failed_exception.EncryptionIntegrityChecksFailedException: <p>An encryption integrity check failed.</p>
        capo_codecommit.errors.encryption_key_access_denied_exception.EncryptionKeyAccessDeniedException: <p>An encryption key could not be accessed.</p>
        capo_codecommit.errors.encryption_key_disabled_exception.EncryptionKeyDisabledException: <p>The encryption key is disabled.</p>
        capo_codecommit.errors.encryption_key_not_found_exception.EncryptionKeyNotFoundException: <p>No encryption key was found.</p>
        capo_codecommit.errors.encryption_key_unavailable_exception.EncryptionKeyUnavailableException: <p>The encryption key is not available.</p>
        capo_codecommit.errors.file_does_not_exist_exception.FileDoesNotExistException: <p>The specified file does not exist. Verify that you have used the correct file name, full path, and extension.</p>
        capo_codecommit.errors.invalid_branch_name_exception.InvalidBranchNameException: <p>The specified reference name is not valid.</p>
        capo_codecommit.errors.invalid_email_exception.InvalidEmailException: <p>The specified email address either contains one or more characters that are not allowed, or it exceeds the maximum number of characters allowed for an email address.</p>
        capo_codecommit.errors.invalid_parent_commit_id_exception.InvalidParentCommitIdException: <p>The parent commit ID is not valid. The commit ID cannot be empty, and must match the head commit ID for the branch of the repository where you want to add or update a file.</p>
        capo_codecommit.errors.invalid_path_exception.InvalidPathException: <p>The specified path is not valid.</p>
        capo_codecommit.errors.invalid_repository_name_exception.InvalidRepositoryNameException: <p>A specified repository name is not valid.</p> <note> <p>This exception occurs only when a specified repository name is not valid. Other exceptions occur when a required repository parameter is missing, or when a specified repository does not exist.</p> </note>
        capo_codecommit.errors.name_length_exceeded_exception.NameLengthExceededException: <p>The user name is not valid because it has exceeded the character limit for author names. </p>
        capo_codecommit.errors.parent_commit_does_not_exist_exception.ParentCommitDoesNotExistException: <p>The parent commit ID is not valid because it does not exist. The specified parent commit ID does not exist in the specified branch of the repository.</p>
        capo_codecommit.errors.parent_commit_id_outdated_exception.ParentCommitIdOutdatedException: <p>The file could not be added because the provided parent commit ID is not the current tip of the specified branch. To view the full commit ID of the current head of the branch, use <a>GetBranch</a>.</p>
        capo_codecommit.errors.parent_commit_id_required_exception.ParentCommitIdRequiredException: <p>A parent commit ID is required. To view the full commit ID of a branch in a repository, use <a>GetBranch</a> or a Git command (for example, git pull or git log).</p>
        capo_codecommit.errors.path_required_exception.PathRequiredException: <p>The folderPath for a location cannot be null.</p>
        capo_codecommit.errors.repository_does_not_exist_exception.RepositoryDoesNotExistException: <p>The specified repository does not exist.</p>
        capo_codecommit.errors.repository_name_required_exception.RepositoryNameRequiredException: <p>A repository name is required, but was not specified.</p>
        capo_codecommit.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_codecommit.types.delete_file_input.DeleteFileInput]",
    ) -> OperationResponse[
        "capo_codecommit.types.delete_file_output.DeleteFileOutput"
    ]:
        import capo_codecommit._operations.code_commit_20150413.delete_file

        output, http_response = (
            capo_codecommit._operations.code_commit_20150413.delete_file.delete_file(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteFile")
    )
    input_: capo_codecommit.types.delete_file_input.DeleteFileInput = {
        "repository_name": repository_name,
        "branch_name": branch_name,
        "file_path": file_path,
        "parent_commit_id": parent_commit_id,
    }
    if keep_empty_folders is not None:
        input_["keep_empty_folders"] = keep_empty_folders
    if commit_message is not None:
        input_["commit_message"] = commit_message
    if name is not None:
        input_["name"] = name
    if email is not None:
        input_["email"] = email

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output