Beispiel #1
0
    def testJournal(self):
        """Verify the state file journal"""

        from os.path import exists

        rontf = ReopenableNamedTemporaryFile('sf', 'tailor')

        sf = StateFile(rontf.name, None)
        sf.setPendingChangesets([1, 2, 3, 4, 5])

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), None)
        cs = sf.next()
        sf.applied()
        self.assertEqual(sf.lastAppliedChangeset(), 1)
        cs = sf.next()
        sf.applied()
        self.assertEqual(sf.lastAppliedChangeset(), 2)
        self.assert_(exists(rontf.name + '.journal'))

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), 2)
        i = 3
        for cs in sf:
            self.assertEqual(cs, i)
            i += 1
Beispiel #2
0
    def _commit(self,
                date,
                author,
                patchname,
                changelog=None,
                entries=None,
                tags=[],
                isinitialcommit=False):
        """
        Commit the changeset.
        """

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)

        # If we cannot use propset, fall back to old behaviour of
        # appending these info to the changelog

        if not self.repository.use_propset:
            logmessage.append('')
            logmessage.append('Original author: %s' % encode(author))
            logmessage.append('Date: %s' % date)
        elif not self.repository.propset_date:
            logmessage.append('')
            logmessage.append('Date: %s' % date)

        rontf = ReopenableNamedTemporaryFile('svn', 'tailor')
        log = open(rontf.name, "w")
        log.write(encode('\n'.join(logmessage)))
        log.close()

        cmd = self.repository.command("commit", "--file", rontf.name)
        commit = ExternalCommand(cwd=self.repository.basedir, command=cmd)

        if not entries or self.repository.commit_all_files:
            entries = ['.']

        out, err = commit.execute(entries, stdout=PIPE, stderr=PIPE)

        if commit.exit_status:
            raise ChangesetApplicationFailure(
                "%s returned status %d saying\n%s" %
                (str(commit), commit.exit_status, err.read()))

        revision = self._propsetRevision(out, commit, date, author)
        if not revision:
            # svn did not find anything to commit
            return

        cmd = self.repository.command("update", "--quiet")
        if self.repository.ignore_externals:
            cmd.append("--ignore-externals")
        cmd.extend(["--revision", revision])

        ExternalCommand(cwd=self.repository.basedir, command=cmd).execute()
Beispiel #3
0
    def testStateFile(self):
        """Verify the state file behaviour"""

        rontf = ReopenableNamedTemporaryFile('sf', 'tailor')

        sf = StateFile(rontf.name, None)
        sf.setPendingChangesets([1, 2, 3, 4, 5])

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), None)
        i = 1
        for cs in sf:
            self.assertEqual(cs, i)
            i += 1

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), None)
        cs = sf.next()
        sf.applied()
        self.assertEqual(sf.lastAppliedChangeset(), 1)
        cs = sf.next()
        sf.applied()
        self.assertEqual(sf.lastAppliedChangeset(), 2)
        sf.finalize()
        self.assertEqual(sf.pending(), True)

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), 2)
        i = 3
        for cs in sf:
            self.assertEqual(cs, i)
            sf.applied()
            i += 1
        sf.finalize()
        self.assertEqual(sf.pending(), False)
