~bzr-pqm/bzr/bzr.dev

1185.14.3 by Aaron Bentley
Copied conflict lister in
1
# Copyright (C) 2005 by Aaron Bentley
2
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.
7
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.
12
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
16
17
import bzrlib.status
18
from bzrlib.branch import Branch
19
from bzrlib.errors import BzrCommandError
1185.14.4 by Aaron Bentley
Registered conflicts, resolve functions
20
from bzrlib.commands import register_command
1185.14.6 by Aaron Bentley
Made iter_conflicts a WorkingTree method
21
from bzrlib.workingtree import CONFLICT_SUFFIXES
1185.14.3 by Aaron Bentley
Copied conflict lister in
22
import os
23
import errno
24
25
class cmd_conflicts(bzrlib.commands.Command):
26
    """List files with conflicts.
27
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
28
    files.)
29
    """
30
    def run(self):
1185.14.6 by Aaron Bentley
Made iter_conflicts a WorkingTree method
31
        for path in Branch.open_containing('.').working_tree().iter_conflicts():
1185.14.3 by Aaron Bentley
Copied conflict lister in
32
            print path
33
1185.14.4 by Aaron Bentley
Registered conflicts, resolve functions
34
register_command(cmd_conflicts)
35
1185.14.3 by Aaron Bentley
Copied conflict lister in
36
class cmd_resolve(bzrlib.commands.Command):
37
    """Mark a conflict as resolved.
38
    """
39
    takes_args = ['file*']
40
    takes_options = ['all']
41
    def run(self, file_list=None, all=False):
42
        if file_list is None:
43
            if not all:
44
                raise BzrCommandError(
45
                    "command 'resolve' needs one or more FILE, or --all")
46
            tree = Branch.open_containing('.').working_tree()
1185.14.6 by Aaron Bentley
Made iter_conflicts a WorkingTree method
47
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
1185.14.3 by Aaron Bentley
Copied conflict lister in
48
        else:
49
            if all:
50
                raise BzrCommandError(
51
                    "If --all is specified, no FILE may be provided")
52
        for filename in file_list:
53
            failures = 0
1185.14.6 by Aaron Bentley
Made iter_conflicts a WorkingTree method
54
            for suffix in CONFLICT_SUFFIXES:
1185.14.3 by Aaron Bentley
Copied conflict lister in
55
                try:
56
                    os.unlink(filename+suffix)
57
                except OSError, e:
58
                    if e.errno != errno.ENOENT:
59
                        raise
60
                    else:
61
                        failures += 1
1185.14.6 by Aaron Bentley
Made iter_conflicts a WorkingTree method
62
            if failures == len(CONFLICT_SUFFIXES):
1185.14.3 by Aaron Bentley
Copied conflict lister in
63
                if not os.path.exists(filename):
64
                    print "%s does not exist" % filename
65
                else:
66
                    print "%s is not conflicted" % filename
67
                        
1185.14.4 by Aaron Bentley
Registered conflicts, resolve functions
68
register_command(cmd_resolve)