| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ Changelog | |||
| 5 | 5 | 0.3.5 - Bugfixes | |
| 6 | 6 | ================ | |
| 7 | 7 | * push/pull/fetch operations will not block anymore | |
| 8 | + * diff() can now properly detect renames, both in patch and raw format. Previously it only worked when create_patch was True. | ||
| 8 | 9 | * A list of all fixed issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.5+-+bugfixes%22+ | |
| 9 | 10 | ||
| 10 | 11 | 0.3.4 - Python 3 Support | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -73,9 +73,9 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs): | |||
| 73 | 73 | args.append("--abbrev=40") # we need full shas | |
| 74 | 74 | args.append("--full-index") # get full index paths, not only filenames | |
| 75 | 75 | ||
| 76 | + args.append("-M") # check for renames, in both formats | ||
| 76 | 77 | if create_patch: | |
| 77 | 78 | args.append("-p") | |
| 78 | - args.append("-M") # check for renames | ||
| 79 | 79 | else: | |
| 80 | 80 | args.append("--raw") | |
| 81 | 81 | ||
@@ -318,14 +318,11 @@ def _index_from_patch_format(cls, repo, stream): | |||
| 318 | 318 | @classmethod | |
| 319 | 319 | def _index_from_raw_format(cls, repo, stream): | |
| 320 | 320 | """Create a new DiffIndex from the given stream which must be in raw format. | |
| 321 | - :note: | ||
| 322 | - This format is inherently incapable of detecting renames, hence we only | ||
| 323 | - modify, delete and add files | ||
| 324 | 321 | :return: git.DiffIndex""" | |
| 325 | 322 | # handles | |
| 326 | 323 | # :100644 100644 687099101... 37c5e30c8... M .gitignore | |
| 327 | 324 | index = DiffIndex() | |
| 328 | - for line in stream: | ||
| 325 | + for line in stream.readlines(): | ||
| 329 | 326 | line = line.decode(defenc) | |
| 330 | 327 | if not line.startswith(":"): | |
| 331 | 328 | continue | |
@@ -336,6 +333,8 @@ def _index_from_raw_format(cls, repo, stream): | |||
| 336 | 333 | b_path = path | |
| 337 | 334 | deleted_file = False | |
| 338 | 335 | new_file = False | |
| 336 | + rename_from = None | ||
| 337 | + rename_to = None | ||
| 339 | 338 | ||
| 340 | 339 | # NOTE: We cannot conclude from the existance of a blob to change type | |
| 341 | 340 | # as diffs with the working do not have blobs yet | |
@@ -345,10 +344,13 @@ def _index_from_raw_format(cls, repo, stream): | |||
| 345 | 344 | elif change_type == 'A': | |
| 346 | 345 | a_blob_id = None | |
| 347 | 346 | new_file = True | |
| 347 | + elif change_type[0] == 'R': # parses RXXX, where XXX is a confidence value | ||
| 348 | + a_path, b_path = path.split('\t', 1) | ||
| 349 | + rename_from, rename_to = a_path, b_path | ||
| 348 | 350 | # END add/remove handling | |
| 349 | 351 | ||
| 350 | 352 | diff = Diff(repo, a_path, b_path, a_blob_id, b_blob_id, old_mode, new_mode, | |
| 351 | - new_file, deleted_file, None, None, '') | ||
| 353 | + new_file, deleted_file, rename_from, rename_to, '') | ||
| 352 | 354 | index.append(diff) | |
| 353 | 355 | # END for each line | |
| 354 | 356 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + :100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 R100 this that | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -56,6 +56,15 @@ def test_diff_with_rename(self): | |||
| 56 | 56 | assert_equal(diff.rename_from, 'AUTHORS') | |
| 57 | 57 | assert_equal(diff.rename_to, 'CONTRIBUTORS') | |
| 58 | 58 | ||
| 59 | + output = StringProcessAdapter(fixture('diff_rename_raw')) | ||
| 60 | + diffs = Diff._index_from_raw_format(self.rorepo, output.stdout) | ||
| 61 | + assert len(diffs) == 1 | ||
| 62 | + diff = diffs[0] | ||
| 63 | + assert diff.renamed | ||
| 64 | + assert diff.rename_from == 'this' | ||
| 65 | + assert diff.rename_to == 'that' | ||
| 66 | + assert len(list(diffs.iter_change_type('R'))) == 1 | ||
| 67 | + | ||
| 59 | 68 | def test_diff_patch_format(self): | |
| 60 | 69 | # test all of the 'old' format diffs for completness - it should at least | |
| 61 | 70 | # be able to deal with it | |
| Back | FazBrowse Home | New Git URL |
0 commit comments