~ubuntu-branches/ubuntu/hardy/bzr/hardy-updates

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeff Bailey
  • Date: 2005-11-07 13:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20051107131753-qsy145z1rfug5i27
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
# TODO: Move this into builtins
 
18
 
 
19
# TODO: 'bzr resolve' should accept a directory name and work from that 
 
20
# point down
 
21
 
 
22
# TODO: bzr revert should resolve; even when reverting the whole tree
 
23
# or particular directories
 
24
 
 
25
import os
 
26
import errno
 
27
 
 
28
import bzrlib.status
 
29
from bzrlib.branch import Branch
 
30
from bzrlib.errors import BzrCommandError
 
31
from bzrlib.commands import register_command
 
32
from bzrlib.workingtree import CONFLICT_SUFFIXES
 
33
 
 
34
class cmd_conflicts(bzrlib.commands.Command):
 
35
    """List files with conflicts.
 
36
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
 
37
    files.)
 
38
    """
 
39
    def run(self):
 
40
        for path in Branch.open_containing('.')[0].working_tree().iter_conflicts():
 
41
            print path
 
42
 
 
43
class cmd_resolve(bzrlib.commands.Command):
 
44
    """Mark a conflict as resolved.
 
45
    """
 
46
    takes_args = ['file*']
 
47
    takes_options = ['all']
 
48
    def run(self, file_list=None, all=False):
 
49
        if file_list is None:
 
50
            if not all:
 
51
                raise BzrCommandError(
 
52
                    "command 'resolve' needs one or more FILE, or --all")
 
53
            tree = Branch.open_containing('.')[0].working_tree()
 
54
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
 
55
        else:
 
56
            if all:
 
57
                raise BzrCommandError(
 
58
                    "If --all is specified, no FILE may be provided")
 
59
        for filename in file_list:
 
60
            failures = 0
 
61
            for suffix in CONFLICT_SUFFIXES:
 
62
                try:
 
63
                    os.unlink(filename+suffix)
 
64
                except OSError, e:
 
65
                    if e.errno != errno.ENOENT:
 
66
                        raise
 
67
                    else:
 
68
                        failures += 1
 
69
            if failures == len(CONFLICT_SUFFIXES):
 
70
                if not os.path.exists(filename):
 
71
                    print "%s does not exist" % filename
 
72
                else:
 
73
                    print "%s is not conflicted" % filename