~abentley/bzrtools/bzrtools.dev

349 by Aaron Bentley
Added cbranch command
1
# Copyright (C) 2006 Aaron Bentley
2
# <aaron.bentley@utoronto.ca>
3
#
4
#    This program is free software; you can redistribute it and/or modify
5
#    it under the terms of the GNU General Public License as published by
6
#    the Free Software Foundation; either version 2 of the License, or
7
#    (at your option) any later version.
8
#
9
#    This program is distributed in the hope that it will be useful,
10
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
11
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
#    GNU General Public License for more details.
13
#
14
#    You should have received a copy of the GNU General Public License
15
#    along with this program; if not, write to the Free Software
16
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
422 by Aaron Bentley
In cbranch, set parent of heavyweight checkouts properly
18
from bzrlib.branch import Branch
409 by Aaron Bentley
Update colordiff to use wrapped versions of diff
19
from bzrlib.builtins import cmd_branch, cmd_checkout
349 by Aaron Bentley
Added cbranch command
20
from bzrlib.config import LocationConfig
21
from bzrlib.errors import BzrCommandError
355.1.2 by Aaron Bentley
cbranch mimics checkout wrt --lightweight
22
from bzrlib.osutils import pathjoin, basename, abspath, getcwd
422 by Aaron Bentley
In cbranch, set parent of heavyweight checkouts properly
23
from bzrlib.urlutils import local_path_to_url
349 by Aaron Bentley
Added cbranch command
24
486 by Aaron Bentley
Support deep cbranch hierarcy via appendpath
25
def cbranch(from_location, to_location=None, revision=None,
26
            lightweight=False):
360 by Aaron Bentley
Strip trailing / from input location
27
    from_location = from_location.rstrip('/')
355.1.3 by Aaron Bentley
Fixed cbranch with empty to_location
28
    if to_location is None:
359 by Aaron Bentley
Fixed thinko determining to_location
29
        to_location = pathjoin(getcwd(), basename(from_location))
349 by Aaron Bentley
Added cbranch command
30
    config = LocationConfig(abspath(to_location))
486 by Aaron Bentley
Support deep cbranch hierarcy via appendpath
31
    b_loc = config.get_user_option("cbranch_target")
32
    if b_loc is None:
33
        b_root = config.get_user_option("cbranch_root")
34
        if b_root is None:
35
            raise BzrCommandError("Can't find cbranch_target in"
36
                                  " locations.conf")
37
        b_loc = pathjoin(b_root, basename(to_location))
409 by Aaron Bentley
Update colordiff to use wrapped versions of diff
38
    cmd_branch().run(from_location, b_loc, revision=revision)
39
    cmd_checkout().run(b_loc, to_location, lightweight=lightweight)
422 by Aaron Bentley
In cbranch, set parent of heavyweight checkouts properly
40
    b = Branch.open(to_location)