Beispiel #4
0
    def testDarcsChangesets(self):
        """Verify the behaviour with Darcs changesets"""

        from os.path import exists
        from vcpx.repository.darcs.source import DarcsChangeset

        changesets = [
            DarcsChangeset("Add dir/a{1,2,3}", None, None, None, [
                Entry(Entry.ADDED, 'dir/'),
                Entry(Entry.ADDED, 'dir/a1'),
                Entry(Entry.ADDED, 'dir/a2'),
                Entry(Entry.ADDED, 'dir/a3'),
            ]),
            DarcsChangeset("Initially empty", None, None, None, []),
            DarcsChangeset("Spread around", None, None, None, [
                Entry(Entry.RENAMED, 'a.root', 'dir/a1'),
                Entry(Entry.RENAMED, 'b.root', 'dir/a2'),
                Entry(Entry.RENAMED, 'newdir/', 'dir/'),
                Entry(Entry.UPDATED, 'newdir/a3', contents="ciao"),
            ]),
        ]

        rontf = ReopenableNamedTemporaryFile('sf', 'tailor')

        sf = StateFile(rontf.name, None)
        sf.setPendingChangesets(changesets)

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), None)
        cs = sf.next()
        sf.applied()
        sf.finalize()

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), changesets[0])
        cs = sf.next()
        self.assertEqual(cs, changesets[1])
        self.assertEqual(sf.lastAppliedChangeset(), changesets[0])
        sf.finalize()

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), changesets[0])
        cs = sf.next()
        self.assertEqual(cs, changesets[1])

        # Some source backends refine the just applied changeset,
        # usually adding entries. Be sure that does not interfere
        # with the journal
        cs.entries.append(Entry(Entry.ADDED, 'dir2'))
        cs.darcs_hash = 'abc'
        self.assertEqual(cs, changesets[1])
        self.assertNotEqual(len(cs.entries), len(changesets[1].entries))
        sf.applied()
        self.assertEqual(sf.lastAppliedChangeset(), changesets[1])

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), changesets[1])
        cs = sf.next()

        self.assertRaises(StopIteration, sf.next)
Beispiel #5
0
 def __change_attribute_file(self, *args, **kwargs):
     """
     Create a temporary file to modify change's attributes.
     """
     if kwargs['brief_description']:
         brief_description = \
             self.repository.normalize(kwargs['brief_description'])
     else:
         brief_description = 'none'
     if kwargs['description']:
         description = \
             self.repository.normalize(kwargs['description'])
     else:
         description = "none"
     attribute_file = ReopenableNamedTemporaryFile('aegis', 'tailor')
     fd = open(attribute_file.name, 'wb')
     fd.write("""
         brief_description = "%s";
         description = "%s";
         cause = external_improvement;
         test_exempt = true;
         test_baseline_exempt = true;
         regression_test_exempt = true;
         """ % (brief_description, description))
     fd.close()
     return attribute_file
Beispiel #6
0
    def _commit(self,
                date,
                author,
                patchname,
                changelog=None,
                entries=None,
                tags=[],
                isinitialcommit=False):
        """
        Commit the changeset.
        """

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)

        rontf = ReopenableNamedTemporaryFile('mtn', 'tailor')
        log = open(rontf.name, "w")
        log.write(encode('\n'.join(logmessage)))
        log.close()

        date = date.astimezone(UTC).replace(microsecond=0,
                                            tzinfo=None)  # monotone wants UTC
        cmd = self.repository.command("commit",
                                      "--author", encode(author), "--date",
                                      date.isoformat(), "--message-file",
                                      rontf.name)
        commit = ExternalCommand(cwd=self.repository.basedir, command=cmd)

        # Always commit everything, ignoring given entries...
        # XXX is this right?
        entries = ['.']

        output, error = commit.execute(entries, stdout=PIPE, stderr=PIPE)

        # monotone complaints if there are no changes from the last commit.
        # we ignore those errors ...
        if commit.exit_status:
            text = error.read()
            if not "mtn: misuse: no changes to commit" in text:
                self.log.error("Monotone commit said: %s", text)
                raise ChangesetApplicationFailure(
                    "%s returned status %s" %
                    (str(commit), commit.exit_status))
            else:
                self.log.info("No changes to commit - changeset ignored")
Beispiel #7
0
 def __new_change(self, title="none", description="none"):
     change_attr_file = \
         self.__change_attribute_file(brief_description = title,
                                      description = description)
     change_number_file = ReopenableNamedTemporaryFile('aegis', 'tailor')
     cmd = self.repository.command("-new_change", "-project",
                                   self.repository.module, "-file",
                                   change_attr_file.name, "-output",
                                   change_number_file.name)
     new_change = ExternalCommand(cwd="/tmp", command=cmd)
     output = new_change.execute(stdout=PIPE, stderr=STDOUT)[0]
     if new_change.exit_status > 0:
         raise ChangesetApplicationFailure(
             "%s returned status %d, saying: %s" %
             (str(new_change), new_change.exit_status, output.read()))
     fd = open(change_number_file.name, "rb")
     change_number = fd.read()
     fd.close()
     return change_number.strip()
