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

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

Mergebot: redesigned implementation. Still has rough edges.

File size: 2.9 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        if not SvnOps.get_branch_info(self.local_url(), logfile):
31            comment = 'Component %s does not exist in the repository.' \
32                % self.component
33            return results, comment, False
34        if not SvnOps.get_branch_info(self.local_url() + '/branches', logfile):
35            comment = 'No directory in which to create branches for ' \
36                'component %s in the repository.' % self.component
37            return results, comment, False
38        if not SvnOps.get_branch_info(self.baseline_local_url(), logfile):
39            comment = 'Version %s for component %s does not exist in the ' \
40                'repository.' % (self.version, self.component)
41            return results, comment, False
42
43        branch_info = SvnOps.get_branch_info(self.branch_local_url(), logfile)
44        if not branch_info:
45            comment = 'Branch for ticket %s does not exist in the repository.' \
46                % (self.ticket)
47            return results, comment, False
48        startrev, endrev = branch_info
49
50        SvnOps.checkout(self.baseline_local_url(), workdir, logfile)
51        # TODO: check return code of the above
52        merge_results = SvnOps.merge(self.branch_local_url(), workdir,
53                                     (startrev, endrev), logfile)
54        conflicts = SvnOps.conflicts_from_merge_results(merge_results)
55        if conflicts:
56            message = '\n'.join([
57                'Found %s conflicts while checking merge of %s:%s to %s for ' \
58                    '%s.' % (len(conflicts), startrev, endrev, self.version,
59                    self.requestor),
60                'Files in conflict:',
61                '{{{',
62                '\n'.join(conflicts),
63                '}}}',
64                'A rebranch will be needed before this can be merged.',
65            ])
66            success = False
67        else:
68            message = 'Found no conflicts while checking merge of %s:%s to ' \
69                '%s for %s.' % (startrev, endrev, self.version, self.requestor)
70            success = True
71
72        # Clean up the work area
73        if os.path.exists(workdir):
74            shutil.rmtree(workdir)
75
76        return results, message, success
77
78# vim:foldcolumn=4 foldmethod=indent
79# vim:tabstop=4 shiftwidth=4 softtabstop=4 expandtab
Note: See TracBrowser for help on using the repository browser.