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
|
#!/usr/bin/python
# Copyright (C) 2019 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 os
from io import BytesIO
from breezy.tests import TestCaseWithTransport
from silver_platter import Workspace
class WorkspaceTests(TestCaseWithTransport):
def test_simple(self):
b = self.make_branch("target")
with Workspace(b, dir=self.test_dir) as ws:
self.assertIsNone(ws.resume_branch)
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("foo")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_main())
def test_with_resume(self):
b = self.make_branch_and_tree("target")
c = b.controldir.sprout("resume").open_workingtree()
c.commit("some change")
with Workspace(
b.branch, resume_branch=c.branch, dir=self.test_dir
) as ws:
self.assertEqual(
ws.local_tree.branch.last_revision(), c.branch.last_revision()
)
self.assertIs(ws.resume_branch, c.branch)
self.assertTrue(ws.changes_since_main())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("foo")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
def test_with_resume_conflicting(self):
b = self.make_branch_and_tree("target")
self.build_tree_contents([("target/foo", "somecontents\n")])
b.add(["foo"])
b.commit("initial")
c = b.controldir.sprout("resume").open_workingtree()
self.build_tree_contents([("target/foo", "new contents in main\n")])
b.commit("add conflict in main")
self.build_tree_contents([("resume/foo", "new contents in resume\n")])
c.commit("add conflict in resume")
with Workspace(
b.branch, resume_branch=c.branch, dir=self.test_dir
) as ws:
self.assertTrue(ws.refreshed)
self.assertEqual(ws.base_revid, b.branch.last_revision())
self.assertEqual(
b.branch.last_revision(), ws.local_tree.branch.last_revision()
)
self.assertFalse(ws.changes_since_main())
self.assertFalse(ws.changes_since_base())
ws.local_tree.commit("foo")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
def test_base_tree(self):
b = self.make_branch_and_tree("target")
cid = b.commit("some change")
with Workspace(b.branch, dir=self.test_dir) as ws:
ws.local_tree.commit("blah")
self.assertEqual(cid, ws.base_tree.get_revision_id())
def test_show_diff(self):
b = self.make_branch_and_tree("target")
with Workspace(b.branch, dir=self.test_dir) as ws:
self.build_tree_contents(
[
(
os.path.join(ws.local_tree.basedir, "foo"),
"some content\n",
)
]
)
ws.local_tree.add(["foo"])
ws.local_tree.commit("blah")
self.assertTrue(ws.changes_since_main())
self.assertTrue(ws.changes_since_base())
f = BytesIO()
ws.show_diff(outf=f)
self.assertContainsRe(
f.getvalue().decode("utf-8"), "\\+some content"
)
|