From fa8d939c8f6a3d25d9a203f28b16a71d891dcc1c Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Wed, 2 Nov 2022 22:01:29 +0000 Subject: sync: clear preciousObjects when set in error. If this is a project that is not using object sharing (there is only one copy of the remote project) then clear preciousObjects. To override this for a project, run: git config --replace-all repo.preservePreciousObjects true Change-Id: If3ea061c631c5ecd44ead84f68576012e2c7405c Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/350235 Reviewed-by: Jonathan Nieder Tested-by: LaMont Jones --- tests/test_subcmds_sync.py | 55 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 7 deletions(-) (limited to 'tests/test_subcmds_sync.py') diff --git a/tests/test_subcmds_sync.py b/tests/test_subcmds_sync.py index aad713f2..13f3f873 100644 --- a/tests/test_subcmds_sync.py +++ b/tests/test_subcmds_sync.py @@ -11,9 +11,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Unittests for the subcmds/sync.py module.""" +import unittest from unittest import mock import pytest @@ -21,17 +21,14 @@ import pytest from subcmds import sync -@pytest.mark.parametrize( - 'use_superproject, cli_args, result', - [ +@pytest.mark.parametrize('use_superproject, cli_args, result', [ (True, ['--current-branch'], True), (True, ['--no-current-branch'], True), (True, [], True), (False, ['--current-branch'], True), (False, ['--no-current-branch'], False), (False, [], None), - ] -) +]) def test_get_current_branch_only(use_superproject, cli_args, result): """Test Sync._GetCurrentBranchOnly logic. @@ -41,5 +38,49 @@ def test_get_current_branch_only(use_superproject, cli_args, result): cmd = sync.Sync() opts, _ = cmd.OptionParser.parse_args(cli_args) - with mock.patch('git_superproject.UseSuperproject', return_value=use_superproject): + with mock.patch('git_superproject.UseSuperproject', + return_value=use_superproject): assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result + + +class GetPreciousObjectsState(unittest.TestCase): + """Tests for _GetPreciousObjectsState.""" + + def setUp(self): + """Common setup.""" + self.cmd = sync.Sync() + self.project = p = mock.MagicMock(use_git_worktrees=False, + UseAlternates=False) + p.manifest.GetProjectsWithName.return_value = [p] + + self.opt = mock.Mock(spec_set=['this_manifest_only']) + self.opt.this_manifest_only = False + + def test_worktrees(self): + """False for worktrees.""" + self.project.use_git_worktrees = True + self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) + + def test_not_shared(self): + """Singleton project.""" + self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) + + def test_shared(self): + """Shared project.""" + self.project.manifest.GetProjectsWithName.return_value = [ + self.project, self.project + ] + self.assertTrue(self.cmd._GetPreciousObjectsState(self.project, self.opt)) + + def test_shared_with_alternates(self): + """Shared project, with alternates.""" + self.project.manifest.GetProjectsWithName.return_value = [ + self.project, self.project + ] + self.project.UseAlternates = True + self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) + + def test_not_found(self): + """Project not found in manifest.""" + self.project.manifest.GetProjectsWithName.return_value = [] + self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt)) -- cgit v1.2.3-54-g00ecf