Beispiel #8
0
    def _commit(self,
                date,
                author,
                patchname,
                changelog=None,
                entries=None,
                tags=[],
                isinitialcommit=False):
        """
        Commit the changeset.
        """

        from vcpx.shwrap import ReopenableNamedTemporaryFile

        encode = self.repository.encode

        logmessage = []
        if patchname:
            logmessage.append(patchname)
        if changelog:
            logmessage.append(changelog)
        logmessage.append('')
        logmessage.append('Original author: %s' % author)
        logmessage.append('Date: %s' % date)

        rontf = ReopenableNamedTemporaryFile('cvs', 'tailor')
        log = open(rontf.name, "w")
        log.write(encode('\n'.join(logmessage)))
        log.close()

        cmd = self.repository.command("-f", "-q", "ci", "-F", rontf.name)
        if not entries:
            entries = ['.']

        c = ExternalCommand(cwd=self.repository.basedir, command=cmd)
        c.execute(entries)

        if c.exit_status:
            raise ChangesetApplicationFailure("%s returned status %d" %
                                              (str(c), c.exit_status))
Beispiel #9
0
    def testSimilarChangesets(self):
        """Verify how the statefile considers two similar changesets"""

        from os.path import exists
        from vcpx.repository.darcs.source import DarcsChangeset

        ts1 = Changeset.Date.next()
        ts2 = ts3 = Changeset.Date.next()
        ts4 = Changeset.Date.next()

        changesets = [
            DarcsChangeset("Add dir/a{1,2,3}",
                           ts1,
                           'me@here',
                           None, [
                               Entry(Entry.ADDED, 'dir/'),
                               Entry(Entry.ADDED, 'dir/a1'),
                               Entry(Entry.ADDED, 'dir/a2'),
                               Entry(Entry.ADDED, 'dir/a3'),
                           ],
                           darcs_hash='abc'),
            DarcsChangeset("Initially empty",
                           ts2,
                           'me@here',
                           None, [],
                           darcs_hash='def'),
            DarcsChangeset("Initially empty",
                           ts3,
                           'me@here',
                           None, [],
                           darcs_hash='ghi'),
            DarcsChangeset(
                "Spread around",
                ts4,
                'me@here',
                None, [
                    Entry(Entry.RENAMED, 'a.root', 'dir/a1'),
                    Entry(Entry.RENAMED, 'b.root', 'dir/a2'),
                    Entry(Entry.RENAMED, 'newdir/', 'dir/'),
                    Entry(Entry.UPDATED, 'newdir/a3', contents="ciao"),
                ],
                darcs_hash='xyz'),
        ]

        self.assertNotEqual(changesets[1], changesets[2])

        rontf = ReopenableNamedTemporaryFile('sf', 'tailor')

        sf = StateFile(rontf.name, None)
        sf.setPendingChangesets(changesets)

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), None)
        cs = sf.next()
        self.assertEqual(cs.darcs_hash, 'abc')
        sf.applied()
        sf.finalize()

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), changesets[0])
        cs = sf.next()
        self.assertEqual(cs, changesets[1])
        self.assertEqual(cs.darcs_hash, 'def')
        self.assertEqual(sf.lastAppliedChangeset(), changesets[0])
        sf.finalize()

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), changesets[0])

        cs = sf.next()
        self.assertEqual(cs, changesets[1])
        self.assertEqual(cs.darcs_hash, 'def')
        cs.entries.append(Entry(Entry.ADDED, 'dir2'))
        self.assertEqual(cs, changesets[1])
        self.assertNotEqual(len(cs.entries), len(changesets[1].entries))
        sf.applied()
        self.assertEqual(sf.lastAppliedChangeset(), changesets[1])

        cs = sf.next()
        self.assertEqual(cs, changesets[2])
        self.assertEqual(cs.darcs_hash, 'ghi')
        cs.entries.append(Entry(Entry.ADDED, 'dir3'))
        self.assertEqual(cs, changesets[2])
        sf.applied()

        sf = StateFile(rontf.name, None)
        self.assertEqual(sf.lastAppliedChangeset(), changesets[2])
        cs = sf.next()

        self.assertRaises(StopIteration, sf.next)