Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork937
How can i set create_patch=true, and meanwhile get change_type in Diff#1898
-
I find that when i use commit1.diff(commit2,create_patch = true), chang_type of Diff is aways none. if create_patch = False, i kown that i can get chang_type of Diff , but I can get hunk text. Can i get Diff text ,and meanWhile get chang_type of Diff? |
BetaWas this translation helpful?Give feedback.
All reactions
+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
-
+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:
Usage Example:
|
BetaWas this translation helpful?Give feedback.
All reactions
-
You're welcome! I ultimately chose to use pygit2, as it seems more flexible and better suited to my needs. |
BetaWas this translation helpful?Give feedback.
All reactions
-
If you want to do it in a single line, although it's just slightly inefficient this way:
|
BetaWas this translation helpful?Give feedback.
All reactions
This discussion was converted from issue #1897 on April 02, 2024 09:08.