Skip to content

create_commit

create_commit(
    repository_name: RepositoryName,
    branch_name: BranchName,
    *,
    config_overrides: Optional[CodeCommitClientConfig] = None,
    parent_commit_id: Optional[CommitId] = None,
    author_name: Optional[Name] = None,
    email: Optional[Email] = None,
    commit_message: Optional[Message] = None,
    keep_empty_folders: Optional[KeepEmptyFolders] = None,
    put_files: Optional[PutFileEntries] = None,
    delete_files: Optional[DeleteFileEntries] = None,
    set_file_modes: Optional[SetFileModeEntries] = None,
) -> CreateCommitOutput

Creates a commit for a repository on the tip of a specified branch.

Parameters:

  • repository_name (RepositoryName) –

    The name of the repository where you create the commit.

  • branch_name (BranchName) –

    The name of the branch where you create the commit.

  • parent_commit_id (Optional[CommitId], default: None ) –

    The ID of the commit that is the parent of the commit you create. Not required if this is an empty repository.

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

    The name of the author who created the commit. This information is used as both the author and committer for the commit.

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

    The email address of the person who created the commit.

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

    The commit message you want to include in the commit. Commit messages are limited to 256 KB. If no message is specified, a default message is used.

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

    If the commit contains deletions, whether to keep a folder or folder structure if the changes leave the folders empty. If true, a ..gitkeep file is created for empty folders. The default is false.

  • put_files (Optional[PutFileEntries], default: None ) –

    The files to add or update in this commit.

  • delete_files (Optional[DeleteFileEntries], default: None ) –

    The files to delete in this commit. These files still exist in earlier commits.

  • set_file_modes (Optional[SetFileModeEntries], default: None ) –

    The file modes to update for files in this commit.

Raises:

