1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
#!/usr/bin/python
# Copyright (C) 2022 Jelmer Vernooij
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import shutil
from breezy.revision import NULL_REVISION
from breezy.tests import TestCaseWithTransport
from silver_platter import Workspace
class TestWorkspace(TestCaseWithTransport):
def test_nascent(self):
tree = self.make_branch_and_tree("origin")
with Workspace(tree.branch, dir=self.test_dir) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("A change")
self.assertEqual(str(ws.path), ws.local_tree.basedir)
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
self.assertTrue(ws.any_branch_changes())
self.assertEqual(
[("", NULL_REVISION, ws.local_tree.last_revision())],
ws.result_branches(),
)
def test_without_main(self):
with Workspace(None, dir=self.test_dir) as ws:
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.any_branch_changes())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("A change")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
self.assertTrue(ws.any_branch_changes())
self.assertEqual(
[("", None, ws.local_tree.last_revision())],
ws.result_branches(),
)
def test_basic(self):
tree = self.make_branch_and_tree("origin")
revid1 = tree.commit("first commit")
with Workspace(tree.branch, dir=self.test_dir) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("A change")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
self.assertTrue(ws.any_branch_changes())
self.assertEqual(
[("", revid1, ws.local_tree.last_revision())],
ws.result_branches(),
)
def test_cached_branch_up_to_date(self):
tree = self.make_branch_and_tree("origin")
revid1 = tree.commit("first commit")
cached = tree.branch.controldir.sprout("cached")
with Workspace(
tree.branch, cached_branch=cached.open_branch(), dir=self.test_dir
) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertFalse(ws.changes_since_base())
self.assertEqual(ws.local_tree.last_revision(), revid1)
def test_cached_branch_out_of_date(self):
tree = self.make_branch_and_tree("origin")
tree.commit("first commit")
cached = tree.branch.controldir.sprout("cached")
revid2 = tree.commit("first commit")
with Workspace(
tree.branch, cached_branch=cached.open_branch(), dir=self.test_dir
) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertFalse(ws.changes_since_base())
self.assertEqual(ws.local_tree.last_revision(), revid2)
def commit_on_colo(self, controldir, name, message):
colo_branch = controldir.create_branch("colo")
colo_checkout = colo_branch.create_checkout(name)
try:
return colo_checkout.commit(message)
finally:
shutil.rmtree(name)
def test_colocated(self):
tree = self.make_branch_and_tree("origin")
revid1 = tree.commit("main")
colo_revid1 = self.commit_on_colo(
tree.branch.controldir, "colo", "Another"
)
self.assertEqual(tree.branch.last_revision(), revid1)
with Workspace(
tree.branch,
dir=self.test_dir,
additional_colocated_branches=["colo"],
) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("A change")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
self.assertTrue(ws.any_branch_changes())
self.assertEqual(
[
("", revid1, ws.local_tree.last_revision()),
("colo", colo_revid1, colo_revid1),
],
ws.result_branches(),
)
def test_resume_continue(self):
tree = self.make_branch_and_tree("origin")
revid1 = tree.commit("first commit")
resume = tree.branch.controldir.sprout("resume")
resume_tree = resume.open_workingtree()
resume_revid1 = resume_tree.commit("resume")
with Workspace(
tree.branch, resume_branch=resume_tree.branch, dir=self.test_dir
) as ws:
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.any_branch_changes())
self.assertFalse(ws.refreshed)
self.assertFalse(ws.changes_since_base())
self.assertEqual(ws.local_tree.last_revision(), resume_revid1)
self.assertEqual(
[("", revid1, resume_revid1)], ws.result_branches()
)
def test_resume_discard(self):
tree = self.make_branch_and_tree("origin")
tree.commit("first commit")
resume = tree.branch.controldir.sprout("resume")
revid2 = tree.commit("second commit")
resume_tree = resume.open_workingtree()
resume_tree.commit("resume")
with Workspace(
tree.branch, resume_branch=resume_tree.branch, dir=self.test_dir
) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertTrue(ws.refreshed)
self.assertFalse(ws.changes_since_base())
self.assertEqual(ws.local_tree.last_revision(), revid2)
self.assertEqual([("", revid2, revid2)], ws.result_branches())
def test_resume_continue_with_unchanged_colocated(self):
tree = self.make_branch_and_tree("origin")
revid1 = tree.commit("first commit")
colo_revid1 = self.commit_on_colo(
tree.branch.controldir, "colo", "First colo"
)
resume = tree.branch.controldir.sprout("resume")
resume_tree = resume.open_workingtree()
resume_revid1 = resume_tree.commit("resume")
with Workspace(
tree.branch,
resume_branch=resume_tree.branch,
dir=self.test_dir,
additional_colocated_branches=["colo"],
) as ws:
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.any_branch_changes())
self.assertFalse(ws.refreshed)
self.assertFalse(ws.changes_since_base())
self.assertEqual(ws.local_tree.last_revision(), resume_revid1)
self.assertEqual(
[
("", revid1, resume_revid1),
("colo", colo_revid1, colo_revid1),
],
ws.result_branches(),
)
def test_resume_discard_with_unchanged_colocated(self):
tree = self.make_branch_and_tree("origin")
tree.commit("first commit")
colo_revid1 = self.commit_on_colo(
tree.branch.controldir, "colo", "First colo"
)
resume = tree.branch.controldir.sprout("resume")
self.commit_on_colo(resume, "colo", "First colo on resume")
revid2 = tree.commit("second commit")
resume_tree = resume.open_workingtree()
resume_tree.commit("resume")
with Workspace(
tree.branch,
resume_branch=resume_tree.branch,
dir=self.test_dir,
additional_colocated_branches=["colo"],
) as ws:
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.any_branch_changes())
self.assertTrue(ws.refreshed)
self.assertFalse(ws.changes_since_base())
self.assertEqual(ws.local_tree.last_revision(), revid2)
self.assertEqual(
[
("", revid2, revid2),
("colo", colo_revid1, colo_revid1),
],
ws.result_branches(),
)
|