1
# Copyright (C) 2005 by Aaron Bentley
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
from bzrlib.branch import Branch
19
from bzrlib.errors import BzrCommandError
23
SUFFIXES = ('.THIS', '.BASE', '.OTHER')
24
def get_conflicted_stem(path):
25
for suffix in SUFFIXES:
26
if path.endswith(suffix):
27
return path[:-len(suffix)]
29
def iter_conflicts(tree):
31
for path in (s[0] for s in tree.list_files()):
32
stem = get_conflicted_stem(path)
35
if stem not in conflicted:
39
class cmd_conflicts(bzrlib.commands.Command):
40
"""List files with conflicts.
41
(conflicts are determined by the presence of .BASE .TREE, and .OTHER
45
for path in iter_conflicts(Branch.open_containing('.').working_tree()):
48
class cmd_resolve(bzrlib.commands.Command):
49
"""Mark a conflict as resolved.
51
takes_args = ['file*']
52
takes_options = ['all']
53
def run(self, file_list=None, all=False):
56
raise BzrCommandError(
57
"command 'resolve' needs one or more FILE, or --all")
58
tree = Branch.open_containing('.').working_tree()
59
file_list = list(iter_conflicts(tree))
62
raise BzrCommandError(
63
"If --all is specified, no FILE may be provided")
64
for filename in file_list:
66
for suffix in SUFFIXES:
68
os.unlink(filename+suffix)
70
if e.errno != errno.ENOENT:
74
if failures == len(SUFFIXES):
75
if not os.path.exists(filename):
76
print "%s does not exist" % filename
78
print "%s is not conflicted" % filename
82
# monkey-patch the standard 'status' to give us conflicts, too.
83
def _show_status(branch, **kwargs):
84
old_show_status(branch, **kwargs)
85
conflicted = list(iter_conflicts(branch.working_tree()))
86
if len(conflicted) > 0:
91
old_show_status = bzrlib.status.show_status
92
bzrlib.status.show_status = _show_status