| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -204,13 +204,13 @@ def diff(cls, repo, a, b = None, paths = None): | |||
| 204 | 204 | if b: | |
| 205 | 205 | paths.insert(0, b) | |
| 206 | 206 | paths.insert(0, a) | |
| 207 | - text = repo.git.diff(full_index=True, *paths) | ||
| 207 | + text = repo.git.diff('-M', full_index=True, *paths) | ||
| 208 | 208 | return diff.Diff.list_from_string(repo, text) | |
| 209 | 209 | ||
| 210 | 210 | @property | |
| 211 | 211 | def diffs(self): | |
| 212 | 212 | if not self.parents: | |
| 213 | - d = self.repo.git.show(self.id, full_index=True, pretty='raw') | ||
| 213 | + d = self.repo.git.show(self.id, '-M', full_index=True, pretty='raw') | ||
| 214 | 214 | if re.search(r'diff --git a', d): | |
| 215 | 215 | if not re.search(r'^diff --git a', d): | |
| 216 | 216 | p = re.compile(r'.+?(diff --git a)', re.MULTILINE | re.DOTALL) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,9 @@ class Diff(object): | |||
| 12 | 12 | A Diff contains diff information between two commits. | |
| 13 | 13 | """ | |
| 14 | 14 | ||
| 15 | - def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode, b_mode, new_file, deleted_file, diff): | ||
| 15 | + def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode, | ||
| 16 | + b_mode, new_file, deleted_file, rename_from, | ||
| 17 | + rename_to, diff): | ||
| 16 | 18 | self.repo = repo | |
| 17 | 19 | self.a_path = a_path | |
| 18 | 20 | self.b_path = b_path | |
@@ -30,6 +32,9 @@ def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode, b_mode, new | |||
| 30 | 32 | self.b_mode = b_mode | |
| 31 | 33 | self.new_file = new_file | |
| 32 | 34 | self.deleted_file = deleted_file | |
| 35 | + self.rename_from = rename_from | ||
| 36 | + self.rename_to = rename_to | ||
| 37 | + self.renamed = rename_from != rename_to | ||
| 33 | 38 | self.diff = diff | |
| 34 | 39 | ||
| 35 | 40 | @classmethod | |
@@ -54,13 +59,13 @@ def list_from_string(cls, repo, text): | |||
| 54 | 59 | header = diff_header(diff) | |
| 55 | 60 | ||
| 56 | 61 | a_path, b_path, similarity_index, rename_from, rename_to, \ | |
| 57 | - old_mode, new_mode, new_file_mode, deleted_file_mode, \ | ||
| 62 | + old_mode, new_mode, new_file_mode, deleted_file_mode, \ | ||
| 58 | 63 | a_commit, b_commit, b_mode = header.groups() | |
| 59 | 64 | new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode) | |
| 60 | 65 | ||
| 61 | 66 | diffs.append(Diff(repo, a_path, b_path, a_commit, b_commit, | |
| 62 | 67 | old_mode or deleted_file_mode, new_mode or new_file_mode or b_mode, | |
| 63 | - new_file, deleted_file, diff[header.end():])) | ||
| 68 | + new_file, deleted_file, rename_from, rename_to, diff[header.end():])) | ||
| 64 | 69 | ||
| 65 | 70 | return diffs | |
| 66 | 71 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,12 @@ | |||
| 1 | + commit 2524c44334a8ba6b2ab8f3f0a478f04c5b073cc8 | ||
| 2 | + tree e126e7b4203dadf083f5eb8e2f34c255b51d8bee | ||
| 3 | + parent d789e23b9ea8d90221d13c46f7c228d729385f92 | ||
| 4 | + author Michael Trier <mtrier@gmail.com> 1229389391 -0500 | ||
| 5 | + committer Michael Trier <mtrier@gmail.com> 1229389391 -0500 | ||
| 6 | + | ||
| 7 | + Renamed AUTHORS to CONTRIBUTORS because it's cooler. | ||
| 8 | + | ||
| 9 | + diff --git a/AUTHORS b/CONTRIBUTORS | ||
| 10 | + similarity index 100% | ||
| 11 | + rename from AUTHORS | ||
| 12 | + rename to CONTRIBUTORS | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,23 @@ def test_diff(self, git): | |||
| 52 | 52 | assert_equal(True, diffs[5].new_file) | |
| 53 | 53 | ||
| 54 | 54 | assert_true(git.called) | |
| 55 | - assert_equal(git.call_args, (('diff', 'master'), {'full_index': True})) | ||
| 55 | + assert_equal(git.call_args, (('diff', '-M', 'master'), {'full_index': True})) | ||
| 56 | + | ||
| 57 | + @patch_object(Git, '_call_process') | ||
| 58 | + def test_diff_with_rename(self, git): | ||
| 59 | + git.return_value = fixture('diff_rename') | ||
| 60 | + | ||
| 61 | + diffs = Commit.diff(self.repo, 'rename') | ||
| 62 | + | ||
| 63 | + assert_equal(1, len(diffs)) | ||
| 64 | + | ||
| 65 | + diff = diffs[0] | ||
| 66 | + assert_true(diff.renamed) | ||
| 67 | + assert_equal(diff.rename_from, 'AUTHORS') | ||
| 68 | + assert_equal(diff.rename_to, 'CONTRIBUTORS') | ||
| 69 | + | ||
| 70 | + assert_true(git.called) | ||
| 71 | + assert_equal(git.call_args, (('diff', '-M', 'rename'), {'full_index': True})) | ||
| 56 | 72 | ||
| 57 | 73 | @patch_object(Git, '_call_process') | |
| 58 | 74 | def test_diff_with_two_commits(self, git): | |
@@ -63,7 +79,7 @@ def test_diff_with_two_commits(self, git): | |||
| 63 | 79 | assert_equal(3, len(diffs)) | |
| 64 | 80 | ||
| 65 | 81 | assert_true(git.called) | |
| 66 | - assert_equal(git.call_args, (('diff', '59ddc32', '13d27d5'), {'full_index': True})) | ||
| 82 | + assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5'), {'full_index': True})) | ||
| 67 | 83 | ||
| 68 | 84 | @patch_object(Git, '_call_process') | |
| 69 | 85 | def test_diff_with_files(self, git): | |
@@ -75,7 +91,7 @@ def test_diff_with_files(self, git): | |||
| 75 | 91 | assert_equal('lib/grit/diff.rb', diffs[0].a_path) | |
| 76 | 92 | ||
| 77 | 93 | assert_true(git.called) | |
| 78 | - assert_equal(git.call_args, (('diff', '59ddc32', '--', 'lib'), {'full_index': True})) | ||
| 94 | + assert_equal(git.call_args, (('diff', '-M', '59ddc32', '--', 'lib'), {'full_index': True})) | ||
| 79 | 95 | ||
| 80 | 96 | @patch_object(Git, '_call_process') | |
| 81 | 97 | def test_diff_with_two_commits_and_files(self, git): | |
@@ -87,7 +103,7 @@ def test_diff_with_two_commits_and_files(self, git): | |||
| 87 | 103 | assert_equal('lib/grit/commit.rb', diffs[0].a_path) | |
| 88 | 104 | ||
| 89 | 105 | assert_true(git.called) | |
| 90 | - assert_equal(git.call_args, (('diff', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) | ||
| 106 | + assert_equal(git.call_args, (('diff', '-M', '59ddc32', '13d27d5', '--', 'lib'), {'full_index': True})) | ||
| 91 | 107 | ||
| 92 | 108 | @patch_object(Git, '_call_process') | |
| 93 | 109 | def test_diffs(self, git): | |
@@ -113,7 +129,8 @@ def test_diffs(self, git): | |||
| 113 | 129 | assert_equal(True, diffs[5].new_file) | |
| 114 | 130 | ||
| 115 | 131 | assert_true(git.called) | |
| 116 | - assert_equal(git.call_args, (('diff', '038af8c329ef7c1bae4568b98bd5c58510465493', | ||
| 132 | + assert_equal(git.call_args, (('diff', '-M', | ||
| 133 | + '038af8c329ef7c1bae4568b98bd5c58510465493', | ||
| 117 | 134 | '91169e1f5fa4de2eaea3f176461f5dc784796769', | |
| 118 | 135 | ), {'full_index': True})) | |
| 119 | 136 | ||
@@ -142,7 +159,7 @@ def test_diffs_on_initial_import(self, git): | |||
| 142 | 159 | assert_equal(True, diffs[5].new_file) | |
| 143 | 160 | ||
| 144 | 161 | assert_true(git.called) | |
| 145 | - assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3'), {'full_index': True, 'pretty': 'raw'})) | ||
| 162 | + assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) | ||
| 146 | 163 | ||
| 147 | 164 | @patch_object(Git, '_call_process') | |
| 148 | 165 | def test_diffs_on_initial_import_with_empty_commit(self, git): | |
@@ -154,7 +171,7 @@ def test_diffs_on_initial_import_with_empty_commit(self, git): | |||
| 154 | 171 | assert_equal([], diffs) | |
| 155 | 172 | ||
| 156 | 173 | assert_true(git.called) | |
| 157 | - assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3'), {'full_index': True, 'pretty': 'raw'})) | ||
| 174 | + assert_equal(git.call_args, (('show', '634396b2f541a9f2d58b00be1a07f0c358b999b3', '-M'), {'full_index': True, 'pretty': 'raw'})) | ||
| 158 | 175 | ||
| 159 | 176 | @patch_object(Git, '_call_process') | |
| 160 | 177 | def test_diffs_with_mode_only_change(self, git): | |
@@ -169,7 +186,7 @@ def test_diffs_with_mode_only_change(self, git): | |||
| 169 | 186 | assert_equal('100755', diffs[0].b_mode) | |
| 170 | 187 | ||
| 171 | 188 | assert_true(git.called) | |
| 172 | - assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769'), {'full_index': True, 'pretty': 'raw'})) | ||
| 189 | + assert_equal(git.call_args, (('show', '91169e1f5fa4de2eaea3f176461f5dc784796769', '-M'), {'full_index': True, 'pretty': 'raw'})) | ||
| 173 | 190 | ||
| 174 | 191 | @patch_object(Git, '_call_process') | |
| 175 | 192 | def test_stats(self, git): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,9 +10,21 @@ | |||
| 10 | 10 | class TestDiff(object): | |
| 11 | 11 | def setup(self): | |
| 12 | 12 | self.repo = Repo(GIT_REPO) | |
| 13 | - | ||
| 13 | + | ||
| 14 | 14 | def test_list_from_string_new_mode(self): | |
| 15 | 15 | output = fixture('diff_new_mode') | |
| 16 | 16 | diffs = Diff.list_from_string(self.repo, output) | |
| 17 | 17 | assert_equal(1, len(diffs)) | |
| 18 | 18 | assert_equal(10, len(diffs[0].diff.splitlines())) | |
| 19 | + | ||
| 20 | + def test_diff_with_rename(self): | ||
| 21 | + output = fixture('diff_rename') | ||
| 22 | + diffs = Diff.list_from_string(self.repo, output) | ||
| 23 | + | ||
| 24 | + assert_equal(1, len(diffs)) | ||
| 25 | + | ||
| 26 | + diff = diffs[0] | ||
| 27 | + assert_true(diff.renamed) | ||
| 28 | + assert_equal(diff.rename_from, 'AUTHORS') | ||
| 29 | + assert_equal(diff.rename_to, 'CONTRIBUTORS') | ||
| 30 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments