summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLaMont Jones <lamontjones@google.com>2022-11-02 22:01:29 +0000
committerLaMont Jones <lamontjones@google.com>2022-11-03 23:01:16 +0000
commitfa8d939c8f6a3d25d9a203f28b16a71d891dcc1c (patch)
tree1d3519d54c1ef256b0acaa19a0d601897a318411 /tests
parenta6c52f566acfbff5b0f37158c0d33adf05d250e5 (diff)
downloadgit-repo-fa8d939c8f6a3d25d9a203f28b16a71d891dcc1c.tar.gz
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 <jrn@google.com> Tested-by: LaMont Jones <lamontjones@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_subcmds_sync.py55
1 files changed, 48 insertions, 7 deletions
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 @@
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14
15"""Unittests for the subcmds/sync.py module.""" 14"""Unittests for the subcmds/sync.py module."""
16 15
16import unittest
17from unittest import mock 17from unittest import mock
18 18
19import pytest 19import pytest
@@ -21,17 +21,14 @@ import pytest
21from subcmds import sync 21from subcmds import sync
22 22
23 23
24@pytest.mark.parametrize( 24@pytest.mark.parametrize('use_superproject, cli_args, result', [
25 'use_superproject, cli_args, result',
26 [
27 (True, ['--current-branch'], True), 25 (True, ['--current-branch'], True),
28 (True, ['--no-current-branch'], True), 26 (True, ['--no-current-branch'], True),
29 (True, [], True), 27 (True, [], True),
30 (False, ['--current-branch'], True), 28 (False, ['--current-branch'], True),
31 (False, ['--no-current-branch'], False), 29 (False, ['--no-current-branch'], False),
32 (False, [], None), 30 (False, [], None),
33 ] 31])
34)
35def test_get_current_branch_only(use_superproject, cli_args, result): 32def test_get_current_branch_only(use_superproject, cli_args, result):
36 """Test Sync._GetCurrentBranchOnly logic. 33 """Test Sync._GetCurrentBranchOnly logic.
37 34
@@ -41,5 +38,49 @@ def test_get_current_branch_only(use_superproject, cli_args, result):
41 cmd = sync.Sync() 38 cmd = sync.Sync()
42 opts, _ = cmd.OptionParser.parse_args(cli_args) 39 opts, _ = cmd.OptionParser.parse_args(cli_args)
43 40
44 with mock.patch('git_superproject.UseSuperproject', return_value=use_superproject): 41 with mock.patch('git_superproject.UseSuperproject',
42 return_value=use_superproject):
45 assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result 43 assert cmd._GetCurrentBranchOnly(opts, cmd.manifest) == result
44
45
46class GetPreciousObjectsState(unittest.TestCase):
47 """Tests for _GetPreciousObjectsState."""
48
49 def setUp(self):
50 """Common setup."""
51 self.cmd = sync.Sync()
52 self.project = p = mock.MagicMock(use_git_worktrees=False,
53 UseAlternates=False)
54 p.manifest.GetProjectsWithName.return_value = [p]
55
56 self.opt = mock.Mock(spec_set=['this_manifest_only'])
57 self.opt.this_manifest_only = False
58
59 def test_worktrees(self):
60 """False for worktrees."""
61 self.project.use_git_worktrees = True
62 self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt))
63
64 def test_not_shared(self):
65 """Singleton project."""
66 self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt))
67
68 def test_shared(self):
69 """Shared project."""
70 self.project.manifest.GetProjectsWithName.return_value = [
71 self.project, self.project
72 ]
73 self.assertTrue(self.cmd._GetPreciousObjectsState(self.project, self.opt))
74
75 def test_shared_with_alternates(self):
76 """Shared project, with alternates."""
77 self.project.manifest.GetProjectsWithName.return_value = [
78 self.project, self.project
79 ]
80 self.project.UseAlternates = True
81 self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt))
82
83 def test_not_found(self):
84 """Project not found in manifest."""
85 self.project.manifest.GetProjectsWithName.return_value = []
86 self.assertFalse(self.cmd._GetPreciousObjectsState(self.project, self.opt))