summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Trier <mtrier@gmail.com>2008-12-15 20:47:19 -0500
committerMichael Trier <mtrier@gmail.com>2008-12-15 20:47:19 -0500
commit6ba8b8b91907bd087dfe201eb0d5dae2feb54881 (patch)
tree0f553a341cdde34d8a92030965b8219a36945308
parent5e062f4d043234312446ea9445f07bd9dc309ce3 (diff)
downloadgitpython-6ba8b8b91907bd087dfe201eb0d5dae2feb54881.tar.gz
Added in new properties Diff.renamed, Diff.rename_from, and Diff.rename_to
-rw-r--r--lib/git/commit.py4
-rw-r--r--lib/git/diff.py11
-rw-r--r--test/fixtures/diff_rename12
-rw-r--r--test/git/test_commit.py33
-rw-r--r--test/git/test_diff.py14
5 files changed, 60 insertions, 14 deletions
diff --git a/lib/git/commit.py b/lib/git/commit.py
index 4aee1280..e35090a1 100644
--- a/lib/git/commit.py
+++ b/lib/git/commit.py
@@ -204,13 +204,13 @@ class Commit(LazyMixin):
if b:
paths.insert(0, b)
paths.insert(0, a)
- text = repo.git.diff(full_index=True, *paths)
+ text = repo.git.diff('-M', full_index=True, *paths)
return diff.Diff.list_from_string(repo, text)
@property
def diffs(self):
if not self.parents:
- d = self.repo.git.show(self.id, full_index=True, pretty='raw')
+ d = self.repo.git.show(self.id, '-M', full_index=True, pretty='raw')
if re.search(r'diff --git a', d):
if not re.search(r'^diff --git a', d):
p = re.compile(r'.+?(diff --git a)', re.MULTILINE | re.DOTALL)
diff --git a/lib/git/diff.py b/lib/git/diff.py
index 626c4df9..7a6770c4 100644
--- a/lib/git/diff.py
+++ b/lib/git/diff.py
@@ -12,7 +12,9 @@ class Diff(object):
A Diff contains diff information between two commits.
"""
- def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode, b_mode, new_file, deleted_file, diff):
+ def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode,
+ b_mode, new_file, deleted_file, rename_from,
+ rename_to, diff):
self.repo = repo
self.a_path = a_path
self.b_path = b_path
@@ -30,6 +32,9 @@ class Diff(object):
self.b_mode = b_mode
self.new_file = new_file
self.deleted_file = deleted_file
+ self.rename_from = rename_from
+ self.rename_to = rename_to
+ self.renamed = rename_from != rename_to
self.diff = diff
@classmethod
@@ -54,13 +59,13 @@ class Diff(object):
header = diff_header(diff)
a_path, b_path, similarity_index, rename_from, rename_to, \
- old_mode, new_mode, new_file_mode, deleted_file_mode, \
+ old_mode, new_mode, new_file_mode, deleted_file_mode, \
a_commit, b_commit, b_mode = header.groups()
new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode)
diffs.append(Diff(repo, a_path, b_path, a_commit, b_commit,
old_mode or deleted_file_mode, new_mode or new_file_mode or b_mode,
- new_file, deleted_file, diff[header.end():]))
+ new_file, deleted_file, rename_from, rename_to, diff[header.end():]))
return diffs
diff --git a/test/fixtures/diff_rename b/test/fixtures/diff_rename
new file mode 100644
index 00000000..13abae0e
--- /dev/null
+++ b/test/fixtures/diff_rename
@@ -0,0 +1,12 @@
+commit 2524c44334a8ba6b2ab8f3f0a478f04c5b073cc8
+tree e126e7b4203dadf083f5eb8e2f34c255b51d8bee
+parent d789e23b9ea8d90221d13c46f7c228d729385f92
+author Michael Trier <mtrier@gmail.com> 1229389391 -0500
+committer Michael Trier <mtrier@gmail.com> 1229389391 -0500
+
+ Renamed AUTHORS to CONTRIBUTORS because it's cooler.
+
+diff --git a/AUTHORS b/CONTRIBUTORS
+similarity index 100%
+rename from AUTHORS
+rename to CONTRIBUTORS
diff --git a/test/git/test_commit.py b/test/git/test_commit.py
index 93c7d2c2..da7236c8 100644
--- a/test/git/test_commit.py
+++ b/test/git/test_commit.py
@@ -52,7 +52,23 @@ class TestCommit(object):
assert_equal(True, diffs[5].new_file)
assert_true(git.called)
- assert_equal(git.call_args, (('diff', 'master'), {'full_index': True}))
+ assert_equal(git.call_args, (('diff', '-M', 'master'), {'full_index': True}))
+
+ @patch_object(Git, '_call_process')
+ def test_diff_with_rename(self, git):
+ git.return_value = fixture('diff_rename')
+
+ diffs = Commit.diff(self.repo, 'rename')
+
+ assert_equal(1, len(diffs))
+
+ diff = diffs[0]
+ assert_true(diff.renamed)
+ assert_equal(diff.rename_from, 'AUTHORS')
+ assert_equal(diff.rename_to, 'CONTRIBUTORS')
+
+ assert_true(git.called)
+ assert_equal(git.call_args, (('diff', '-M', 'rename'), {'full_index': True}))
@patch_object(Git, '_call_process')
def test_diff_with_two_commits(self, git):
@@ -63,7 +79,7 @@ class TestCommit(object):
assert_equal(3, len(diffs))
assert_true(git.called)
- assert_equal(git.call_args, (('diff', '59ddc32', '13d27d5'), {'full_index': True}))
+ assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5'), {'full_index': True}))
@patch_object(Git, '_call_process')
def test_diff_with_files(self, git):
@@ -75,7 +91,7 @@ class TestCommit(object):
assert_equal('lib/grit/diff.rb', diffs[0].a_path)
assert_true(git.called)
- assert_equal(git.call_args, (('diff', '59ddc32', '--', 'lib'), {'full_index': True}))
+ assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True}))
@patch_object(Git, '_call_process')
def test_diff_with_two_commits_and_files(self, git):
@@ -87,7 +103,7 @@ class TestCommit(object):
assert_equal('lib/grit/commit.rb', diffs[0].a_path)
assert_true(git.called)
- assert_equal(git.call_args, (('diff', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True}))
+ assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True}))
@patch_object(Git, '_call_process')
def test_diffs(self, git):
@@ -113,7 +129,8 @@ class TestCommit(object):
assert_equal(True, diffs[5].new_file)
assert_true(git.called)
- assert_equal(git.call_args, (('diff', '038af8c329ef7c1bae4568b98bd5c58510465493',
+ assert_equal(git.call_args, (('diff', '-M',
+ '038af8c329ef7c1bae4568b98bd5c58510465493',
'91169e1f5fa4de2eaea3f176461f5dc784796769',
), {'full_index': True}))
@@ -142,7 +159,7 @@ class TestCommit(object):
assert_equal(True, diffs[5].new_file)
assert_true(git.called)
- assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3'), {'full_index': True, 'pretty': 'raw'}))
+ assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'}))
@patch_object(Git, '_call_process')
def test_diffs_on_initial_import_with_empty_commit(self, git):
@@ -154,7 +171,7 @@ class TestCommit(object):
assert_equal([], diffs)
assert_true(git.called)
- assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3'), {'full_index': True, 'pretty': 'raw'}))
+ assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'}))
@patch_object(Git, '_call_process')
def test_diffs_with_mode_only_change(self, git):
@@ -169,7 +186,7 @@ class TestCommit(object):
assert_equal('100755', diffs[0].b_mode)
assert_true(git.called)
- assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769'), {'full_index': True, 'pretty': 'raw'}))
+ assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769', '-M'), {'full_index': True, 'pretty': 'raw'}))
@patch_object(Git, '_call_process')
def test_stats(self, git):
diff --git a/test/git/test_diff.py b/test/git/test_diff.py
index 9b7e9c73..94ac03e0 100644
--- a/test/git/test_diff.py
+++ b/test/git/test_diff.py
@@ -10,9 +10,21 @@ from git import *
class TestDiff(object):
def setup(self):
self.repo = Repo(GIT_REPO)
-
+
def test_list_from_string_new_mode(self):
output = fixture('diff_new_mode')
diffs = Diff.list_from_string(self.repo, output)
assert_equal(1, len(diffs))
assert_equal(10, len(diffs[0].diff.splitlines()))
+
+ def test_diff_with_rename(self):
+ output = fixture('diff_rename')
+ diffs = Diff.list_from_string(self.repo, output)
+
+ assert_equal(1, len(diffs))
+
+ diff = diffs[0]
+ assert_true(diff.renamed)
+ assert_equal(diff.rename_from, 'AUTHORS')
+ assert_equal(diff.rename_to, 'CONTRIBUTORS')
+