1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
2
# Some parts of the code are:
3
# Copyright (C) 2005, 2006 by Canonical Ltd
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
import bzrlib.errors as errors
23
from errors import (DirectoryAlreadyExists, MissingArgumentError,
24
MultipleMoveError, NoFilesSpecified, NoMatchingFiles,
28
""" Add listed files to the branch.
30
:param file_list - list of files to be added (using full paths)
32
:return: count of ignored files
36
added, ignored = bzrlib.add.smart_add(file_list)
39
for glob, paths in ignored.items():
40
match_len += len(paths)
45
""" Create new versioned directory.
47
:param directory: the full path to the directory to be created
49
from bzrlib.workingtree import WorkingTree
55
raise DirectoryAlreadyExists(directory)
57
wt, dd = WorkingTree.open_containing(directory)
61
""" Move or rename given files.
63
:param file_list: if two elements, then rename the first to the second, if more elements then move all of them to the directory specified in the last element
65
from bzrlib.builtins import tree_files
67
if len(names_list) < 2:
68
raise MissingArgumentError
69
tree, rel_names = tree_files(names_list)
71
if os.path.isdir(names_list[-1]):
72
# move into existing directory
73
for pair in tree.move(rel_names[:-1], rel_names[-1]):
76
if len(names_list) != 2:
77
raise MultipleMoveError
78
tree.rename_one(rel_names[0], rel_names[1])
80
def remove(file_list, new=False):
81
""" Make selected files unversioned.
83
:param file_list: list of files/directories to be removed
85
:param new: if True, the 'added' files will be removed
87
from bzrlib.builtins import tree_files
89
tree, file_list = tree_files(file_list)
93
raise NoFilesSpecified
95
from bzrlib.delta import compare_trees
96
added = [compare_trees(tree.basis_tree(), tree,
97
specific_files=file_list).added]
98
file_list = sorted([f[0] for f in added[0]], reverse=True)
99
if len(file_list) == 0:
100
raise NoMatchingFiles
103
tree.remove(file_list)
104
except errors.NotVersionedError:
105
raise NotVersionedError