source: mergebot/trunk/mergebot/CheckMergeActor.py @ 24

Last change on this file since 24 was 24, checked in by retracile, 15 years ago

Ticket #2: merge to trunk

File size: 2.3 KB
Line 
1#!/usr/bin/env python
2"""
3Verify that a branch can be merged to its trunk without conflicts, but don't
4commit the merge.
5"""
6
7import os
8import shutil
9
10from mergebot import SvnOps
11from mergebot.Actor import Actor
12
13class CheckMergeActor(Actor):
14    """Checks that this ticket can be merged to its baseline, but don't modify
15    the repository.
16    """
17    def execute(self):
18        """
19        Verify that a branch can be merged to its trunk without conflicts, but
20        don't commit the merge.
21        """
22        results = {}
23        workdir = self.work_dir
24        logfile = self.logfilename()
25
26        if os.path.exists(workdir):
27            shutil.rmtree(workdir)
28
29        # Make sure the various urls we require do exist
30        problems = self.check_required_directories()
31        if problems:
32            return results, problems, False
33
34        branch_info = SvnOps.get_branch_info(self.branch_local_url(), logfile)
35        if not branch_info:
36            comment = 'Branch for ticket %s does not exist in the repository.' \
37                % (self.ticket)
38            return results, comment, False
39        startrev, endrev = branch_info
40
41        SvnOps.checkout(self.baseline_local_url(), workdir, logfile)
42        # TODO: check return code of the above
43        merge_results = SvnOps.merge(self.branch_local_url(), workdir,
44                                     (startrev, endrev), logfile)
45        conflicts = SvnOps.conflicts_from_merge_results(merge_results)
46        if conflicts:
47            message = '\n'.join([
48                'Found %s conflicts while checking merge of %s:%s to %s for ' \
49                    '%s.' % (len(conflicts), startrev, endrev, self.version,
50                    self.requestor),
51                'Files in conflict:',
52                '{{{',
53                '\n'.join(conflicts),
54                '}}}',
55                'A rebranch will be needed before this can be merged.',
56            ])
57            success = False
58        else:
59            message = 'Found no conflicts while checking merge of %s:%s to ' \
60                '%s for %s.' % (startrev, endrev, self.version, self.requestor)
61            success = True
62
63        # Clean up the work area
64        if os.path.exists(workdir):
65            shutil.rmtree(workdir)
66
67        return results, message, success
68
69# vim:foldcolumn=4 foldmethod=indent
70# vim:tabstop=4 shiftwidth=4 softtabstop=4 expandtab
Note: See TracBrowser for help on using the repository browser.