| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f253335 commit 9432e43
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -187,7 +187,14 @@ def diff( | |||
| 187 | 187 | kwargs["as_process"] = True | |
| 188 | 188 | proc = diff_cmd(*self._process_diff_args(args), **kwargs) | |
| 189 | 189 | ||
| 190 | - diff_method = Diff._index_from_patch_format if create_patch else Diff._index_from_raw_format | ||
| 190 | + cmdline = getattr(proc, 'args', '') # PY3+ only | ||
| 191 | + | ||
| 192 | + if '--name-only' in cmdline: | ||
| 193 | + diff_method = Diff._index_from_name_only_format | ||
| 194 | + elif create_patch: | ||
| 195 | + diff_method = Diff._index_from_patch_format | ||
| 196 | + else: | ||
| 197 | + diff_method = Diff._index_from_raw_format | ||
| 191 | 198 | index = diff_method(self.repo, proc) | |
| 192 | 199 | ||
| 193 | 200 | proc.wait() | |
@@ -569,6 +576,34 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn | |||
| 569 | 576 | ||
| 570 | 577 | return index | |
| 571 | 578 | ||
| 579 | + @classmethod | ||
| 580 | + def _index_from_name_only_format(cls, repo, proc): | ||
| 581 | + """Create a new DiffIndex from the given text which must be in name only format | ||
| 582 | + :param repo: is the repository we are operating on - it is required | ||
| 583 | + :param stream: result of 'git diff' as a stream (supporting file protocol) | ||
| 584 | + :return: git.DiffIndex """ | ||
| 585 | + | ||
| 586 | + cls.is_first = True | ||
| 587 | + | ||
| 588 | + index = DiffIndex() | ||
| 589 | + | ||
| 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)) | ||
| 602 | + | ||
| 603 | + handle_process_output(proc, handle_diff_line_name_only, None, finalize_process, decode_streams=False) | ||
| 604 | + | ||
| 605 | + return index | ||
| 606 | + | ||
| 572 | 607 | @staticmethod | |
| 573 | 608 | def _handle_diff_line(lines_bytes: bytes, repo: "Repo", index: DiffIndex) -> None: | |
| 574 | 609 | lines = lines_bytes.decode(defenc) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -263,6 +263,19 @@ def test_diff_initial_commit(self): | |||
| 263 | 263 | self.assertIsNotNone(diff_index[0].new_file) | |
| 264 | 264 | self.assertEqual(diff_index[0].diff, fixture("diff_initial")) | |
| 265 | 265 | ||
| 266 | + def test_diff_initial_commit_name_only(self): | ||
| 267 | + initial_commit = self.rorepo.commit('33ebe7acec14b25c5f84f35a664803fcab2f7781') | ||
| 268 | + | ||
| 269 | + # Without creating a patch... | ||
| 270 | + diff_index = initial_commit.diff(NULL_TREE, **{'name-only': True}) | ||
| 271 | + self.assertEqual(diff_index[0].a_path, 'CHANGES') | ||
| 272 | + self.assertEqual(diff_index[0].b_path, 'CHANGES') | ||
| 273 | + | ||
| 274 | + # ...and with creating a patch | ||
| 275 | + diff_index = initial_commit.diff(NULL_TREE, create_patch=True, **{'name-only': True}) | ||
| 276 | + self.assertEqual(diff_index[0].a_path, 'CHANGES') | ||
| 277 | + self.assertEqual(diff_index[0].b_path, 'CHANGES') | ||
| 278 | + | ||
| 266 | 279 | def test_diff_unsafe_paths(self): | |
| 267 | 280 | output = StringProcessAdapter(fixture("diff_patch_unsafe_paths")) | |
| 268 | 281 | res = Diff._index_from_patch_format(None, output) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments