bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
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  | 
||
| 
1185.16.11
by Martin Pool
 todo  | 
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  | 
||
| 
1185.16.33
by Martin Pool
 - move 'conflict' and 'resolved' from shipped plugin to regular builtins  | 
25  | 
import os  | 
26  | 
import errno  | 
|
27  | 
||
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
28  | 
import bzrlib.status  | 
| 
1551.2.18
by Aaron Bentley
 Updated docs to clarify conflict handling  | 
29  | 
from bzrlib.commands import register_command  | 
| 
1185.35.1
by Aaron Bentley
 Implemented conflicts.restore  | 
30  | 
from bzrlib.errors import BzrCommandError, NotConflicted  | 
| 
1551.2.18
by Aaron Bentley
 Updated docs to clarify conflict handling  | 
31  | 
from bzrlib.option import Option  | 
| 
1551.2.17
by Aaron Bentley
 Fixed conflict commands  | 
32  | 
from bzrlib.workingtree import CONFLICT_SUFFIXES, WorkingTree  | 
| 
1185.31.49
by John Arbash Meinel
 Some corrections using the new osutils.rename. **ALL TESTS PASS**  | 
33  | 
from bzrlib.osutils import rename  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
34  | 
|
35  | 
class cmd_conflicts(bzrlib.commands.Command):  | 
|
36  | 
"""List files with conflicts.  | 
|
| 
1551.2.18
by Aaron Bentley
 Updated docs to clarify conflict handling  | 
37  | 
|
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.
 | 
|
42  | 
||
43  | 
    Use bzr resolve when you have fixed a problem.
 | 
|
44  | 
||
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
45  | 
    (conflicts are determined by the presence of .BASE .TREE, and .OTHER 
 | 
46  | 
    files.)
 | 
|
| 
1551.2.18
by Aaron Bentley
 Updated docs to clarify conflict handling  | 
47  | 
|
48  | 
    See also bzr resolve.
 | 
|
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
49  | 
    """
 | 
50  | 
def run(self):  | 
|
| 
1551.2.17
by Aaron Bentley
 Fixed conflict commands  | 
51  | 
for path in WorkingTree.open_containing(u'.')[0].iter_conflicts():  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
52  | 
print path  | 
53  | 
||
54  | 
class cmd_resolve(bzrlib.commands.Command):  | 
|
55  | 
"""Mark a conflict as resolved.  | 
|
| 
1551.2.18
by Aaron Bentley
 Updated docs to clarify conflict handling  | 
56  | 
|
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.
 | 
|
61  | 
||
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
 | 
|
64  | 
    resolved.
 | 
|
65  | 
||
66  | 
    See also bzr conflicts.
 | 
|
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
67  | 
    """
 | 
| 
1185.33.24
by Martin Pool
 Add alias 'resolved'  | 
68  | 
aliases = ['resolved']  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
69  | 
takes_args = ['file*']  | 
| 
1551.2.18
by Aaron Bentley
 Updated docs to clarify conflict handling  | 
70  | 
takes_options = [Option('all', help='Resolve all conflicts in this tree')]  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
71  | 
def run(self, file_list=None, all=False):  | 
72  | 
if file_list is None:  | 
|
73  | 
if not all:  | 
|
74  | 
raise BzrCommandError(  | 
|
75  | 
"command 'resolve' needs one or more FILE, or --all")  | 
|
| 
1551.2.17
by Aaron Bentley
 Fixed conflict commands  | 
76  | 
tree = WorkingTree.open_containing(u'.')[0]  | 
| 
1185.14.6
by Aaron Bentley
 Made iter_conflicts a WorkingTree method  | 
77  | 
file_list = list(tree.abspath(f) for f in tree.iter_conflicts())  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
78  | 
else:  | 
79  | 
if all:  | 
|
80  | 
raise BzrCommandError(  | 
|
81  | 
"If --all is specified, no FILE may be provided")  | 
|
82  | 
for filename in file_list:  | 
|
83  | 
failures = 0  | 
|
| 
1185.14.6
by Aaron Bentley
 Made iter_conflicts a WorkingTree method  | 
84  | 
for suffix in CONFLICT_SUFFIXES:  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
85  | 
try:  | 
86  | 
os.unlink(filename+suffix)  | 
|
87  | 
except OSError, e:  | 
|
88  | 
if e.errno != errno.ENOENT:  | 
|
89  | 
                        raise
 | 
|
90  | 
else:  | 
|
91  | 
failures += 1  | 
|
| 
1185.14.6
by Aaron Bentley
 Made iter_conflicts a WorkingTree method  | 
92  | 
if failures == len(CONFLICT_SUFFIXES):  | 
| 
1185.14.3
by Aaron Bentley
 Copied conflict lister in  | 
93  | 
if not os.path.exists(filename):  | 
94  | 
print "%s does not exist" % filename  | 
|
95  | 
else:  | 
|
96  | 
print "%s is not conflicted" % filename  | 
|
| 
1185.35.1
by Aaron Bentley
 Implemented conflicts.restore  | 
97  | 
|
98  | 
def restore(filename):  | 
|
99  | 
"""\  | 
|
100  | 
    Restore a conflicted file to the state it was in before merging.
 | 
|
101  | 
    Only text restoration supported at present.
 | 
|
102  | 
    """
 | 
|
103  | 
conflicted = False  | 
|
104  | 
try:  | 
|
| 
1185.31.49
by John Arbash Meinel
 Some corrections using the new osutils.rename. **ALL TESTS PASS**  | 
105  | 
rename(filename + ".THIS", filename)  | 
| 
1185.35.1
by Aaron Bentley
 Implemented conflicts.restore  | 
106  | 
conflicted = True  | 
107  | 
except OSError, e:  | 
|
108  | 
if e.errno != errno.ENOENT:  | 
|
109  | 
            raise
 | 
|
110  | 
try:  | 
|
111  | 
os.unlink(filename + ".BASE")  | 
|
112  | 
conflicted = True  | 
|
113  | 
except OSError, e:  | 
|
114  | 
if e.errno != errno.ENOENT:  | 
|
115  | 
            raise
 | 
|
116  | 
try:  | 
|
117  | 
os.unlink(filename + ".OTHER")  | 
|
118  | 
conflicted = True  | 
|
119  | 
except OSError, e:  | 
|
120  | 
if e.errno != errno.ENOENT:  | 
|
121  | 
            raise
 | 
|
122  | 
if not conflicted:  | 
|
123  | 
raise NotConflicted(filename)  |