Example #1
0
def _upgrade(ui, repo):
    ext_dir = os.path.dirname(os.path.abspath(__file__))
    ui.debug(_('kiln: checking for extensions upgrade for %s\n') % ext_dir)

    try:
        r = localrepo.localrepository(hgui.ui(), ext_dir)
    except RepoError:
        commands.init(hgui.ui(), dest=ext_dir)
        r = localrepo.localrepository(hgui.ui(), ext_dir)

    r.ui.setconfig('kiln', 'autoupdate', False)
    r.ui.pushbuffer()
    try:
        source = 'https://developers.kilnhg.com/Repo/Kiln/Group/Kiln-Extensions'
        if commands.incoming(r.ui, r, bundle=None, force=False, source=source) != 0:
            # no incoming changesets, or an error. Don't try to upgrade.
            ui.debug('kiln: no extensions upgrade available\n')
            return
        ui.write(_('updating Kiln Extensions at %s... ') % ext_dir)
        # pull and update return falsy values on success
        if commands.pull(r.ui, r, source=source) or commands.update(r.ui, r, clean=True):
            url = urljoin(repo.url()[:repo.url().lower().index('/repo')], 'Tools')
            ui.write(_('unable to update\nvisit %s to download the newest extensions\n') % url)
        else:
            ui.write(_('complete\n'))
    except Exception, e:
        ui.debug(_('kiln: error updating extensions: %s\n') % e)
        ui.debug(_('kiln: traceback: %s\n') % traceback.format_exc())
Example #2
0
 def init(cls, path):
     if os.path.isdir(path):
         shutil.rmtree(path)
     os.mkdir(path)
     ui = cls._ui()
     hgcommands.init(ui, path)
     return repository(ui, path)
Example #3
0
    def test_handlePushes_cause_repoerror(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///does/not/exist'
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': '******',
        })
        self.assertRaises(RepoError, handlePushes,
                          repo.pk, [pushjs0])
Example #4
0
    def test_handlePushes_cause_repoerror(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///does/not/exist')
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        self.assertRaises(RepoError, handlePushes, repo.pk, [pushjs0])
Example #5
0
def _upgrade(ui, repo):
    ext_dir = os.path.dirname(os.path.abspath(__file__))
    ui.debug('kiln: checking for extensions upgrade for %s\n' % ext_dir)

    try:
        r = localrepo.localrepository(hgui.ui(), ext_dir)
    except RepoError:
        commands.init(hgui.ui(), dest=ext_dir)
        r = localrepo.localrepository(hgui.ui(), ext_dir)

    r.ui.setconfig('kiln', 'autoupdate', False)
    r.ui.pushbuffer()
    try:
        source = 'https://developers.kilnhg.com/Repo/Kiln/Group/Kiln-Extensions'
        if commands.incoming(r.ui, r, bundle=None, force=False, source=source) != 0:
            # no incoming changesets, or an error. Don't try to upgrade.
            ui.debug('kiln: no extensions upgrade available\n')
            return
        ui.write(_('updating Kiln Extensions at %s... ') % ext_dir)
        # pull and update return falsy values on success
        if commands.pull(r.ui, r, source=source) or commands.update(r.ui, r, clean=True):
            url = urljoin(repo.url()[:repo.url().lower().index('/repo')], 'Tools')
            ui.write(_('unable to update\nvisit %s to download the newest extensions\n') % url)
        else:
            ui.write(_('complete\n'))
    except Exception, e:
        ui.debug(_('kiln: error updating Kiln Extensions: %s\n') % e)
Example #6
0
    def setUp(self):
        self.repo_path = mkdtemp()
        self.ui = ui.ui()
        self.ui.setconfig('ui', 'username', 'foo <*****@*****.**>')
        self.ui.setconfig('ui', 'quiet', True)
        commands.init(self.ui, self.repo_path)
        self.repo = hg.repository(self.ui, self.repo_path)
        file_dir = os.path.join(self.repo_path, 'content')
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)
        for i in range(3):
            file_path = os.path.join(file_dir, 'page-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_PAGE)
            commands.add(self.ui, self.repo, file_path)
        file_path = os.path.join(file_dir, 'about.rst')
        with codecs.open(file_path, 'w', encoding='utf-8') as fp:
            fp.write(SAMPLE_PAGE + """
.. aliases: 301:/my-old-post-location/,/another-old-location/""")
        commands.add(self.ui, self.repo, file_path)
        file_dir = os.path.join(self.repo_path, 'content', 'post')
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)
        for i in range(3):
            file_path = os.path.join(file_dir, 'post-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_POST)
            commands.add(self.ui, self.repo, file_path)
        file_path = os.path.join(file_dir, 'foo.rst')
        with codecs.open(file_path, 'w', encoding='utf-8') as fp:
            # using the page template, because we want to set tags manually
            fp.write(SAMPLE_PAGE + """
.. tags: foo, bar, lol""")
        commands.add(self.ui, self.repo, file_path)
        commands.commit(self.ui, self.repo, message='foo', user='******')
Example #7
0
    def setUp(self):
        self.repo_path = mkdtemp()
        self.ui = ui.ui()
        self.ui.setconfig('ui', 'username', 'foo <*****@*****.**>')
        self.ui.setconfig('ui', 'quiet', True)
        commands.init(self.ui, self.repo_path)
        self.repo = hg.repository(self.ui, self.repo_path)
        file_dir = os.path.join(self.repo_path, 'content')
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)
        for i in range(3):
            file_path = os.path.join(file_dir, 'page-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_PAGE)
            commands.add(self.ui, self.repo, file_path)
        file_path = os.path.join(file_dir, 'about.rst')
        with codecs.open(file_path, 'w', encoding='utf-8') as fp:
            fp.write(SAMPLE_PAGE + """
.. aliases: 301:/my-old-post-location/,/another-old-location/""")
        commands.add(self.ui, self.repo, file_path)
        file_dir = os.path.join(self.repo_path, 'content', 'post')
        if not os.path.isdir(file_dir):
            os.makedirs(file_dir)
        for i in range(3):
            file_path = os.path.join(file_dir, 'post-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_POST)
            commands.add(self.ui, self.repo, file_path)
        file_path = os.path.join(file_dir, 'foo.rst')
        with codecs.open(file_path, 'w', encoding='utf-8') as fp:
            # using the page template, because we want to set tags manually
            fp.write(SAMPLE_PAGE + """
.. tags: foo, bar, lol""")
        commands.add(self.ui, self.repo, file_path)
        commands.commit(self.ui, self.repo, message='foo', user='******')
Example #8
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_repeated(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "******"})
        # first time
        pushes_initial = Push.objects.all().count()
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after = Push.objects.all().count()
        self.assertEqual(pushes_initial, pushes_after - 1)

        # a second time should be harmless
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after_after = Push.objects.all().count()
        self.assertEqual(pushes_after, pushes_after_after)
Example #9
0
File: tests.py Project: gerv/elmo
    def test_file_only_copied(self):
        """Change by copying a file with no content editing"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.copy(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd"))
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("copied from file.dtd" in re.sub("<.*?>", "", html_diff))
        ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff))
        ok_(not re.findall(">\s*Hello\s*<", html_diff))
        ok_(not re.findall(">\s*Cruel\s*<", html_diff))
Example #10
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd "), "w").write(  # deliberate trailing space
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "******"})
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, "file.dtd ")
Example #11
0
File: tests.py Project: gerv/elmo
    def test_file_edited_broken_encoding(self):
        """Change by editing a good with a broken edit"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)

        (open(hgrepo.pathto("file.dtd"), "w").write(u'<!ENTITY key1 "Hello">\n'))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        # do this to trigger an exception on Mozilla.Parser.readContents
        _content = u'<!ENTITY key1 "Hell\xe3">\n'
        (codecs.open(hgrepo.pathto("file.dtd"), "w", "latin1").write(_content))

        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/" + self.repo_name + "/"
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("Cannot parse file" in html_diff)
        # also, expect a link to this file
        change_url = repo_url + "file/%s/file.dtd" % rev1
        ok_('href="%s"' % change_url in html_diff)
Example #12
0
File: tests.py Project: gerv/elmo
    def test_remove_file(self):
        """Change by removing a file, with parser"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.remove(ui, hgrepo, "path:file.dtd")
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.dtd\s*<", html_diff))
        # 2 entities with 2 rows each
        eq_(html_diff.count('<tr class="line-removed">'), 4)
        ok_(re.findall(">\s*key1\s*<", html_diff))
        ok_(re.findall(">\s*Hello\s*<", html_diff))
        ok_(re.findall(">\s*key2\s*<", html_diff))
        ok_(re.findall(">\s*Cruel\s*<", html_diff))
Example #13
0
 def setUp(self):
     # create a test repo location.
     self.tmpdir = tempfile.mkdtemp('hg-git_url-test')
     self.tmpdir = util.to_bytes(self.tmpdir)
     commands.init(ui.ui(), self.tmpdir)
     repo = hg.repository(ui.ui(), self.tmpdir)
     self.handler = GitHandler(repo, ui.ui())
Example #14
0
File: tests.py Project: gerv/elmo
    def test_error_handling(self):
        """Test various bad request parameters to the diff_app
        and assure that it responds with the right error codes."""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {})
        eq_(response.status_code, 400)
        response = self.client.get(url, {"repo": "junk"})
        eq_(response.status_code, 404)

        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        # missing 'from' and 'to'
        response = self.client.get(url, {"repo": self.repo_name})
        eq_(response.status_code, 400)

        # missing 'to'
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0})
        eq_(response.status_code, 400)
Example #15
0
    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///' + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd '), 'w')  # deliberate trailing space
         .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, 'file.dtd ')
Example #16
0
 def setUp(self):
     self.repo_path = mkdtemp()
     self.repo_pathb = u2hg(self.repo_path)
     self.ui = ui.ui()
     self.ui.setconfig(b'ui', b'quiet', True)
     commands.init(self.ui, self.repo_pathb)
     self.repo = hg.repository(self.ui, self.repo_pathb)
Example #17
0
File: tests.py Project: gerv/elmo
    def test_remove_file_no_parser(self):
        """Change by removing a file, without parser"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto("file.txt"), "w").write("line 1\nline 2\n"))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        hgcommands.remove(ui, hgrepo, "path:file.txt")
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/%s/" % self.repo_name
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.txt\s*<", html_diff))
        # 1 removed file
        eq_(html_diff.count('<div class="diff file-removed">'), 1)
        # also, expect a link to the old revision of the file
        change_ref = 'href="%sfile/%s/file.txt"' % (repo_url, rev0)
        ok_(change_ref in html_diff)
        ok_(not re.findall(">\s*line 1\s*<", html_diff))
        ok_(not re.findall(">\s*line 2\s*<", html_diff))
Example #18
0
 def init(cls, path):
     if os.path.isdir(path):
         shutil.rmtree(path)
     os.mkdir(path)
     ui = cls._ui()
     hgcommands.init(ui, path)
     return repository(ui, path)
Example #19
0
    def test_handlePushes_space_files(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///' + self.repo
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd '), 'w')  # deliberate trailing space
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': '******',
        })
        handlePushes(repo.pk, [pushjs0])

        file_, = File.objects.all()
        self.assertEqual(file_.path, 'file.dtd ')
Example #20
0
    def test_handlePushes_twice(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file://' + self.repo
        )

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
          'date': timestamp,
          'changesets': [rev0],
          'user': '******',
        })
        result = handlePushes(repo.pk, [pushjs0])

        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             '''))
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {
          'date': timestamp,
          'changesets': [rev1],
          'user': '******',
        })

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
Example #21
0
    def test_handlePushes_twice(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file://' + self.repo)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        result = handlePushes(repo.pk, [pushjs0])

        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             '''))
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {
            'date': timestamp,
            'changesets': [rev1],
            'user': '******',
        })

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
Example #22
0
File: tests.py Project: gerv/elmo
    def test_diff_base_against_clone(self):
        """Test that the right error is raised on trying to do a diff across
        a different divergant clone"""
        ui = mock_ui()
        orig = os.path.join(settings.REPOSITORY_BASE, "orig")
        clone = os.path.join(settings.REPOSITORY_BASE, "clone")
        hgcommands.init(ui, orig)
        hgorig = repository(ui, orig)
        (
            open(hgorig.pathto("file.dtd"), "w").write(
                """
          <!ENTITY old "content we will delete">
          <!ENTITY mod "this has stuff to keep and delete">
        """
            )
        )
        hgcommands.addremove(ui, hgorig)
        hgcommands.commit(ui, hgorig, user="******", message="initial commit")
        assert len(hgorig) == 1  # 1 commit

        # set up a second repo called 'clone'
        hgcommands.clone(ui, orig, clone)
        hgclone = repository(ui, clone)

        # new commit on base
        (
            open(hgorig.pathto("file.dtd"), "w").write(
                """
         <!ENTITY mod "this has stuff to keep and add">
         <!ENTITY new "this has stuff that is new">
         """
            )
        )
        hgcommands.commit(ui, hgorig, user="******", message="second commit on base")
        assert len(hgorig) == 2  # 2 commits
        rev_from = hgorig[1].hex()

        # different commit on clone
        (
            open(hgclone.pathto("file.dtd"), "w").write(
                """
         <!ENTITY mod "this has stuff to keep and change">
         <!ENTITY new_in_clone "this has stuff that is different from base">
         """
            )
        )
        hgcommands.commit(ui, hgclone, user="******", message="a different commit on clone")
        rev_to = hgclone[1].hex()

        Repository.objects.create(name="orig", url="http://localhost:8001/orig/")
        Repository.objects.create(name="clone", url="http://localhost:8001/clone/")

        url = reverse("pushes.views.diff")
        # right now, we can't diff between repos, this might change!
        self.assertRaises(RepoError, self.client.get, url, {"repo": "clone", "from": rev_from[:12], "to": rev_to[:12]})
Example #23
0
 def setUp(self):
     self.repo_path = mkdtemp()
     self.ui = ui.ui()
     self.ui.setconfig('ui', 'quiet', True)
     commands.init(self.ui, self.repo_path)
     self.file_name = 'foo.rst'
     self.file_path = os.path.join(self.repo_path, self.file_name)
     with codecs.open(self.file_path, 'w', encoding='utf-8') as fp:
         fp.write('test\n')
     self.repo = hg.repository(self.ui, self.repo_path)
     self.changectx = self.repo[None]
     commands.commit(self.ui, self.repo, message='foo',
                     user='******', addremove=True)
Example #24
0
    def test_handlePushes(self):
        repo = Repository.objects.create(
          name='mozilla-central',
          url='file:///' + self.repo
        )
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w')
             .write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo,
                  user="******",
                  message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        push_id = 100
        username = '******'
        pushjs0 = PushJS(push_id, {
          'date': timestamp,
          'changesets': [rev0],
          'user': username,
        })
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # expect all of these to have been created
        push, = Push.objects.all()
        branch, = Branch.objects.all()
        changeset, = push.changesets.all()

        self.assertEqual(push.repository, repo)
        self.assertEqual(push.push_id, push_id)
        self.assertEqual(push.user, username)
        self.assertEqual(push.push_date.strftime('%Y%m%d%H%M'),
                         datetime.datetime.utcnow().strftime('%Y%m%d%H%M'))

        self.assertEqual(changeset.description, 'initial commit')
        self.assertEqual(changeset.user, 'Jane Doe <*****@*****.**>')
        self.assertEqual(changeset.revision, rev0)
        self.assertEqual(changeset.branch, branch)

        self.assertEqual(branch.name, 'default')
Example #25
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_twice(self):
        repo = Repository.objects.create(name="mozilla-central", url="file://" + self.repo)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0], "user": "******"})
        result = handlePushes(repo.pk, [pushjs0])

        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             """
            )
        )
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        # a second time
        timestamp = int(time.time())
        pushjs0 = PushJS(101, {"date": timestamp, "changesets": [rev1], "user": "******"})

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 2)

        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # re-fetch
        repo = Repository.objects.get(pk=repo.pk)
        self.assertEqual(repo.changesets.all().count(), 3)
Example #26
0
    def create(self, name):
        # Check if it's an absolute path
        if os.path.exists(os.path.dirname(name)):
            path = os.path.dirname(name)
            newname = os.path.basename(name)
        else:
            path = self.default_root
            newname = name

        repo = os.path.join(path, newname)
        if newname not in self.available_repos:
            hgui = ui.ui()
            os.makedirs(repo)
            commands.init(hgui, repo)
            self.available_repos[newname] = repo
Example #27
0
def _clone_or_pull(ui, repo, name, source, pull_opts):
    cache_path = os.path.join(repo.path, 'subtree-cache')
    if not os.path.exists(cache_path):
        os.makedirs(cache_path)

    subrepo_cache = os.path.join(cache_path, name)
    if not os.path.exists(subrepo_cache):
        os.makedirs(subrepo_cache)
        ui.status("initializing clean cache repo for %s in %s\n" %
                  (name, subrepo_cache))
        commands.init(ui, subrepo_cache)
    cache_repo = hg.repository(ui, path=subrepo_cache)
    commands.pull(ui, cache_repo, source=source, **pull_opts)

    return subrepo_cache
Example #28
0
    def __init__(self, path, init=False):

        GeneralVCSInterface.__init__(self, path, init)

        if init:
            commands.init(ui.ui(), self.path)
            open(opath.join(self.path, ".hgignore"),
                 "w").write("syntax: re\n\n")

        self.repo = hg.repository(ui.ui(), self.path)
        self.ui = self.repo.ui

        if init:
            self.addPath(opath.join(self.repo.root, ".hgignore"))
            self.addStandardIgnores()
Example #29
0
    def test_handlePushes(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///' + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        push_id = 100
        username = '******'
        pushjs0 = PushJS(push_id, {
            'date': timestamp,
            'changesets': [rev0],
            'user': username,
        })
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # expect all of these to have been created
        push, = Push.objects.all()
        branch, = Branch.objects.all()
        changeset, = push.changesets.all()

        self.assertEqual(push.repository, repo)
        self.assertEqual(push.push_id, push_id)
        self.assertEqual(push.user, username)
        self.assertEqual(push.push_date.strftime('%Y%m%d%H%M'),
                         datetime.datetime.utcnow().strftime('%Y%m%d%H%M'))

        self.assertEqual(changeset.description, 'initial commit')
        self.assertEqual(changeset.user, 'Jane Doe <*****@*****.**>')
        self.assertEqual(changeset.revision, rev0)
        self.assertEqual(changeset.branch, branch)

        self.assertEqual(branch.name, 'default')
Example #30
0
    def __init__(self,
                 path,
                 init=False):

        GeneralVCSInterface.__init__(self,path,init)

        if init:
            commands.init(ui.ui(),self.path)
            open(opath.join(self.path,".hgignore"),"w").write("syntax: re\n\n")

        self.repo=hg.repository(ui.ui(),self.path)
        self.ui=self.repo.ui

        if init:
            self.addPath(opath.join(self.repo.root,".hgignore"))
            self.addStandardIgnores()
Example #31
0
    def setUp(self):
        self.repo_path = mkdtemp()
        self.ui = ui.ui()
        self.ui.setconfig('ui', 'quiet', True)
        self.ui.setconfig('ui', 'username', 'foo')
        commands.init(self.ui, self.repo_path)

        # create files
        self.repo_files = ['a%i.rst' % i for i in range(5)]
        for i in self.repo_files:
            with codecs.open(os.path.join(self.repo_path, i), 'w',
                             encoding='utf-8') as fp:
                fp.write('dumb file %s\n' % i)

        self.repo = hg.repository(self.ui, self.repo_path)
        commands.commit(self.ui, self.repo, message='foo', user='******',
                        addremove=True)
Example #32
0
 def setUp(self):
     self.repo_path = mkdtemp()
     self.repo_pathb = u2hg(self.repo_path)
     self.ui = ui.ui()
     self.ui.setconfig(b'ui', b'quiet', True)
     commands.init(self.ui, self.repo_pathb)
     self.file_name = 'foo.rst'
     self.file_path = os.path.join(self.repo_path, self.file_name)
     with codecs.open(self.file_path, 'w', encoding='utf-8') as fp:
         fp.write('test\n')
     self.repo = hg.repository(self.ui, self.repo_pathb)
     self.changectx = self.repo[None]
     commands.commit(self.ui,
                     self.repo,
                     message=b'foo',
                     user=b'foo <*****@*****.**>',
                     addremove=True)
Example #33
0
    def create_repo(repo_path):
        """Function to initialize a blohg repo, with the default template files
        inside.
        """

        template_path = resource_filename('blohg', 'repo_template')
        template_rootfiles = resource_listdir('blohg', 'repo_template')

        initialized = False
        for f in template_rootfiles + ['.hg']:
            if os.path.exists(os.path.join(repo_path, f)):
                initialized = True

        if initialized:
            raise RuntimeError('repository already initialized: %s' % \
                               repo_path)

        if not os.path.exists(repo_path):
            os.makedirs(repo_path)

        for f in template_rootfiles:
            full_path = os.path.join(template_path, f)
            if os.path.isdir(full_path):
                shutil.copytree(full_path, os.path.join(repo_path, f))
            elif os.path.isfile(full_path):
                shutil.copy2(full_path, os.path.join(repo_path, f))
            else:
                raise RuntimeError('unrecognized file: %s' % full_path)

        # create a .hgignore, to avoid people to acidentally push a build/ dir
        # with stuff built with 'blohg freeze'. creating the file here because
        # a .hgignore file in the repo may cause some weird behavior that we
        # are not aware of.
        with codecs.open(os.path.join(repo_path, '.hgignore'), 'w',
                         encoding='utf-8') as fp:
            fp.write('^build/' + os.linesep)

        ui = _ui.ui()
        ui.setconfig('ui', 'quiet', True)
        try:
            commands.init(ui, repo_path)
        except error, err:
            raise RuntimeError('an error was occurred: %s' % err)
Example #34
0
File: tests.py Project: gerv/elmo
    def test_handlePushes(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        push_id = 100
        username = "******"
        pushjs0 = PushJS(push_id, {"date": timestamp, "changesets": [rev0], "user": username})
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)

        # expect all of these to have been created
        push, = Push.objects.all()
        branch, = Branch.objects.all()
        changeset, = push.changesets.all()

        self.assertEqual(push.repository, repo)
        self.assertEqual(push.push_id, push_id)
        self.assertEqual(push.user, username)
        self.assertEqual(push.push_date.strftime("%Y%m%d%H%M"), datetime.datetime.utcnow().strftime("%Y%m%d%H%M"))

        self.assertEqual(changeset.description, "initial commit")
        self.assertEqual(changeset.user, "Jane Doe <*****@*****.**>")
        self.assertEqual(changeset.revision, rev0)
        self.assertEqual(changeset.branch, branch)

        self.assertEqual(branch.name, "default")
Example #35
0
File: repo.py Project: MrPetru/spam
def repo_init(proj):
    """Init a new mercurial repository for ``proj``."""
    repo_path = os.path.join(G.REPOSITORY, proj)
    try:
        repo = repo_get(proj)
    except SPAMRepoNotFound:
        commands.init(repo_ui, repo_path)
        repo = repo_get(proj)
    
    hgignore_path = os.path.join(G.REPOSITORY, proj, '.hgignore')
    if not os.path.exists(hgignore_path):
        hgignore = open(hgignore_path, 'w')
        hgignore.write('syntax: regexp\n')
        hgignore.write('^.previews/')
        hgignore.close()
    
    if not '.hgignore' in repo['tip']:
        commands.add(repo_ui, repo, hgignore_path)
        matched = match.exact(repo.root, repo.getcwd(), ['.hgignore'])
        commit_id = repo.commit('add .hgignore', user='******', match=matched)
Example #36
0
File: tests.py Project: gerv/elmo
    def test_file_entity_addition(self):
        """Change one file by adding a new line to it"""
        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             <!ENTITY key3 "World">
             """
            )
        )
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_(re.findall(">\s*file\.dtd\s*<", html_diff))
        ok_('<tr class="line-added">' in html_diff)
        ok_(re.findall(">\s*key3\s*<", html_diff))
        ok_(re.findall(">\s*World\s*<", html_diff))
        ok_(not re.findall(">\s*Cruel\s*<", html_diff))
Example #37
0
File: tests.py Project: gerv/elmo
    def test_file_renamed_and_edited_original_broken(self):
        """Change by doing a rename on a previously broken file"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)

        hgrepo = repository(ui, self.repo)
        (
            codecs.open(hgrepo.pathto("file.dtd"), "w", "latin1").write(
                u"""
             <!ENTITY key1 "Hell\xe3">
             <!ENTITY key2 "Cruel">
             """
            )
        )
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        hgcommands.rename(ui, hgrepo, hgrepo.pathto("file.dtd"), hgrepo.pathto("newnamefile.dtd"))
        (
            open(hgrepo.pathto("newnamefile.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "World">
             """
            )
        )
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1].split("page_footer")[0]
        html_diff = unicode(html_diff, "utf-8")
        ok_(re.findall(">\s*newnamefile\.dtd\s*<", html_diff))
        ok_("Cannot parse file" in html_diff)
        eq_(html_diff.count("Cannot parse file"), 1)
        ok_("renamed from file.dtd" in re.sub("<.*?>", "", html_diff))
Example #38
0
    def setUp(self):
        self.repo_path = mkdtemp()
        self.ui = ui.ui()
        self.ui.setconfig('ui', 'quiet', True)
        self.ui.setconfig('ui', 'username', 'foo')
        commands.init(self.ui, self.repo_path)

        # create files
        self.repo_files = ['a%i.rst' % i for i in range(5)]
        for i in self.repo_files:
            with codecs.open(os.path.join(self.repo_path, i),
                             'w',
                             encoding='utf-8') as fp:
                fp.write('dumb file %s\n' % i)

        self.repo = hg.repository(self.ui, self.repo_path)
        commands.commit(self.ui,
                        self.repo,
                        message='foo',
                        user='******',
                        addremove=True)
Example #39
0
	def openRepo(self):
		# Create a new repository or continue from aborted dump
		self.ui=ui.ui()
		self.last_names = {} # Tracks page renames: name atm -> last name in repo
		self.last_parents = {} # Tracks page parent names: name atm -> last parent in repo
		
		if os.path.isfile(self.path+'\\.wstate'):
			print "Continuing from aborted dump state..."
			self.loadState()
			self.repo = hg.repository(self.ui, self.path)
		
		else: # create a new repository (will fail if one exists)
			print "Initializing repository..."
			commands.init(self.ui, self.path)
			self.repo = hg.repository(self.ui, self.path)
			self.rev_no = 0
			
			if self.storeRevIds:
				# Add revision id file to the new repo
				fname = self.path+'\\.revid'
				codecs.open(fname, "w", "UTF-8").close()
				commands.add(self.ui, self.repo, str(fname))
Example #40
0
def create_repository(location):
    """
    Creates a new mercurial repository at the specified location
    if it doesn't exist already.

    Can throw IOErrors or OSErrors if there are any problems creating
    the repository on disk.
    """
    if re.match("[\w\d]+://", location):
        raise ValueError(_("Remote repository locations are not supported"))

    #if not os.path.isabs(location):
    #    if not settings.REPO_ROOT:
    #        raise ImproperlyConfigured(_("REPO_ROOT must be defined in your settings file if using a relative path."))
    #    location = os.path.join(settings.REPO_ROOT, location)

    if not os.path.isdir(os.path.join(location, ".hg")):
        if not os.path.exists(location):
            os.mkdir(location)

        u = setup_ui()
        commands.init(u, location)
Example #41
0
    def test_handlePushes_repeated(self):
        repo = Repository.objects.create(name='mozilla-central',
                                         url='file:///' + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto('file.dtd'), 'w').write('''
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             '''))

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui,
                          hgrepo,
                          user="******",
                          message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {
            'date': timestamp,
            'changesets': [rev0],
            'user': '******',
        })
        # first time
        pushes_initial = Push.objects.all().count()
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after = Push.objects.all().count()
        self.assertEqual(pushes_initial, pushes_after - 1)

        # a second time should be harmless
        result = handlePushes(repo.pk, [pushjs0])
        self.assertEqual(result, 1)
        pushes_after_after = Push.objects.all().count()
        self.assertEqual(pushes_after, pushes_after_after)
