| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9432e43 commit b1ae544
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -148,7 +148,8 @@ def diff( | |||
| 148 | 148 | if not any(x in kwargs for x in ('find_renames', 'no_renames', 'M')): | |
| 149 | 149 | args.append("-M") | |
| 150 | 150 | ||
| 151 | - if create_patch: | ||
| 151 | + name_only = 'name-only' in kwargs | ||
| 152 | + if not name_only and create_patch: | ||
| 152 | 153 | args.append("-p") | |
| 153 | 154 | else: | |
| 154 | 155 | args.append("--raw") | |
@@ -170,6 +171,7 @@ def diff( | |||
| 170 | 171 | elif other is NULL_TREE: | |
| 171 | 172 | args.insert(0, "-r") # recursive diff-tree | |
| 172 | 173 | args.insert(0, "--root") | |
| 174 | + Diff.is_first = True | ||
| 173 | 175 | diff_cmd = self.repo.git.diff_tree | |
| 174 | 176 | elif other is not None: | |
| 175 | 177 | args.insert(0, "-r") # recursive diff-tree | |
@@ -576,29 +578,33 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn | |||
| 576 | 578 | ||
| 577 | 579 | return index | |
| 578 | 580 | ||
| 581 | + is_first = False | ||
| 582 | + | ||
| 579 | 583 | @classmethod | |
| 580 | 584 | def _index_from_name_only_format(cls, repo, proc): | |
| 581 | 585 | """Create a new DiffIndex from the given text which must be in name only format | |
| 582 | 586 | :param repo: is the repository we are operating on - it is required | |
| 583 | 587 | :param stream: result of 'git diff' as a stream (supporting file protocol) | |
| 584 | 588 | :return: git.DiffIndex """ | |
| 585 | 589 | ||
| 586 | - cls.is_first = True | ||
| 587 | - | ||
| 588 | 590 | index = DiffIndex() | |
| 589 | 591 | ||
| 590 | - def handle_diff_line_name_only(line): | ||
| 591 | - path = line.decode(defenc) | ||
| 592 | - if cls.is_first: | ||
| 593 | - cls.is_first = False | ||
| 594 | - return | ||
| 595 | - | ||
| 596 | - path = path.strip() | ||
| 597 | - a_path = path.encode(defenc) | ||
| 598 | - b_path = path.encode(defenc) | ||
| 599 | - index.append(Diff(repo, a_path, b_path, None, None, None, None, | ||
| 600 | - False, False, None, None, None, | ||
| 601 | - '', None, None)) | ||
| 592 | + def handle_diff_line_name_only(lines): | ||
| 593 | + lines = lines.decode(defenc) | ||
| 594 | + | ||
| 595 | + for line in lines.split('\x00'): | ||
| 596 | + path = line.strip() | ||
| 597 | + if len(path) == 0: | ||
| 598 | + continue | ||
| 599 | + if cls.is_first: | ||
| 600 | + cls.is_first = False | ||
| 601 | + continue | ||
| 602 | + | ||
| 603 | + a_path = path.encode(defenc) | ||
| 604 | + b_path = path.encode(defenc) | ||
| 605 | + index.append(Diff(repo, a_path, b_path, None, None, None, None, | ||
| 606 | + False, False, None, None, None, | ||
| 607 | + '', None, None)) | ||
| 602 | 608 | ||
| 603 | 609 | handle_process_output(proc, handle_diff_line_name_only, None, finalize_process, decode_streams=False) | |
| 604 | 610 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -276,6 +276,23 @@ def test_diff_initial_commit_name_only(self): | |||
| 276 | 276 | self.assertEqual(diff_index[0].a_path, 'CHANGES') | |
| 277 | 277 | self.assertEqual(diff_index[0].b_path, 'CHANGES') | |
| 278 | 278 | ||
| 279 | + def test_diff_between_commit_name_only(self): | ||
| 280 | + initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') | ||
| 281 | + new_commit = self.rorepo.commit('1f66cfbbce58b4b552b041707a12d437cc5f400a') | ||
| 282 | + | ||
| 283 | + # Without creating a patch... | ||
| 284 | + diff_index = initial_commit.diff(new_commit, **{'name-only': True}) | ||
| 285 | + | ||
| 286 | + files = {'lib/git_python/diff.py', 'lib/git_python/git.py', 'lib/git_python/repo.py', | ||
| 287 | + 'test/git/test_repo.py', 'README'} | ||
| 288 | + | ||
| 289 | + for diff in diff_index: | ||
| 290 | + self.assertTrue(diff.a_path in files) | ||
| 291 | + self.assertTrue(diff.b_path in files) | ||
| 292 | + files.remove(diff.b_path) | ||
| 293 | + | ||
| 294 | + self.assertTrue(len(files) == 0) | ||
| 295 | + | ||
| 279 | 296 | def test_diff_unsafe_paths(self): | |
| 280 | 297 | output = StringProcessAdapter(fixture("diff_patch_unsafe_paths")) | |
| 281 | 298 | res = Diff._index_from_patch_format(None, output) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments