Ejemplo n.º 1
0
    def patch(self, patch, thefile, content=None):
        # if there's no diff, there's no conflict
        if patch in ("", None):
            return True

        try:
            # write the file in a temporary file
            tmpfile = tempfile.mkstemp()
            os.write(tmpfile[0], patch)

            # create a temp directory
            tmpdir = tempfile.mkdtemp()
            tmprepo = Repo(tmpdir)

            # initialize a new hg repo
            tmprepo.hg_init()

            # copy the file to patch in the temp directory
            rel_path = os.path.relpath(thefile, self.config.path)
            self._dir_tree(rel_path, tmpdir)

            shutil.copy2(thefile, os.path.join(tmpdir, rel_path))

            # add the file to the temp hg repo
            tmprepo.hg_add('.')

            # commit the current working tree
            tmprepo.hg_commit('Baboon commit')

            # import the patch in the tmpfile hg repo
            try:
                tmprepo.hg_command('import', tmpfile[1], '--no-commit')
            except Exception:
                # an exception is raised if the command failed
                return False
        finally:
            try:
                os.remove(tmpfile[1])
                shutil.rmtree(tmpdir)
            except:
                """ There's at least one error during the clean of tmpfile
                files. It's a pity but not fatal."""
                pass

        return True
Ejemplo n.º 2
0
 def setUp(self):
     repo = Repo(ROOT)
     repo.hg_init()
     self.lm = LocalMonitor(repo, LocalHandler())
Ejemplo n.º 3
0
Archivo: util_test.py Proyecto: jw/vonk
 def test_repository_exists_file(self):
     self.assertFalse(repository_exists(LOCAL_ROOT_FILE))
     repo = Repo(LOCAL_ROOT_FILE)
     repo.hg_init()
     self.assertTrue(repository_exists(LOCAL_ROOT_FILE))
Ejemplo n.º 4
0
Archivo: util_test.py Proyecto: jw/vonk
 def test_repository_exists_ssh(self):
     self.assertFalse(repository_exists(REMOTE_ROOT_SSH))
     repo = Repo(REMOTE_ROOT_SSH)
     repo.hg_init()
     self.assertTrue(repository_exists(REMOTE_ROOT_SSH))
Ejemplo n.º 5
0
Archivo: util_test.py Proyecto: jw/vonk
 def test_repository_exists_path(self):
     self.assertFalse(repository_exists(LOCAL_ROOT_PATH))
     repo = Repo(LOCAL_ROOT_PATH)
     repo.hg_init()
     self.assertTrue(repository_exists(LOCAL_ROOT_PATH))