Source code in docs_src/capo_codecommit/_services/code_commit.py
def create_commit(
    self,
    repository_name: "capo_codecommit.types.repository_name.RepositoryName",
    branch_name: "capo_codecommit.types.branch_name.BranchName",
    *,
    config_overrides: Optional[CodeCommitClientConfig] = None,
    parent_commit_id: Optional["capo_codecommit.types.commit_id.CommitId"] = None,
    author_name: Optional["capo_codecommit.types.name.Name"] = None,
    email: Optional["capo_codecommit.types.email.Email"] = None,
    commit_message: Optional["capo_codecommit.types.message.Message"] = None,
    keep_empty_folders: Optional[
        "capo_codecommit.types.keep_empty_folders.KeepEmptyFolders"
    ] = None,
    put_files: Optional[
        "capo_codecommit.types.put_file_entries.PutFileEntries"
    ] = None,
    delete_files: Optional[
        "capo_codecommit.types.delete_file_entries.DeleteFileEntries"
    ] = None,
    set_file_modes: Optional[
        "capo_codecommit.types.set_file_mode_entries.SetFileModeEntries"
    ] = None,
) -> "capo_codecommit.types.create_commit_output.CreateCommitOutput":
    """<p>Creates a commit for a repository on the tip of a specified branch.</p>

    Args:
        repository_name: <p>The name of the repository where you create the commit.</p>
        branch_name: <p>The name of the branch where you create the commit.</p>
        parent_commit_id: <p>The ID of the commit that is the parent of the commit you create. Not required if this is an empty repository.</p>
        author_name: <p>The name of the author who created the commit. This information is used as both the author and committer for the commit.</p>
        email: <p>The email address of the person who created the commit.</p>
        commit_message: <p>The commit message you want to include in the commit. Commit messages are limited to 256 KB. If no message is specified, a default message is used.</p>
        keep_empty_folders: <p>If the commit contains deletions, whether to keep a folder or folder structure if the changes leave the folders empty. If true, a ..gitkeep file is created for empty folders. The default is false.</p>
        put_files: <p>The files to add or update in this commit.</p>
        delete_files: <p>The files to delete in this commit. These files still exist in earlier commits.</p>
        set_file_modes: <p>The file modes to update for files in this commit.</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.directory_name_conflicts_with_file_name_exception.DirectoryNameConflictsWithFileNameException: <p>A file cannot be added to the repository because the specified path name has the same name as a file that already exists in this repository. Either provide a different name for the file, or specify a different path for the file.</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_content_and_source_file_specified_exception.FileContentAndSourceFileSpecifiedException: <p>The commit cannot be created because both a source file and file content have been specified for the same file. You cannot provide both. Either specify a source file or provide the file content directly.</p>
        capo_codecommit.errors.file_content_size_limit_exceeded_exception.FileContentSizeLimitExceededException: <p>The file cannot be added because it is too large. The maximum file size is 6 MB, and the combined file content change size is 7 MB. Consider making these changes using a Git client.</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.file_entry_required_exception.FileEntryRequiredException: <p>The commit cannot be created because no files have been specified as added, updated, or changed (PutFile or DeleteFile) for the commit.</p>
        capo_codecommit.errors.file_mode_required_exception.FileModeRequiredException: <p>The commit cannot be created because no file mode has been specified. A file mode is required to update mode permissions for a file.</p>
        capo_codecommit.errors.file_name_conflicts_with_directory_name_exception.FileNameConflictsWithDirectoryNameException: <p>A file cannot be added to the repository because the specified file name has the same name as a directory in this repository. Either provide another name for the file, or add the file in a directory that does not match the file name.</p>
        capo_codecommit.errors.file_path_conflicts_with_submodule_path_exception.FilePathConflictsWithSubmodulePathException: <p>The commit cannot be created because a specified file path points to a submodule. Verify that the destination files have valid file paths that do not point to a submodule.</p>
        capo_codecommit.errors.folder_content_size_limit_exceeded_exception.FolderContentSizeLimitExceededException: <p>The commit cannot be created because at least one of the overall changes in the commit results in a folder whose contents exceed the limit of 6 MB. Either reduce the number and size of your changes, or split the changes across multiple folders.</p>
        capo_codecommit.errors.invalid_branch_name_exception.InvalidBranchNameException: <p>The specified reference name is not valid.</p>
        capo_codecommit.errors.invalid_deletion_parameter_exception.InvalidDeletionParameterException: <p>The specified deletion parameter 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_file_mode_exception.InvalidFileModeException: <p>The specified file mode permission is not valid. For a list of valid file mode permissions, see <a>PutFile</a>. </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.maximum_file_entries_exceeded_exception.MaximumFileEntriesExceededException: <p>The number of specified files to change as part of this commit exceeds the maximum number of files that can be changed in a single commit. Consider using a Git client for these changes.</p>
        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.no_change_exception.NoChangeException: <p>The commit cannot be created because no changes will be made to the repository as a result of this commit. A commit must contain at least one change.</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.put_file_entry_conflict_exception.PutFileEntryConflictException: <p>The commit cannot be created because one or more files specified in the commit reference both a file and a folder.</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.restricted_source_file_exception.RestrictedSourceFileException: <p>The commit cannot be created because one of the changes specifies copying or moving a .gitkeep file.</p>
        capo_codecommit.errors.same_path_request_exception.SamePathRequestException: <p>The commit cannot be created because one or more changes in this commit duplicate actions in the same file path. For example, you cannot make the same delete request to the same file in the same file path twice, or make a delete request and a move request to the same file as part of the same commit.</p>
        capo_codecommit.errors.source_file_or_content_required_exception.SourceFileOrContentRequiredException: <p>The commit cannot be created because no source files or file content have been specified for the commit.</p>
        capo_codecommit.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_codecommit.types.create_commit_input.CreateCommitInput]",
    ) -> OperationResponse[
        "capo_codecommit.types.create_commit_output.CreateCommitOutput"
    ]:
        import capo_codecommit._operations.code_commit_20150413.create_commit

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateCommit")
    )
    input_: capo_codecommit.types.create_commit_input.CreateCommitInput = {
        "repository_name": repository_name,
        "branch_name": branch_name,
    }
    if parent_commit_id is not None:
        input_["parent_commit_id"] = parent_commit_id
    if author_name is not None:
        input_["author_name"] = author_name
    if email is not None:
        input_["email"] = email
    if commit_message is not None:
        input_["commit_message"] = commit_message
    if keep_empty_folders is not None:
        input_["keep_empty_folders"] = keep_empty_folders
    if put_files is not None:
        input_["put_files"] = put_files
    if delete_files is not None:
        input_["delete_files"] = delete_files
    if set_file_modes is not None:
        input_["set_file_modes"] = set_file_modes

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