Skip to content

dulwich disable empty commit #936

Answered by luckydonald
QGB asked this question in Q&A
Discussion options

You must be logged in to vote

In case of already using dulwich_tree, subclassing with this overwritten function includes that check:

If allow_empty_commits is False (default), it will check for the tree to be changed, and not commit in that case.

from dulwich_tree import TreeWriter


class TreeWriterNoEmptyCommits(TreeWriter):
    """
    Allows to not commit empty commits
    https://github.com/dulwich/dulwich/issues/740
    """
    def do_commit(self, allow_empty_commits=False, **kwargs):
        self.add_changed_to_object_store()
        tree: bytes = self.tree.id
        if not allow_empty_commits:
            index = self.repo.open_index()
            index.commit(self.repo.object_store)
            head_tree = self

Replies: 5 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jelmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #740 on February 17, 2022 19:54.