How can i set create_patch=true, and meanwhile get change_type in Diff · gitpython-developers/GitPython · Discussion #1898 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

How can i set create_patch=true, and meanwhile get change_type in Diff #1898

Answered by topp
SongXueZhi asked this question in Q&A
Discussion options

You must be logged in to vote

+1 For getting change_type also set on diff item when create_patch=True.

@SongXueZhi Approach depends on your intention for further processing, but you can certainly retrieve the change type info even from a Diff generated with create_patch=True:

def get_change_type_of_diff_item(diff_item):
    if diff_item.new_file:
        change_type = 'Added'
    elif diff_item.deleted_file:
        change_type = 'Deleted'
    elif diff_item.renamed_file:
        change_type = 'Renamed'
    elif diff_item.copied_file:
        change_type = 'Copied'
    else:
        change_type = 'Modified'
    return change_type

Usage Example:

repo = git.Repo('/path/to/repository')
diff_index = repo.head.commit.diff…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@SongXueZhi
Comment options

Answer selected by SongXueZhi
Comment options

You must be logged in to vote
0 replies
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 #1897 on April 02, 2024 09:08.

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.