Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is None possible for the attribute change_type of git.diff.Diff object? #1696

Answered by Byron
jiseongg asked this question in Q&A
Discussion options

I am using GitPython 3.1.37 to use commit history for software analysis.
While using git.diff.Diff instance, I accidentally found that the change_type attribute was None, which I had expected to be one of ('A', 'C', 'D', 'R', 'M', 'T').

I am not sure this is bug. If not, I want to know when it happens.

The sample code to reproduce my situation is like follows:

from git import Repo
# used repository: https://github.com/gocd/gocd
repo = Repo('/path/to/repository')
prev_commit = repo.commit('86064ef5ee28e0d0d12911f46fd603d15246fdd5')
next_commit = repo.commit('42e58c22aefd036b6fdd2095ed0d391f5238c6c4')
diff_index = prev_commit.diff(next_commit, create_patch=True)
# one example file
target_diff = list(filter(
 lambda d: d.a_path == 'agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacAboutBox.java',
 diff_index))[0]
print(target_diff.change_type) # `None` printed

The result of actual git diff command, which considers the aforementioned diff as 'M' type:

# git diff 86064ef5ee28e0d0d12911f46fd603d15246fdd5 42e58c22aefd036b6fdd2095ed0d391f5238c6c4 --diff-filter 'M' -- agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacAboutBox.java
diff --git a/agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacAboutBox.java b/agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacAboutBox.java
index 0103494d4a..90d876badb 100644
--- a/agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacAboutBox.java
+++ b/agent-bootstrapper/src/com/thoughtworks/go/agent/bootstrapper/osx/MacAboutBox.java
@@ -55,7 +55,7 @@ public class MacAboutBox extends JFrame implements ActionListener {
 aboutLabels.add(bodyLabel("Bootstrapper Version " + getBootstrapperVersion()));
 aboutLabels.add(emptyLabel());
 aboutLabels.add(bodyLabel("Java Version " + System.getProperty("java.version")));
- aboutLabels.add(bodyLabel("Copyright (C) 2013 ThoughtWorks Inc."));
+ aboutLabels.add(bodyLabel("Copyright (C) 2015 ThoughtWorks Inc."));
 aboutLabels.add(emptyLabel());
 Panel textPanel2 = new Panel(new GridLayout(aboutLabels.size(), 1));

Thank you for any help you can offer.

You must be logged in to vote

I looks like change_type is known to possibly be None as per the bolted on type-system. Ideally the editor would know and warn about it, but apparently this didn't happen here.

The actual problem seems to be though that a modified file isn't classified as such - instead, no classification is provided.

Since I don't know why that is, a contributor could probably create a test with reproduction and fix it that way, or at least, understand what's going on.


Instead of trying to fix this, I recommend using gitoxide - it will probably be multiple times faster and doesn't have these typing problems either.

Replies: 1 comment 1 reply

Comment options

I looks like change_type is known to possibly be None as per the bolted on type-system. Ideally the editor would know and warn about it, but apparently this didn't happen here.

The actual problem seems to be though that a modified file isn't classified as such - instead, no classification is provided.

Since I don't know why that is, a contributor could probably create a test with reproduction and fix it that way, or at least, understand what's going on.


Instead of trying to fix this, I recommend using gitoxide - it will probably be multiple times faster and doesn't have these typing problems either.

You must be logged in to vote
1 reply
Comment options

Thank you for the recommendation!! I will try to use gitoxide :)

Answer selected by Byron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /