~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/conflicts.py

Implemented conflicts.restore

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 
28
28
import bzrlib.status
29
29
from bzrlib.branch import Branch
30
 
from bzrlib.errors import BzrCommandError
 
30
from bzrlib.errors import BzrCommandError, NotConflicted
31
31
from bzrlib.commands import register_command
32
32
from bzrlib.workingtree import CONFLICT_SUFFIXES
33
33
 
71
71
                    print "%s does not exist" % filename
72
72
                else:
73
73
                    print "%s is not conflicted" % filename
 
74
 
 
75
def restore(filename):
 
76
    """\
 
77
    Restore a conflicted file to the state it was in before merging.
 
78
    Only text restoration supported at present.
 
79
    """
 
80
    conflicted = False
 
81
    try:
 
82
        os.rename(filename + ".THIS", filename)
 
83
        conflicted = True
 
84
    except OSError, e:
 
85
        if e.errno != errno.ENOENT:
 
86
            raise
 
87
    try:
 
88
        os.unlink(filename + ".BASE")
 
89
        conflicted = True
 
90
    except OSError, e:
 
91
        if e.errno != errno.ENOENT:
 
92
            raise
 
93
    try:
 
94
        os.unlink(filename + ".OTHER")
 
95
        conflicted = True
 
96
    except OSError, e:
 
97
        if e.errno != errno.ENOENT:
 
98
            raise
 
99
    if not conflicted:
 
100
        raise NotConflicted(filename)