Example #1
0
 def test_scrape_single(self):
     repo = Repo(local_url)
     commit = list(repo.revisions(slice(0, 1)))[0]
     activity = scraper._commit2activity(commit=commit)
     self.assertIsNotNone(activity)
     self.assertIsNotNone(activity.login)
     self.assertIsNotNone(activity.date)
Example #2
0
    def diff(self, filepath):
        """ Computes the diff of the filepath
        """

        repo = Repo(self.config.path)
        thepatch = repo.hg_command("diff", filepath)

        return thepatch
Example #3
0
File: util.py Project: jw/vonk
def repository_exists(path):
    o = urlparse(path)
    valid = False
    # local
    if o.scheme == '' or o.scheme == 'file':
        if exists(path):
            # exists, but is it a repository?
            repo = Repo(path)
            try:
                repo.hg_status()
                # is indeed a valid repository
                valid = True
            except HgException:
                pass
    # remote
    elif o.scheme == 'http' or o.scheme == 'https' or o.scheme == 'ssh':
        print("remote: {} -> {}".format(o, o.scheme))
        repo = Repo(path, user=o.username)
        try:
            repo.hg_status()
            # is indeed a valid repository
            valid = True
        except HgException:
            pass
    return valid
Example #4
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
Example #5
0
 def setUp(self):
     repo = Repo(ROOT)
     repo.hg_init()
     self.lm = LocalMonitor(repo, LocalHandler())
Example #6
0
File: util_test.py Project: 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))
Example #7
0
File: util_test.py Project: 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))
Example #8
0
File: util_test.py Project: 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))