Index: mergebot/trunk/utils/test.py
===================================================================
--- mergebot/trunk/utils/test.py	(revision 47)
+++ mergebot/trunk/utils/test.py	(revision 51)
@@ -189,4 +189,48 @@
 
 
+class FunctionalSvnTestCaseSetup(FunctionalTwillTestCaseSetup):
+    def get_workdir(self):
+        return os.path.join(self._testenv.dirname, self.__class__.__name__)
+
+    def checkout(self, ticket_id=None):
+        """checkout a working copy of the branch for the given ticket, or trunk if none given"""
+        if ticket_id is None:
+            svnurl = self._testenv.repo_url() + '/stuff/trunk'
+        else:
+            svnurl = self._testenv.repo_url() + '/stuff/branches/ticket-%s' % ticket_id
+        retval = call(['svn', 'checkout', svnurl, self.get_workdir()],
+            stdout=logfile, stderr=logfile)
+        self.assertEqual(retval, 0, "svn checkout failed with error %s" % (retval))
+
+    def switch(self, ticket_id=None):
+        if ticket_id is None:
+            svnurl = self._testenv.repo_url() + '/stuff/trunk'
+        else:
+            svnurl = self._testenv.repo_url() + '/stuff/branches/ticket-%s' % ticket_id
+        retval = call(['svn', 'switch', svnurl, self.get_workdir()],
+            stdout=logfile, stderr=logfile)
+        self.assertEqual(retval, 0, "svn checkout failed with error %s" % (retval))
+
+    def add_new_file(self, filename=None):
+        workdir = self.get_workdir()
+        if filename is None:
+            newfile = os.path.join(workdir, self.__class__.__name__)
+        else:
+            newfile = os.path.join(workdir, filename)
+        open(newfile, 'w').write(random_page())
+        retval = call(['svn', 'add', newfile],
+            cwd=workdir,
+            stdout=logfile, stderr=logfile)
+        self.assertEqual(retval, 0, "svn add failed with error %s" % (retval))
+
+    def commit(self, message, files=None):
+        if files is None:
+            files = ['.']
+        retval = call(['svn', 'commit', '-m', message] + list(files),
+            cwd=self.get_workdir(),
+            stdout=logfile, stderr=logfile)
+        self.assertEqual(retval, 0, "svn commit failed with error %s" % (retval))
+
+
 class MergeBotTestEnabled(FunctionalTwillTestCaseSetup):
     def runTest(self):
@@ -246,5 +290,5 @@
 
 
-class MergeBotTestRebranchWithChange(FunctionalTwillTestCaseSetup):
+class MergeBotTestRebranchWithChange(FunctionalSvnTestCaseSetup):
     def runTest(self):
         """Verify that the 'rebranch' button works with changes on the branch"""
@@ -254,20 +298,28 @@
 
         # checkout a working copy & make a change
-        svnurl = self._testenv.repo_url()
-        workdir = os.path.join(self._testenv.dirname, self.__class__.__name__)
-        retval = call(['svn', 'checkout', svnurl + '/stuff/branches/ticket-%s' % ticket_id, workdir],
-            stdout=logfile, stderr=logfile)
-        self.assertEqual(retval, 0, "svn checkout failed with error %s" % (retval))
+        self.checkout(ticket_id)
         # Create & add a new file
-        newfile = os.path.join(workdir, self.__class__.__name__)
-        open(newfile, 'w').write(random_page())
-        retval = call(['svn', 'add', self.__class__.__name__],
-            cwd=workdir,
-            stdout=logfile, stderr=logfile)
-        self.assertEqual(retval, 0, "svn add failed with error %s" % (retval))
-        retval = call(['svn', 'commit', '-m', 'Add a new file', self.__class__.__name__],
-            cwd=workdir,
-            stdout=logfile, stderr=logfile)
-        self.assertEqual(retval, 0, "svn commit failed with error %s" % (retval))
+        self.add_new_file()
+        self.commit('Add a new file')
+
+        self._tester.rebranch(ticket_id, 'stuff')
+
+
+class MergeBotTestRebranchWithChangeAndTrunkChange(FunctionalSvnTestCaseSetup):
+    def runTest(self):
+        """Verify that the 'rebranch' button works with changes on the branch"""
+        ticket_id = self._tester.create_ticket(summary=self.__class__.__name__,
+            info={'component':'stuff', 'version':'trunk'})
+        self._tester.branch(ticket_id, 'stuff')
+
+        # checkout a working copy & make a change
+        self.checkout(ticket_id)
+        # Create & add a new file
+        basename = self.__class__.__name__
+        self.add_new_file(basename + '-ticket')
+        self.commit('Add a new file on ticket')
+        self.switch()
+        self.add_new_file(basename + '-trunk')
+        self.commit('Add a new file on trunk')
 
         self._tester.rebranch(ticket_id, 'stuff')
@@ -313,4 +365,5 @@
     suite.addTest(MergeBotTestMerge())
     suite.addTest(MergeBotTestRebranchWithChange())
+    suite.addTest(MergeBotTestRebranchWithChangeAndTrunkChange())
     suite.addTest(MergeBotTestSingleUseCase())
     return suite
