本文整理汇总了Python中bzrlib.workingtree.WorkingTree类的典型用法代码示例。如果您正苦于以下问题:Python WorkingTree类的具体用法?Python WorkingTree怎么用?Python WorkingTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkingTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_init_branch
def test_init_branch(self):
out, err = self.run_bzr('init')
self.assertEqual("Created a standalone tree (format: %s)\n" % (
self._default_label,), out)
self.assertEqual('', err)
# Can it handle subdirectories of branches too ?
out, err = self.run_bzr('init subdir1')
self.assertEqual("Created a standalone tree (format: %s)\n" % (
self._default_label,), out)
self.assertEqual('', err)
WorkingTree.open('subdir1')
self.run_bzr_error(['Parent directory of subdir2/nothere does not exist'],
'init subdir2/nothere')
out, err = self.run_bzr('init subdir2/nothere', retcode=3)
self.assertEqual('', out)
os.mkdir('subdir2')
out, err = self.run_bzr('init subdir2')
self.assertEqual("Created a standalone tree (format: %s)\n" % (
self._default_label,), out)
self.assertEqual('', err)
# init an existing branch.
out, err = self.run_bzr('init subdir2', retcode=3)
self.assertEqual('', out)
self.assertTrue(err.startswith('bzr: ERROR: Already a branch:'))
示例2: test_mkdir_w_nested_trees
def test_mkdir_w_nested_trees(self):
"""'bzr mkdir' with nested trees"""
self.make_branch_and_tree('.')
self.make_branch_and_tree('a')
self.make_branch_and_tree('a/b')
self.run_bzr(['mkdir', 'dir', 'a/dir', 'a/b/dir'])
self.assertTrue(os.path.isdir('dir'))
self.assertTrue(os.path.isdir('a/dir'))
self.assertTrue(os.path.isdir('a/b/dir'))
wt = WorkingTree.open('.')
wt_a = WorkingTree.open('a')
wt_b = WorkingTree.open('a/b')
delta = wt.changes_from(wt.basis_tree())
self.assertEquals(len(delta.added), 1)
self.assertEquals(delta.added[0][0], 'dir')
self.assertFalse(delta.modified)
delta = wt_a.changes_from(wt_a.basis_tree())
self.assertEquals(len(delta.added), 1)
self.assertEquals(delta.added[0][0], 'dir')
self.assertFalse(delta.modified)
delta = wt_b.changes_from(wt_b.basis_tree())
self.assertEquals(len(delta.added), 1)
self.assertEquals(delta.added[0][0], 'dir')
self.assertFalse(delta.modified)
示例3: test_new_files
def test_new_files(self):
if sys.platform == 'win32':
raise TestSkipped('chmod has no effect on win32')
t = self.make_branch_and_tree('.')
b = t.branch
with open('a', 'wb') as f: f.write('foo\n')
# ensure check_mode_r works with capital-letter file-ids like TREE_ROOT
t.add('a', 'CAPS-ID')
t.commit('foo')
chmod_r('.bzr', 0644, 0755)
check_mode_r(self, '.bzr', 0644, 0755)
# although we are modifying the filesystem
# underneath the objects, they are not locked, and thus it must
# be safe for most operations. But here we want to observe a
# mode change in the control bits, which current do not refresh
# when a new lock is taken out.
t = WorkingTree.open('.')
b = t.branch
self.assertEqualMode(0755, b.control_files._dir_mode)
self.assertEqualMode(0644, b.control_files._file_mode)
self.assertEqualMode(0755, b.bzrdir._get_dir_mode())
self.assertEqualMode(0644, b.bzrdir._get_file_mode())
# Modifying a file shouldn't break the permissions
with open('a', 'wb') as f: f.write('foo2\n')
t.commit('foo2')
# The mode should be maintained after commit
check_mode_r(self, '.bzr', 0644, 0755)
# Adding a new file should maintain the permissions
with open('b', 'wb') as f: f.write('new b\n')
t.add('b')
t.commit('new b')
check_mode_r(self, '.bzr', 0644, 0755)
# Recursively update the modes of all files
chmod_r('.bzr', 0664, 0775)
check_mode_r(self, '.bzr', 0664, 0775)
t = WorkingTree.open('.')
b = t.branch
self.assertEqualMode(0775, b.control_files._dir_mode)
self.assertEqualMode(0664, b.control_files._file_mode)
self.assertEqualMode(0775, b.bzrdir._get_dir_mode())
self.assertEqualMode(0664, b.bzrdir._get_file_mode())
with open('a', 'wb') as f: f.write('foo3\n')
t.commit('foo3')
check_mode_r(self, '.bzr', 0664, 0775)
with open('c', 'wb') as f: f.write('new c\n')
t.add('c')
t.commit('new c')
check_mode_r(self, '.bzr', 0664, 0775)
示例4: update_branches
def update_branches(sourcecode_directory, update_branches,
possible_transports=None, tip=False, quiet=False):
"""Update the existing branches in sourcecode."""
if possible_transports is None:
possible_transports = []
# XXX: JonathanLange 2009-11-09: Rather than updating one branch after
# another, we could instead try to get them in parallel.
for project, (branch_url, revision, optional) in (
update_branches.iteritems()):
# Update project from branch_url.
destination = os.path.join(sourcecode_directory, project)
if not quiet:
print 'Updating %s to %s' % (
project, _format_revision_name(revision, tip))
local_tree = WorkingTree.open(destination)
try:
remote_branch = Branch.open(
branch_url, possible_transports=possible_transports)
except BzrError:
if optional:
report_exception(sys.exc_info(), sys.stderr)
continue
else:
raise
possible_transports.append(
remote_branch.bzrdir.root_transport)
revision_id = get_revision_id(revision, remote_branch, tip)
try:
result = local_tree.pull(
remote_branch, stop_revision=revision_id, overwrite=True,
possible_transports=possible_transports)
except IncompatibleRepositories:
# XXX JRV 20100407: Ideally remote_branch.bzrdir._format
# should be passed into upgrade() to ensure the format is the same
# locally and remotely. Unfortunately smart server branches
# have their _format set to RemoteFormat rather than an actual
# format instance.
upgrade(destination)
# Upgraded, repoen working tree
local_tree = WorkingTree.open(destination)
result = local_tree.pull(
remote_branch, stop_revision=revision_id, overwrite=True,
possible_transports=possible_transports)
if result.old_revid == result.new_revid:
if not quiet:
print ' (No change)'
else:
if result.old_revno < result.new_revno:
change = 'Updated'
else:
change = 'Reverted'
if not quiet:
print ' (%s from %s to %s)' % (
change, result.old_revno, result.new_revno)
示例5: run
def run(self, merge_type=None, directory="."):
from bzrlib.plugins.rewrite.rebase import RebaseState1, WorkingTreeRevisionRewriter
from bzrlib.workingtree import WorkingTree
wt = WorkingTree.open_containing(directory)[0]
wt.lock_write()
try:
state = RebaseState1(wt)
replayer = WorkingTreeRevisionRewriter(wt, state, merge_type=merge_type)
# Abort if there are any conflicts
if len(wt.conflicts()) != 0:
raise BzrCommandError(
gettext(
"There are still conflicts present. "
"Resolve the conflicts and then run "
"'bzr resolve' and try again."
)
)
# Read plan file
try:
replace_map = state.read_plan()[1]
except NoSuchFile:
raise BzrCommandError(gettext("No rebase to continue"))
oldrevid = state.read_active_revid()
if oldrevid is not None:
oldrev = wt.branch.repository.get_revision(oldrevid)
replayer.commit_rebase(oldrev, replace_map[oldrevid][0])
finish_rebase(state, wt, replace_map, replayer)
finally:
wt.unlock()
示例6: __init__
def __init__(self, path=None):
WorkingCopy.__init__(self)
self.path = path or os.getcwd()
self.workingtree = WorkingTree.open(self.path)
self.repository = BazaarRepository(self.workingtree.branch.user_url)
#self.repository.working_copy = self
self._current_version = self.repository._repository.revno()
示例7: test_set_and_get_view_info
def test_set_and_get_view_info(self):
wt = self.make_branch_and_tree('wt')
view_current = 'view-name'
view_dict = {
view_current: ['dir-1'],
'other-name': ['dir-2']}
wt.views.set_view_info(view_current, view_dict)
current, views = wt.views.get_view_info()
self.assertEquals(view_current, current)
self.assertEquals(view_dict, views)
# then reopen the tree and see they're still there
wt = WorkingTree.open('wt')
current, views = wt.views.get_view_info()
self.assertEquals(view_current, current)
self.assertEquals(view_dict, views)
# test setting a current view which does not exist
self.assertRaises(errors.NoSuchView,
wt.views.set_view_info, 'yet-another', view_dict)
current, views = wt.views.get_view_info()
self.assertEquals(view_current, current)
self.assertEquals(view_dict, views)
# test clearing the current view
wt.views.set_view_info(None, view_dict)
current, views = wt.views.get_view_info()
self.assertEquals(None, current)
self.assertEquals(view_dict, views)
示例8: test_branch_stacked_branch_stacked
def test_branch_stacked_branch_stacked(self):
"""Asking to stack on a stacked branch does work"""
# We have a mainline
trunk_tree = self.make_branch_and_tree('target',
format='development')
trunk_revid = trunk_tree.commit('mainline')
# and a branch from it which is stacked
branch_tree = self.make_branch_and_tree('branch',
format='development')
branch_tree.branch.set_stacked_on_url(trunk_tree.branch.base)
# with some work on it
branch_revid = branch_tree.commit('moar work plz')
# you can chain branches on from there
out, err = self.run_bzr(['branch', 'branch', '--stacked', 'branch2'])
self.assertEqual('', out)
self.assertEqual('Created new stacked branch referring to %s.\n' %
branch_tree.branch.base, err)
self.assertEqual(branch_tree.branch.base,
branch.Branch.open('branch2').get_stacked_on_url())
branch2_tree = WorkingTree.open('branch2')
branch2_revid = branch2_tree.commit('work on second stacked branch')
self.assertRevisionInRepository('branch2', branch2_revid)
self.assertRevisionsInBranchRepository(
[trunk_revid, branch_revid, branch2_revid],
'branch2')
示例9: runUpdate
def runUpdate(filename):
branch = "versioning.git"
REMOTE_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch)
PUSHTO_URL="bzr+ssh://bazaar.launchpad.net/~freecad-maintainers/freecad/%s" % (branch)
LOCAL_BRANCH=path.join(gettempdir(),branch)
# Location of branch on Launchpad
remote_branch = Branch.open(REMOTE_URL)
# Location of branch on local system
local_branch = remote_branch.bzrdir.sprout(LOCAL_BRANCH).open_branch()
# Change a file in the local branch
try:
wf = open(LOCAL_BRANCH + "/src/Build/Version.h", 'w')
rf = open(filename, 'r')
except IOError as error:
raise error
else:
wf.write(rf.read())
wf.close()
# Commit the change
tree = WorkingTree.open(LOCAL_BRANCH)
tree.commit("Update version number")
示例10: create_tree
def create_tree(self):
'''Create the dir and working tree.'''
try:
self.logger.debug(
'Using tree in %(tree_dir)s' % {
'tree_dir': self.config.tree_dir})
if os.path.exists(self.config.tree_dir):
self.tree = WorkingTree.open(self.config.tree_dir)
if self.tree.branch.user_url != self.bzr_branch.user_url:
self.logger.debug('Tree URLs do not match: %s - %s' % (
self.bzr_branch.user_url, self.tree.branch.user_url))
raise InvalidWorkingTree(
'The `tree_dir` option for the target branch is not a '
'lightweight checkout. Please ask a project '
'administrator to resolve the issue, and try again.')
else:
self.logger.debug('Tree does not exist. Creating dir')
# Create the path up to but not including tree_dir if it does
# not exist.
parent_dir = os.path.dirname(self.config.tree_dir)
if not os.path.exists(parent_dir):
os.makedirs(parent_dir)
self.tree = self.bzr_branch.create_checkout(
self.config.tree_dir, lightweight=True)
except AttributeError:
# Store this so we can rmtree later
self.temp_tree_dir = tempfile.mkdtemp()
self.logger.debug(
'Using temp dir at %(tree_dir)s' % {
'tree_dir': self.temp_tree_dir})
self.tree = self.bzr_branch.create_checkout(self.temp_tree_dir)
self.cleanup()
示例11: test_branch_push_pull_merge_copies_tags
def test_branch_push_pull_merge_copies_tags(self):
t = self.make_branch_and_tree('branch1')
t.commit(allow_pointless=True, message='initial commit',
rev_id='first-revid')
b1 = t.branch
b1.tags.set_tag('tag1', 'first-revid')
# branching copies the tag across
self.run_bzr('branch branch1 branch2')
b2 = Branch.open('branch2')
self.assertEquals(b2.tags.lookup_tag('tag1'), 'first-revid')
# make a new tag and pull it
b1.tags.set_tag('tag2', 'twa')
self.run_bzr('pull -d branch2 branch1')
self.assertEquals(b2.tags.lookup_tag('tag2'), 'twa')
# make a new tag and push it
b1.tags.set_tag('tag3', 'san')
self.run_bzr('push -d branch1 branch2')
self.assertEquals(b2.tags.lookup_tag('tag3'), 'san')
# make a new tag and merge it
t.commit(allow_pointless=True, message='second commit',
rev_id='second-revid')
t2 = WorkingTree.open('branch2')
t2.commit(allow_pointless=True, message='commit in second')
b1.tags.set_tag('tag4', 'second-revid')
self.run_bzr('merge -d branch2 branch1')
self.assertEquals(b2.tags.lookup_tag('tag4'), 'second-revid')
# pushing to a new location copies the tag across
self.run_bzr('push -d branch1 branch3')
b3 = Branch.open('branch3')
self.assertEquals(b3.tags.lookup_tag('tag1'), 'first-revid')
示例12: commit
def commit(self, mutable_tree):
# BUG: not run recursively if in above branch not have changes
if disable_hooks or not self.read_config():
return
from bzrlib.workingtree import WorkingTree
snapshot = []
for arg in self.config: # url directory [revisionspec]
wt = WorkingTree.open(pathjoin(self.root, arg[1]))
if wt.has_changes(wt.basis_tree()):
cmd = ['ci']
os.chdir(wt.basedir)
try:
run_bzr_catch_user_errors(cmd)
finally:
os.chdir(self.cwd)
if len(arg) < 3:
arg.append('')
arg[2] = 'revid:' + wt.last_revision()
arg[1] = self._quoted_if_need(arg[1])
snapshot.append(' '.join(arg).encode('utf-8'))
path = pathjoin(self.root, SNAPSHOT_PATH)
f = open(path, 'w')
try:
f.write('\n'.join(snapshot))
finally:
f.close()
示例13: run
def run(self, location=None, remember=False, directory=None,
no_rebase=False, strict=None):
from bzrlib import urlutils
from bzrlib.controldir import ControlDir
from bzrlib.errors import BzrCommandError, NoWorkingTree
from bzrlib.workingtree import WorkingTree
if directory is None:
directory = "."
try:
source_wt = WorkingTree.open_containing(directory)[0]
source_branch = source_wt.branch
except NoWorkingTree:
source_branch = Branch.open(directory)
source_wt = None
if source_wt is not None:
source_wt.check_changed_or_out_of_date(
strict, 'dpush_strict',
more_error='Use --no-strict to force the push.',
more_warning='Uncommitted changes will not be pushed.')
stored_loc = source_branch.get_push_location()
if location is None:
if stored_loc is None:
raise BzrCommandError(gettext("No push location known or specified."))
else:
display_url = urlutils.unescape_for_display(stored_loc,
self.outf.encoding)
self.outf.write(
gettext("Using saved location: %s\n") % display_url)
location = stored_loc
controldir = ControlDir.open(location)
target_branch = controldir.open_branch()
target_branch.lock_write()
try:
try:
push_result = source_branch.push(target_branch, lossy=True)
except errors.LossyPushToSameVCS:
raise BzrCommandError(gettext("{0!r} and {1!r} are in the same VCS, lossy "
"push not necessary. Please use regular push.").format(
source_branch, target_branch))
# We successfully created the target, remember it
if source_branch.get_push_location() is None or remember:
# FIXME: Should be done only if we succeed ? -- vila 2012-01-18
source_branch.set_push_location(target_branch.base)
if not no_rebase:
old_last_revid = source_branch.last_revision()
source_branch.pull(target_branch, overwrite=True)
new_last_revid = source_branch.last_revision()
if source_wt is not None and old_last_revid != new_last_revid:
source_wt.lock_write()
try:
target = source_wt.branch.repository.revision_tree(
new_last_revid)
update_workingtree_fileids(source_wt, target)
finally:
source_wt.unlock()
push_result.report(self.outf)
finally:
target_branch.unlock()
示例14: test_merge_rename_to_temp_before_delete
def test_merge_rename_to_temp_before_delete(self):
"""rename to temp before delete, source children before parents
This case requires that you must not do deletes before
move-out-of-the-way, and that you must not do children
after parents:
$ mkdir foo
$ touch foo/bar
$ bzr add foo/bar
$ bzr commit
$ bzr mv foo/bar bar
$ rmdir foo
$ bzr commit
"""
a_wt = self.make_branch_and_tree("a")
os.mkdir("a/foo")
with file("a/foo/bar", "wb") as f:
f.write("A/FOO/BAR")
a_wt.add("foo")
a_wt.add("foo/bar")
a_wt.commit("added foo/bar")
self.run_bzr("branch a b")
b_wt = WorkingTree.open("b")
b_wt.rename_one("foo/bar", "bar")
os.rmdir("b/foo")
b_wt.remove("foo")
b_wt.commit("moved foo/bar to bar, deleted foo")
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1))
示例15: test_merge_rename_before_create
def test_merge_rename_before_create(self):
"""rename before create
This case requires that you must not do creates
before move-into-place:
$ touch foo
$ bzr add foo
$ bzr commit
$ bzr mv foo bar
$ touch foo
$ bzr add foo
$ bzr commit
"""
a_wt = self.make_branch_and_tree("a")
with file("a/foo", "wb") as f:
f.write("A/FOO")
a_wt.add("foo")
a_wt.commit("added foo")
self.run_bzr("branch a b")
b_wt = WorkingTree.open("b")
b_wt.rename_one("foo", "bar")
with file("b/foo", "wb") as f:
f.write("B/FOO")
b_wt.add("foo")
b_wt.commit("moved foo to bar, added new foo")
a_wt.merge_from_branch(b_wt.branch, b_wt.branch.last_revision(), b_wt.branch.get_rev_id(1))