Example #42
0
File: tests.py Project: gerv/elmo
    def test_binary_file_edited(self):
        """Modify a binary file"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.png"), "wb").write(
                base64.b64decode(
                    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklE" "QVR4nGNoAAAAggCBd81ytgAAAABJRU5ErkJggg=="
                )
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()
        # a bit unfair of a change but works for the tests
        (
            open(hgrepo.pathto("file.png"), "wb").write(
                base64.b64decode(
                    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQAAAAA3bvkkAAAACklE" "QVR4nGNgAAAAAgABSK+kcQAAAABJRU5ErkJggg=="
                )
            )
        )

        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        repo_url = "http://localhost:8001/" + self.repo_name + "/"
        Repository.objects.create(name=self.repo_name, url=repo_url)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("Cannot parse file" in html_diff)
        # also, expect a link to this file
        change_ref = 'href="%sfile/%s/file.png"' % (repo_url, rev1)
        ok_(change_ref in html_diff)
Example #43
0
def create_repository(location):
    """
    Creates a new mercurial repository at the specified location
    if it doesn't exist already.

    Can throw IOErrors or OSErrors if there are any problems creating
    the repository on disk.
    """
    if re.match("[\w\d]+://", location):
        raise ValueError(_("Remote repository locations are not supported"))

    #if not os.path.isabs(location):
    #    if not settings.REPO_ROOT:
    #        raise ImproperlyConfigured(_("REPO_ROOT must be defined in your settings file if using a relative path."))
    #    location = os.path.join(settings.REPO_ROOT, location)

    if not os.path.isdir(os.path.join(location, ".hg")):
        if not os.path.exists(location):
            os.mkdir(location)

        u = setup_ui()
        commands.init(u, location)
Example #44
0
File: tests.py Project: gerv/elmo
    def test_file_only_renamed_no_parser(self):
        """Change by doing a rename of a file without parser"""
        ui = mock_ui()
        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (open(hgrepo.pathto("file.txt"), "w").write("line 1\nline 2\n"))
        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        hgcommands.rename(ui, hgrepo, hgrepo.pathto("file.txt"), hgrepo.pathto("newnamefile.txt"))
        hgcommands.commit(ui, hgrepo, user="******", message="Second commit")
        rev1 = hgrepo[1].hex()

        Repository.objects.create(name=self.repo_name, url="http://localhost:8001/%s/" % self.repo_name)

        url = reverse("pushes.views.diff")
        response = self.client.get(url, {"repo": self.repo_name, "from": rev0, "to": rev1})
        eq_(response.status_code, 200)
        html_diff = response.content.split("Changed files:")[1]
        ok_("renamed from file.txt" in re.sub("<.*?>", "", html_diff))
        ok_(re.findall(">\s*newnamefile\.txt\s*<", html_diff))
        ok_(not re.findall(">\s*line 1\s*<", html_diff))
Example #45
0
 def __init__(self, path, vcs_type):
     self.ui = hgui.ui()
     self.path = path
     self.vcs_type = vcs_type
     if self.vcs_type == 'git':
         if not os.path.exists(self.path):
             os.makedirs(self.path)
         try:
             self.r = gitrepo.Repo(self.path)
         except:
             self.r = gitrepo.Repo.init(self.path)
     elif self.vcs_type == 'hg':
         if not os.path.exists(self.path):
             os.makedirs(self.path)
         try:
             self.r = hgrepo.localrepository(
                 self.ui,
                 self.path)
         except:
             hg.init(self.ui, self.path)
             self.r = hgrepo.localrepository(
                 self.ui,
                 self.path)
Example #46
0
    def create_repo(self, dest, ui):
        vct = 'http://hg.mozilla.org/hgcustom/version-control-tools'
        commands.clone(ui, vct, dest=os.path.join(dest, 'vct.hg'))

        ui.setconfig('extensions', 'pushlog',
                     os.path.join(dest, 'vct.hg/hgext/pushlog'))

        srcdir = os.path.join(dest, 'test')
        destdir = os.path.join(dest, 'testwork')

        if not os.path.exists(srcdir):
            os.makedirs(srcdir)

        commands.init(ui, srcdir)
        commands.init(ui, destdir)

        repo = hg.repository(ui, destdir)

        myfile1 = os.path.join(destdir, 'myfile1')
        myfile2 = os.path.join(destdir, 'myfile2')
        for i in range(5):
            with open(myfile1, 'a') as In:
                In.write(str(i))
            with open(myfile2, 'a') as In:
                In.write(str(i))
            commands.commit(ui,
                            repo,
                            myfile1,
                            myfile2,
                            message='message' + str(i),
                            user='******',
                            addremove=True)
            commands.push(ui, repo, dest=srcdir)
            time.sleep(1.01)

        return srcdir
Example #47
0
    def openRepo(self):
        # Create a new repository or continue from aborted dump
        self.ui = ui.ui()
        self.last_names = {
        }  # Tracks page renames: name atm -> last name in repo
        self.last_parents = {
        }  # Tracks page parent names: name atm -> last parent in repo

        if os.path.isfile(self.path + '\\.wstate'):
            print "Continuing from aborted dump state..."
            self.loadState()
            self.repo = hg.repository(self.ui, self.path)

        else:  # create a new repository (will fail if one exists)
            print "Initializing repository..."
            commands.init(self.ui, self.path)
            self.repo = hg.repository(self.ui, self.path)
            self.rev_no = 0

            if self.storeRevIds:
                # Add revision id file to the new repo
                fname = self.path + '\\.revid'
                codecs.open(fname, "w", "UTF-8").close()
                commands.add(self.ui, self.repo, str(fname))
Example #48
0
File: tests.py Project: gerv/elmo
    def test_handlePushes_messedup_revisions(self):
        repo = Repository.objects.create(name="mozilla-central", url="file:///" + self.repo)
        self.assertEqual(handlePushes(repo.pk, []), None)

        ui = mock_ui()

        hgcommands.init(ui, self.repo)
        hgrepo = repository(ui, self.repo)
        (
            open(hgrepo.pathto("file.dtd"), "w").write(
                """
             <!ENTITY key1 "Hello">
             <!ENTITY key2 "Cruel">
             """
            )
        )

        hgcommands.addremove(ui, hgrepo)
        hgcommands.commit(ui, hgrepo, user="******", message="initial commit")
        rev0 = hgrepo[0].hex()

        timestamp = int(time.time())
        pushjs0 = PushJS(100, {"date": timestamp, "changesets": [rev0[::-1]], "user": "******"})
        self.assertRaises(RepoLookupError, handlePushes, repo.pk, [pushjs0])
Example #49
0
 def create(self, path):
     "Create an empty repository"
     commands.init(self.ui, path)
def hg_repo(hg_ui, repo_dir):
    """Get test mercurial repo."""
    commands.init(hg_ui, repo_dir)
    return hg.repository(hg_ui, repo_dir)
Example #51
0
def setup_sandbox():
    os.mkdir(sandbox_path)
    os.chdir(sandbox_path)
    
    commands.init(_ui)
Example #52
0
 def init(path):
     "Initialize a mercurial repository."
     commands.init(ui.ui(), path)