Show More
@@ -634,8 +634,7 b' class GitRepository(BaseRepository):' | |||||
634 | if path: |
|
634 | if path: | |
635 | cmd += ['--', path] |
|
635 | cmd += ['--', path] | |
636 |
|
636 | |||
637 | stdout, stderr = self.run_git_command(cmd) |
|
637 | stdout, stderr = self._run_git_command(cmd, cwd=self.path) | |
638 | # TODO: don't ignore stderr |
|
|||
639 | # If we used 'show' command, strip first few lines (until actual diff |
|
638 | # If we used 'show' command, strip first few lines (until actual diff | |
640 | # starts) |
|
639 | # starts) | |
641 | if rev1 == self.EMPTY_CHANGESET: |
|
640 | if rev1 == self.EMPTY_CHANGESET: |
@@ -665,65 +665,65 b' class TestGitSpecificWithRepo(_BackendTe' | |||||
665 | assert self.repo.workdir.get_branch() == 'master' |
|
665 | assert self.repo.workdir.get_branch() == 'master' | |
666 |
|
666 | |||
667 | def test_get_diff_runs_git_command_with_hashes(self): |
|
667 | def test_get_diff_runs_git_command_with_hashes(self): | |
668 |
self.repo.run_git_command = mock.Mock(return_value= |
|
668 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
669 | self.repo.get_diff(0, 1) |
|
669 | self.repo.get_diff(0, 1) | |
670 | self.repo.run_git_command.assert_called_once_with( |
|
670 | self.repo._run_git_command.assert_called_once_with( | |
671 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
671 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
672 | self.repo._get_revision(0), self.repo._get_revision(1)]) |
|
672 | self.repo._get_revision(0), self.repo._get_revision(1)], cwd=self.repo.path) | |
673 |
|
673 | |||
674 | def test_get_diff_runs_git_command_with_str_hashes(self): |
|
674 | def test_get_diff_runs_git_command_with_str_hashes(self): | |
675 |
self.repo.run_git_command = mock.Mock(return_value= |
|
675 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
676 | self.repo.get_diff(self.repo.EMPTY_CHANGESET, 1) |
|
676 | self.repo.get_diff(self.repo.EMPTY_CHANGESET, 1) | |
677 | self.repo.run_git_command.assert_called_once_with( |
|
677 | self.repo._run_git_command.assert_called_once_with( | |
678 | ['show', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
678 | ['show', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
679 | self.repo._get_revision(1)]) |
|
679 | self.repo._get_revision(1)], cwd=self.repo.path) | |
680 |
|
680 | |||
681 | def test_get_diff_runs_git_command_with_path_if_its_given(self): |
|
681 | def test_get_diff_runs_git_command_with_path_if_its_given(self): | |
682 |
self.repo.run_git_command = mock.Mock(return_value= |
|
682 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
683 | self.repo.get_diff(0, 1, 'foo') |
|
683 | self.repo.get_diff(0, 1, 'foo') | |
684 | self.repo.run_git_command.assert_called_once_with( |
|
684 | self.repo._run_git_command.assert_called_once_with( | |
685 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
685 | ['diff', '-U3', '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
686 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) |
|
686 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path) | |
687 |
|
687 | |||
688 | def test_get_diff_does_not_sanitize_valid_context(self): |
|
688 | def test_get_diff_does_not_sanitize_valid_context(self): | |
689 | almost_overflowed_long_int = 2**31-1 |
|
689 | almost_overflowed_long_int = 2**31-1 | |
690 |
|
690 | |||
691 |
self.repo.run_git_command = mock.Mock(return_value= |
|
691 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
692 | self.repo.get_diff(0, 1, 'foo', context=almost_overflowed_long_int) |
|
692 | self.repo.get_diff(0, 1, 'foo', context=almost_overflowed_long_int) | |
693 | self.repo.run_git_command.assert_called_once_with( |
|
693 | self.repo._run_git_command.assert_called_once_with( | |
694 | ['diff', '-U' + str(almost_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
694 | ['diff', '-U' + str(almost_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
695 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) |
|
695 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path) | |
696 |
|
696 | |||
697 | def test_get_diff_sanitizes_overflowing_context(self): |
|
697 | def test_get_diff_sanitizes_overflowing_context(self): | |
698 | overflowed_long_int = 2**31 |
|
698 | overflowed_long_int = 2**31 | |
699 | sanitized_overflowed_long_int = overflowed_long_int-1 |
|
699 | sanitized_overflowed_long_int = overflowed_long_int-1 | |
700 |
|
700 | |||
701 |
self.repo.run_git_command = mock.Mock(return_value= |
|
701 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
702 | self.repo.get_diff(0, 1, 'foo', context=overflowed_long_int) |
|
702 | self.repo.get_diff(0, 1, 'foo', context=overflowed_long_int) | |
703 |
|
703 | |||
704 | self.repo.run_git_command.assert_called_once_with( |
|
704 | self.repo._run_git_command.assert_called_once_with( | |
705 | ['diff', '-U' + str(sanitized_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
705 | ['diff', '-U' + str(sanitized_overflowed_long_int), '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
706 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) |
|
706 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path) | |
707 |
|
707 | |||
708 | def test_get_diff_does_not_sanitize_zero_context(self): |
|
708 | def test_get_diff_does_not_sanitize_zero_context(self): | |
709 | zero_context = 0 |
|
709 | zero_context = 0 | |
710 |
|
710 | |||
711 |
self.repo.run_git_command = mock.Mock(return_value= |
|
711 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
712 | self.repo.get_diff(0, 1, 'foo', context=zero_context) |
|
712 | self.repo.get_diff(0, 1, 'foo', context=zero_context) | |
713 |
|
713 | |||
714 | self.repo.run_git_command.assert_called_once_with( |
|
714 | self.repo._run_git_command.assert_called_once_with( | |
715 | ['diff', '-U' + str(zero_context), '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
715 | ['diff', '-U' + str(zero_context), '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
716 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) |
|
716 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path) | |
717 |
|
717 | |||
718 | def test_get_diff_sanitizes_negative_context(self): |
|
718 | def test_get_diff_sanitizes_negative_context(self): | |
719 | negative_context = -10 |
|
719 | negative_context = -10 | |
720 |
|
720 | |||
721 |
self.repo.run_git_command = mock.Mock(return_value= |
|
721 | self.repo._run_git_command = mock.Mock(return_value=(b'', b'')) | |
722 | self.repo.get_diff(0, 1, 'foo', context=negative_context) |
|
722 | self.repo.get_diff(0, 1, 'foo', context=negative_context) | |
723 |
|
723 | |||
724 | self.repo.run_git_command.assert_called_once_with( |
|
724 | self.repo._run_git_command.assert_called_once_with( | |
725 | ['diff', '-U0', '--full-index', '--binary', '-p', '-M', '--abbrev=40', |
|
725 | ['diff', '-U0', '--full-index', '--binary', '-p', '-M', '--abbrev=40', | |
726 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo']) |
|
726 | self.repo._get_revision(0), self.repo._get_revision(1), '--', 'foo'], cwd=self.repo.path) | |
727 |
|
727 | |||
728 |
|
728 | |||
729 | class TestGitRegression(_BackendTestMixin): |
|
729 | class TestGitRegression(_BackendTestMixin): |
General Comments 0
You need to be logged in to leave comments.
Login now