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
 
 
17
# TODO: Move this into builtins
 
 
19
# TODO: 'bzr resolve' should accept a directory name and work from that 
 
 
22
# TODO: bzr revert should resolve; even when reverting the whole tree
 
 
23
# or particular directories
 
 
29
from bzrlib.commands import register_command
 
 
30
from bzrlib.errors import BzrCommandError, NotConflicted
 
 
31
from bzrlib.option import Option
 
 
32
from bzrlib.workingtree import CONFLICT_SUFFIXES, WorkingTree
 
 
33
from bzrlib.osutils import rename
 
 
35
class cmd_conflicts(bzrlib.commands.Command):
 
 
36
    """List files with conflicts.
 
 
38
    Merge will do its best to combine the changes in two branches, but there
 
 
39
    are some kinds of problems only a human can fix.  When it encounters those,
 
 
40
    it will mark a conflict.  A conflict means that you need to fix something,
 
 
41
    before you should commit.
 
 
43
    Use bzr resolve when you have fixed a problem.
 
 
45
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
 
 
51
        for path in WorkingTree.open_containing(u'.')[0].iter_conflicts():
 
 
54
class cmd_resolve(bzrlib.commands.Command):
 
 
55
    """Mark a conflict as resolved.
 
 
57
    Merge will do its best to combine the changes in two branches, but there
 
 
58
    are some kinds of problems only a human can fix.  When it encounters those,
 
 
59
    it will mark a conflict.  A conflict means that you need to fix something,
 
 
60
    before you should commit.
 
 
62
    Once you have fixed a problem, use "bzr resolve FILE.." to mark
 
 
63
    individual files as fixed, or "bzr resolve --all" to mark all conflicts as
 
 
66
    See also bzr conflicts.
 
 
68
    aliases = ['resolved']
 
 
69
    takes_args = ['file*']
 
 
70
    takes_options = [Option('all', help='Resolve all conflicts in this tree')]
 
 
71
    def run(self, file_list=None, all=False):
 
 
74
                raise BzrCommandError(
 
 
75
                    "command 'resolve' needs one or more FILE, or --all")
 
 
76
            tree = WorkingTree.open_containing(u'.')[0]
 
 
77
            file_list = list(tree.abspath(f) for f in tree.iter_conflicts())
 
 
80
                raise BzrCommandError(
 
 
81
                    "If --all is specified, no FILE may be provided")
 
 
82
        for filename in file_list:
 
 
84
            for suffix in CONFLICT_SUFFIXES:
 
 
86
                    os.unlink(filename+suffix)
 
 
88
                    if e.errno != errno.ENOENT:
 
 
92
            if failures == len(CONFLICT_SUFFIXES):
 
 
93
                if not os.path.exists(filename):
 
 
94
                    print "%s does not exist" % filename
 
 
96
                    print "%s is not conflicted" % filename
 
 
98
def restore(filename):
 
 
100
    Restore a conflicted file to the state it was in before merging.
 
 
101
    Only text restoration supported at present.
 
 
105
        rename(filename + ".THIS", filename)
 
 
108
        if e.errno != errno.ENOENT:
 
 
111
        os.unlink(filename + ".BASE")
 
 
114
        if e.errno != errno.ENOENT:
 
 
117
        os.unlink(filename + ".OTHER")
 
 
120
        if e.errno != errno.ENOENT:
 
 
123
        raise NotConflicted(filename)