Exemple #1
0
    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))
Exemple #2
0
def qrefresh_wrapper(orig, self, repo, *pats, **opts):
    mqmessage = opts.pop('mqmessage', '') or '%a: %p\n%s%Q'
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    diffstat = ""
    if mqcommit and mqmessage:
        if mqmessage.find("%s") != -1:
            self.pushbuffer()
            m = cmdutil.matchmod.match(repo.root, repo.getcwd(), [],
                                       opts.get('include'), opts.get('exclude'),
                                       'relpath', auditor=repo.auditor)
            cmdutil.diffordiffstat(self, repo, mdiff.diffopts(),
                                   repo.dirstate.parents()[0], None, m,
                                   stat=True)
            diffstat = self.popbuffer()

    ret = orig(self, repo, *pats, **opts)
    if ret:
        return ret

    if mqcommit and len(q.applied) > 0:
        patch = q.applied[-1].name
        if r is None:
            raise util.Abort("no patch repository found when using -Q option")
        mqmessage = substitute_mqmessage(mqmessage, repo, { 'p': patch,
                                                            'a': 'UPDATE',
                                                            's': diffstat })
        commands.commit(r.ui, r, message=mqmessage)
Exemple #3
0
def qdelete_wrapper(self, repo, *patches, **opts):
    '''This function takes a list of patches, which makes the message
    substitution rather weird. %a and %p will be replaced with the
    action ('DELETE') and patch name, as usual, but one line per patch
    will be generated. In addition the %m (multi?) replacement string,
    if given, will be replaced with a prefix message "DELETE (n)
    patches: patch1 patch2..." that is NOT repeated per patch. It
    probably would have been cleaner to give two formats, one for the
    header and one for the per-patch lines.'''

    mqmessage = opts.pop('mqmessage', None)
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    if mqcommit and mqmessage:
        patchnames = [ q.lookup(p) for p in patches ]

    mq.delete(self, repo, *patches, **opts)

    if mqcommit and mqmessage:
        mqmessage = mqmessage.replace("%a", 'DELETE')
        if (len(patches) > 1) and (mqmessage.find("%m") != -1):
            rep_message = mqmessage.replace("%m", "")
            mqmessage = "DELETE %d patches: %s\n" % (len(patches), " ".join(patchnames))
            mqmessage += "\n".join([ rep_message.replace("%p", p) for p in patchnames ])
        else:
            mqmessage = mqmessage.replace("%m", "")
            mqmessage = "\n".join([ mqmessage.replace("%p", p) for p in patchnames ])
        commands.commit(r.ui, r, message=mqmessage)
Exemple #4
0
    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))
Exemple #5
0
def wkcommit(ui, repo, *pats, **opts):
    '''Another Mercurial Extension

    this extension using clang-format to format files with suffix like ``.cpp``,
    ``.c`` and ``.h`` before you commit them to the local repository.

    How to Use this Extension:(.hgrc)

    [extensions]

    wkcommit = /path/to/this/extension
    '''

    modified, added, removed, deleted, unknown, ignored, clean = repo.status()

    if len(pats) == 0:
        for file in (modified + added):
            clangFormat(ui, file)
    else:
        for file in pats:
            if file in (modified + added):
                clangFormat(ui, file)
    ui.flush()

    commands.commit(ui, repo, *pats, **opts)
    return 0
Exemple #6
0
def update_html(head, jar_chk, zip_chk):
    ui_ = ui.ui()
    repo = hg.repository(ui_, REPO_DIR)
    site_usk = PUBLIC_SITE % (latest_site_index(repo) + 1)

    html = simple_templating(open(INDEX_HTML_TEMPLATE).read(),
                             {'__HEAD__':head,
                              '__JAR_CHK__': jar_chk,
                              '__SRC_CHK__': zip_chk,
                              '__RELEASE_NOTES__' : html_escape(get_release_notes()),
                              '__SITE_USK__': site_usk,
                              '__INDEX_FDW__': FREENET_DOC_WIKI_IDX,
                              '__INDEX_FNIKI__': FNIKI_IDX,
                              '__INDEX_REPO__': REPO_IDX,
                              '__INDEX_DFC__': DFC_IDX,
                              })

    updated = open(INDEX_HTML, 'w')
    updated.write(html)
    updated.close()

    if JUST_CHECK_HTML:
        print "Just checking html. Didn't tag repo."
        return

    commit_msg = "index.html:%s" % head
    commands.commit(ui_, repo, pat = (INDEX_HTML, ),
                    include = [], addremove = None, close_branch = None,
                    user = '', date = '',
                    exclude = [], logfile = '',
                    message = commit_msg)
    tag_site_index(ui_, repo)
Exemple #7
0
    def test_filectx_needs_reload(self):

        # add a file to repo
        with codecs.open(os.path.join(self.repo.path, 'a.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        self.assertTrue(ctx.filectx_needs_reload(filectx))

        with codecs.open(os.path.join(self.repo.path, 'a.rst'), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # should always be true
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        commands.commit(self.ui, self.repo, message='foo', user='******',
                        addremove=True)

        # should need a reload now, after the commit
        self.assertTrue(ctx.filectx_needs_reload(filectx))

        # reload
        ctx = self.get_ctx()
        filectx = ctx.get_filectx('a.rst')

        # should still need a reload, right after the reload
        self.assertTrue(ctx.filectx_needs_reload(filectx))
Exemple #8
0
    def test_files(self):

        new_file = 'a.rst'

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, new_file), 'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # before commit files
        ctx = self.get_ctx()
        for f in self.repo_files:
            self.assertTrue(f in ctx.files, 'file not found in stable state: '
                            '%s' % f)
        self.assertFalse(new_file in ctx.files, 'stable state is '
                         'listing uncommited file.')

        commands.commit(self.ui, self.repo, message='foo', user='******',
                        addremove=True)

        # after commit files
        ctx = self.get_ctx()
        for f in self.repo_files + [new_file]:
            self.assertTrue(f in ctx.files, 'file not found in stable '
                            'state: %s' % f)
Exemple #9
0
def record(ui, repo, *pats, **opts):
    '''interactively select changes to commit

    If a list of files is omitted, all changes reported by :hg:`status`
    will be candidates for recording.

    See :hg:`help dates` for a list of formats valid for -d/--date.

    You will be prompted for whether to record changes to each
    modified file, and for files with multiple changes, for each
    change to use. For each query, the following responses are
    possible::

      y - record this change
      n - skip this change
      e - edit this change manually

      s - skip remaining changes to this file
      f - record remaining changes to this file

      d - done, skip remaining changes and files
      a - record all changes to all remaining files
      q - quit, recording no changes

      ? - display help

    This command is not available when committing a merge.'''

    opts["interactive"] = True
    backup = ui.backupconfig('experimental', 'crecord')
    try:
        ui.setconfig('experimental', 'crecord', False, 'record')
        commands.commit(ui, repo, *pats, **opts)
    finally:
        ui.restoreconfig(backup)
Exemple #10
0
    def hgflow_func_feature_finish(self, target_branch, name):
        '''finish this feature.
        1, Check develop branch version and current feature
        1, Close this branch
        2, Merge it into develop
        3, Commit develop branch
        '''

        if not self._findBranch(target_branch, name):
            return

        commands.update(self.ui, self.repo, target_branch)
        commands.commit(self.ui,
                        self.repo,
                        close_branch=True,
                        message='hg flow, close feature %s' % (name, ))

        commands.update(self.ui, self.repo, self.developBranch)
        commands.merge(self.ui, self.repo, target_branch)
        #commands.commit(self.ui, self.repo, message='hg flow, merge feature `%s` to develop branch `%s`' % (target_branch, self.developBranch))
        commands.commit(
            self.ui,
            self.repo,
            message='hg flow, merge release `%s` to develop branch `%s`' %
            (name, self.developBranch))
Exemple #11
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])
Exemple #12
0
    def commit(self):
        """Use the list of files given by the user to commit to the repository"""
        # The variable passing schema we use means that we'll have problems
        # with a repository named 'on'.  We should look into a fix for that.
        url = request.environ['routes.url']

        # We send out a form with two inputs per file, one hidden with the
        # repository, and one checkbox.  We get back two values for the file if
        # the checkbox is checked, and one otherwise.  It's not perfect, but it
        # works for now.
        message = request.params['message']
        if not message:
            redirect(url.current(action='index'))
        for repo, root in self.repositories:
            if root not in request.params:
                continue
            repochroot = Chroot(repo.root)
            try:
                files = (repochroot(path.join(repo.root, file)) for file in request.params.getall(root))
            except IOError:
                error = 'Bad Filename'
                redirect(url(controller='dv', action='index', error=error))
            self.ui.pushbuffer()
            commands.commit(self.ui, repo, message=message, logfile=None, *files)
            output = self.ui.popbuffer()
        redirect(url.current(action='index'))
Exemple #13
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 ')
Exemple #14
0
def record(ui, repo, *pats, **opts):
    '''interactively select changes to commit

    If a list of files is omitted, all changes reported by :hg:`status`
    will be candidates for recording.

    See :hg:`help dates` for a list of formats valid for -d/--date.

    You will be prompted for whether to record changes to each
    modified file, and for files with multiple changes, for each
    change to use. For each query, the following responses are
    possible::

      y - record this change
      n - skip this change
      e - edit this change manually

      s - skip remaining changes to this file
      f - record remaining changes to this file

      d - done, skip remaining changes and files
      a - record all changes to all remaining files
      q - quit, recording no changes

      ? - display help

    This command is not available when committing a merge.'''

    opts["interactive"] = True
    backup = ui.backupconfig('experimental', 'crecord')
    try:
        ui.setconfig('experimental', 'crecord', False, 'record')
        commands.commit(ui, repo, *pats, **opts)
    finally:
        ui.restoreconfig(backup)
Exemple #15
0
 def _commit(self, message):
     user = self.environ.get("http_authenticator.username") or "Anonymous"
     commands.commit(self.provider.ui, self.provider.repo, 
                     self.localHgPath, 
                     addremove=True,
                     user=user,
                     message=message)
Exemple #16
0
 def _createBranch(self, branch_name, message, from_branch = None):
     if not from_branch is None:
         #first update to from_branch
         commands.update(self.ui, self.repo, from_branch)
         
     commands.branch(self.ui, self.repo, branch_name)
     commands.commit(self.ui, self.repo, message = message)
Exemple #17
0
    def test_get_from_archive(self):
        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(1, 4):
            file_path = os.path.join(file_dir, 'archive-%i.rst' % i)
            with codecs.open(file_path, 'w', encoding='utf-8') as fp:
                fp.write(SAMPLE_POST + """
.. date: 2010-%02i-01 12:00:00""" % i)
        commands.commit(self.ui,
                        self.repo,
                        user='******',
                        message='foo',
                        addremove=True)
        model = self.get_model()
        now = datetime.utcnow()
        self.assertEqual(model.archives, [(now.year, now.month), (2010, 3),
                                          (2010, 2), (2010, 1)])
        jan_2010 = model.get_from_archive(2010, 1)
        self.assertEqual(jan_2010[0].slug, 'post/archive-1')
        feb_2010 = model.get_from_archive(2010, 2)
        self.assertEqual(feb_2010[0].slug, 'post/archive-2')
        mar_2010 = model.get_from_archive(2010, 3)
        self.assertEqual(mar_2010[0].slug, 'post/archive-3')
        apr_2010 = model.get_from_archive(2010, 4)
        self.assertEqual(len(apr_2010), 0)
Exemple #18
0
    def test_files(self):

        new_file = 'a.rst'

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, new_file),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # before commit files
        ctx = self.get_ctx()
        for f in self.repo_files:
            self.assertTrue(f in ctx.files, 'file not found in stable state: '
                            '%s' % f)
        self.assertFalse(new_file in ctx.files, 'stable state is '
                         'listing uncommited file.')

        commands.commit(self.ui,
                        self.repo,
                        message=b'foo',
                        user=b'foo',
                        addremove=True)

        # after commit files
        ctx = self.get_ctx()
        for f in self.repo_files + [new_file]:
            self.assertTrue(f in ctx.files, 'file not found in stable '
                            'state: %s' % f)
Exemple #19
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])
Exemple #20
0
    def test_needs_reload(self):
        ctx = self.get_ctx()
        self.assertTrue(ctx.needs_reload())

        # add a file to repo
        with codecs.open(os.path.join(hg2u(self.repo.path), 'a.rst'),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # should always be true
        self.assertTrue(ctx.needs_reload())

        commands.commit(self.ui,
                        self.repo,
                        message=b'foo',
                        user=b'foo',
                        addremove=True)

        # should need a reload now, after the commit
        self.assertTrue(ctx.needs_reload())

        # reload
        ctx = self.get_ctx()

        # should still need a reload, right after the reload
        self.assertTrue(ctx.needs_reload())
Exemple #21
0
def qrefresh_wrapper(orig, self, repo, *pats, **opts):
    mqmessage = opts.pop('mqmessage', '') or '%a: %p\n%s%Q'
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    diffstat = ""
    if mqcommit and mqmessage:
        if mqmessage.find("%s") != -1:
            self.pushbuffer()
            m = cmdutil.matchmod.match(repo.root, repo.getcwd(), [],
                                       opts.get('include'), opts.get('exclude'),
                                       'relpath', auditor=repo.auditor)
            diffordiffstat(self, repo, mdiff.diffopts(),
                                   repo.dirstate.parents()[0], None, m,
                                   stat=True)
            diffstat = self.popbuffer()

    ret = orig(self, repo, *pats, **opts)
    if ret:
        return ret

    if mqcommit and len(q.applied) > 0:
        patch = q.applied[-1].name
        if r is None:
            raise error.Abort("no patch repository found when using -Q option")
        mqmessage = substitute_mqmessage(mqmessage, repo, { 'p': patch,
                                                            'a': 'UPDATE',
                                                            's': diffstat })
        commands.commit(r.ui, r, message=mqmessage)
Exemple #22
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='******')
Exemple #23
0
 def test_up2date_changectx_working_dir(self):
     app = create_app(repo_path=self.repo_path,
                      revision_id=REVISION_WORKING_DIR)
     with app.test_request_context():
         app.preprocess_request()
         self.assertRaises(TemplateNotFound, app.jinja_loader.get_source,
                           app.jinja_env, 'test.html')
     new_file = os.path.join(self.repo_path, app.template_folder,
                             'test.html')
     with codecs.open(new_file, 'w', encoding='utf-8') as fp:
         fp.write('foo')
     with app.test_request_context():
         app.preprocess_request()
         contents, filename, up2date = app.jinja_loader.get_source(
             app.jinja_env, 'test.html')
         self.assertEqual('foo', contents)
         self.assertEqual(filename,
                          os.path.join(app.template_folder, 'test.html'))
         app.preprocess_request()
         self.assertFalse(up2date())
         commands.commit(self.ui,
                         self.repo,
                         message='foo',
                         user='******',
                         addremove=True)
         contents, filename, up2date = app.jinja_loader.get_source(
             app.jinja_env, 'test.html')
         self.assertEqual('foo', contents)
         app.preprocess_request()
         self.assertFalse(up2date())
Exemple #24
0
 def _createBranch(self, branch_name, message, from_branch = None):
     if not from_branch is None:
         #first update to from_branch
         commands.update(self.ui, self.repo, from_branch)
         
     commands.branch(self.ui, self.repo, branch_name)
     commands.commit(self.ui, self.repo, message = message)
Exemple #25
0
 def _commit(self, message):
     user = self.environ.get("http_authenticator.username") or "Anonymous"
     commands.commit(self.provider.ui, self.provider.repo, 
                     self.localHgPath, 
                     addremove=True,
                     user=user,
                     message=message)
Exemple #26
0
def qrefresh_wrapper(self, repo, *pats, **opts):
    mqmessage = opts.pop('mqmessage', None)
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    diffstat = ""
    if mqcommit and mqmessage:
        if mqmessage.find("%s") != -1:
            buffer = StringIO.StringIO()
            m = cmdutil.match(repo, None, {})
            diffopts = mdiff.diffopts()
            cmdutil.diffordiffstat(self, repo, diffopts,
                                   repo.dirstate.parents()[0], None, m,
                                   stat=True, fp = buffer)
            diffstat = buffer.getvalue()
            buffer.close()

    mq.refresh(self, repo, *pats, **opts)

    if mqcommit and len(q.applied) > 0:
        patch = q.applied[-1].name
        if r is None:
            raise util.Abort("no patch repository found when using -Q option")
        mqmessage = mqmessage.replace("%p", patch)
        mqmessage = mqmessage.replace("%a", 'UPDATE')
        mqmessage = mqmessage.replace("%s", diffstat)
        commands.commit(r.ui, r, message=mqmessage)
Exemple #27
0
    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))
Exemple #28
0
        def _feature_func(action, name, target_branch):
            if 'start' == action:
                self._startBranch(target_branch, 'feature')

            elif 'finish' == action:
                '''finish this feature.
                1, Check develop branch version and current feature
                1, Close this branch
                2, Merge it into develop
                3, Commit develop branch
                '''

                if not self._findBranch(target_branch, name):
                    return

                commands.update(self.ui, self.repo, target_branch)
                commands.commit(self.ui, self.repo, close_branch=True, message='hg flow, close feature %s' % (name,))

                commands.update(self.ui, self.repo, self.developBranch)
                commands.merge(self.ui, self.repo, target_branch)
                #commands.commit(self.ui, self.repo, message='hg flow, merge feature `%s` to develop branch `%s`' % (target_branch, self.developBranch))
                commands.commit(self.ui, self.repo, message='hg flow, merge release `%s` to develop branch `%s`' % (name, self.developBranch))
                #self.outputln(_('WARNING: No automatic commit after merge from feature `%s`, you should resolve the confict (if any) then commit manually.' % (name,)))

            elif 'change' == action:
                commands.update(self.ui, self.repo, target_branch)
                """
            elif 'fetchdev' == action:
                pass
            """
            else:
                self.outputln(_('Please give a valid action.'))
Exemple #29
0
def hg_commit(filename='text.txt'):
    with open(os.path.join(sandbox_path, filename), 'a') as test_file:
        test_file.writelines(['test', '.'])
    
    opts = { 'addremove': True, 'date': None, 'user': '******',
             'logfile': None, 'message': "Sandbox commit." }
    commands.commit(get_sandbox_ui(), get_sandbox_repo(), **opts)
Exemple #30
0
 def test_up2date_changectx_working_dir(self):
     app = create_app(repo_path=self.repo_path,
                      revision_id=REVISION_WORKING_DIR)
     with app.test_request_context():
         app.preprocess_request()
         self.assertRaises(TemplateNotFound, app.jinja_loader.get_source,
                           app.jinja_env, 'test.html')
     new_file = os.path.join(self.repo_path,
                             app.template_folder, 'test.html')
     with codecs.open(new_file, 'w', encoding='utf-8') as fp:
         fp.write('foo')
     with app.test_request_context():
         app.preprocess_request()
         contents, filename, up2date = app.jinja_loader.get_source(
             app.jinja_env, 'test.html')
         self.assertEqual('foo', contents)
         self.assertEqual(filename,
                           os.path.join(app.template_folder,
                                        'test.html'))
         app.preprocess_request()
         self.assertFalse(up2date())
         commands.commit(self.ui, self.repo, message='foo', user='******',
                         addremove=True)
         contents, filename, up2date = app.jinja_loader.get_source(
             app.jinja_env, 'test.html')
         self.assertEqual('foo', contents)
         app.preprocess_request()
         self.assertFalse(up2date())
Exemple #31
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)
Exemple #32
0
    def test_needs_reload(self):
        ctx = self.get_ctx()
        self.assertFalse(ctx.needs_reload())

        # add a file to repo
        with codecs.open(os.path.join(self.repo_path, 'a.rst'),
                         'w',
                         encoding='utf-8') as fp:
            fp.write('testing\n')

        # should still be false
        self.assertFalse(ctx.needs_reload())

        commands.commit(self.ui,
                        self.repo,
                        message=b'foo',
                        user=b'foo',
                        addremove=True)

        # should need a reload now, after the commit
        self.assertTrue(ctx.needs_reload())

        # reload
        ctx = self.get_ctx()

        # shouldn't need a reload again
        self.assertFalse(ctx.needs_reload())
Exemple #33
0
    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)
Exemple #34
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").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 ")
Exemple #35
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='******')
Exemple #36
0
    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)
Exemple #37
0
    def commit(self, path=None, message=None, user=None):
        from mercurial import commands, hg, ui, error
        log.debug("Commit to Mercurial repository.")

        path = path or self.path
        message = message or self.message
        user = user or self.user

        strings = [user.first_name, '<%s>' % user.email]
        author = ' '.join(filter(None, strings)) #  Only if not empty

        # For some reason default push path is not set properly
        import configparser, codecs
        config = configparser.ConfigParser()

        with codecs.open(os.path.join(path, '.hg/hgrc'), 'r', 'utf-8') as f:
            try:
                config.read_file(f)
            except Exception as e:
                raise CommitToRepositoryException(str(e))

        default_path = config.get('paths', 'default')

        try:
            u = ui.ui()
            u.setconfig('paths', 'default', default_path)
            repo = hg.repository(u, path)
            commands.commit(u, repo, message=message, user=author)
            commands.push(u, repo)
            log.info(message)

        except Exception as e:
            raise CommitToRepositoryException(str(e))
Exemple #38
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 ')
Exemple #39
0
 def commit(self, paths=(), message=None, user=None):
     commands.commit(self.ui,
                     self.repo,
                     user=user,
                     message=message,
                     logfile=None,
                     date=None,
                     *self.joined(paths))
 def commit_deletions(self, repo, file_names, msg='no comment'):
     for fname in file_names:
         commands.remove(self.ui_, repo,
                         os.path.join(repo.root, fname))
     commands.commit(self.ui_, repo,
                     logfile=None, addremove=None, user=None,
                     date=None,
                     message=msg)
Exemple #41
0
 def commit_change(ui,
                   repo,
                   action,
                   force_name=None,
                   node=None,
                   revisions=None,
                   **opts):
     commands.commit(ui, repo, **opts)
Exemple #42
0
def qfinish_wrapper(self, repo, *revrange, **opts):
    mqmessage = opts.pop('mqmessage', None)
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    mq.finish(self, repo, *revrange, **opts)

    if mqcommit and mqmessage:
        commands.commit(r.ui, r, message=mqmessage)
Exemple #43
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)
Exemple #44
0
 def store_results(self, results):
     base_fn = "results_%s.cpkl" % self.name
     fn = self.repo.pathto(base_fn)
     cPickle.dump(results, open(fn, "w"))
     if base_fn not in self.repo['tip'].manifest():
         commands.add(self.ui, self.repo, fn)
     message = "Committing results from current run"
     commands.commit(self.ui, self.repo, fn, message=message)
     print "Committed"
 def create_test_changesets(self, repo, count=1, dates=[]):
     for i in range(count):
         filename = repo_test_utils._create_random_file(self.directory)
         commands.add(repo.get_ui(), repo.get_repo(), filename)
         
         date=None
         if i < len(dates):
             date=dates[i]
         commands.commit(repo.get_ui(), repo.get_repo(), date=date, message="creating test commit", user='******')
Exemple #46
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)
Exemple #47
0
 def force_commit(self, msg='F', notify=True): # F -> Failed
     """ Force a commit to the repository after failure. """
     self.logger.trace("force_commit -- Commit local changes " +
                        "after failure.")
     commands.commit(self.ui_, self.repo,
                     logfile=None, addremove=None, user=None,
                     date=None,
                     message=msg)
     if notify:
         self.notify_committed(False)
Exemple #48
0
 def _commit(self, message):
     user = self.environ.get("wsgidav.auth.user_name") or "Anonymous"
     commands.commit(
         self.provider.ui,
         self.provider.repo,
         self.localHgPath,
         addremove=True,
         user=user,
         message=message,
     )
Exemple #49
0
 def setUp(self):
     self.repo_path = mkdtemp()
     self.ui = ui.ui()
     self.ui.setconfig('ui', 'quiet', True)
     HgRepository.create_repo(self.repo_path)
     self.repo = hg.repository(self.ui, self.repo_path)
     commands.commit(self.ui, self.repo, message='foo', user='******',
                     addremove=True)
     self.app = create_app(repo_path=self.repo_path,
                           revision_id=REVISION_DEFAULT)
Exemple #50
0
def qfinish_wrapper(orig, self, repo, *revrange, **opts):
    mqmessage = opts.pop('mqmessage', None)
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    ret = orig(self, repo, *revrange, **opts)
    if ret:
        return ret

    if mqcommit and mqmessage:
        mqmessage = substitute_mqmessage(mqmessage, repo, { })
        commands.commit(r.ui, r, message=mqmessage)
Exemple #51
0
def run_try(ui, repo, *args, **opts):
    """Push the current head to try
    """
    if not opts['build'] or not opts['platform']:
        raise util.Abort('Both -b and -p are required')

    # We rely on the try server to validate anything beyond that simple
    # check above, so let's just blindly go about our business!

    tryopts = []
    tryopts.append('-b')
    tryopts.extend(opts['build'])
    tryopts.append('-p')
    tryopts.extend(opts['platform'])
    if opts.get('unit'):
        tryopts.append('-u')
        tryopts.extend(opts['unit'])
    if opts.get('talos'):
        tryopts.append('-t')
        tryopts.extend(opts['talos'])

    trymsg = 'try: %s' % (' '.join(tryopts),)

    if repo[None].dirty():
        raise util.Abort('You have outstanding changes')

    try:
        strip = extensions.find('strip')
    except KeyError:
        ui.warn('strip extension not found, use the following syntax:\n')
        ui.write('%s\n' % (trymsg,))
        return

    ui.write('setting try selections...\n')

    # This next bit here is a hack to get an empty commit
    cwd = os.getcwd()
    junkfile = tempfile.mktemp(prefix='hgjunk', dir='')
    os.chdir(repo.root)
    file(junkfile, 'w').close()
    commands.add(ui, repo, junkfile)
    commands.commit(ui, repo, message='add junk file (will be gone)')
    commands.remove(ui, repo, junkfile)
    commands.commit(ui, repo, amend=True, message=trymsg, logfile=None)
    os.chdir(cwd)

    # Get the revision of our try commit so we can strip it later
    node = repo[None].p1().hex()

    ui.write('pushing to try...\n')
    commands.push(ui, repo, 'try', force=True)

    # Now we must clean up after ourslves by stripping the try commit
    strip.stripcmd(ui, repo, node, rev=[], no_backup=True)
Exemple #52
0
 def test_get_changectx_rev_default(self):
     hg_repo = HgRepository(self.repo_path)
     with codecs.open(os.path.join(self.repo_path, 'foo.rst'), 'w',
                      encoding='utf-8') as fp:
         fp.write('foo')
     commands.commit(self.ui, self.repo, message=b'foo', user=b'foo',
                     addremove=True)
     self.assertTrue(isinstance(hg_repo.get_changectx(REVISION_DEFAULT),
                                ChangeCtxDefault),
                     'changectx object is not an instance of '
                     'ChangeCtxDefault')
Exemple #53
0
def qcrecord_wrapper(orig, self, repo, patchfn, *pats, **opts):
    mqmessage = opts.pop('mqmessage', None)
    mqcommit, q, r = mqcommit_info(self, repo, opts)

    ret = orig(self, repo, patchfn, *pats, **opts)
    if ret:
        return ret

    if mqcommit and mqmessage:
        mqmessage = substitute_mqmessage(mqmessage, repo, { 'p': patchfn,
                                                            'a': 'NEW' })
        commands.commit(r.ui, r, message=mqmessage)
Exemple #54
0
 def test_date_and_mdate(self):
     ctx = FileCtx(self.repo, self.changectx, self.file_name)
     time.sleep(1)
     self.assertTrue(ctx.date < time.time())
     self.assertTrue(ctx.mdate is None)
     old_date = ctx.date
     time.sleep(1)
     with codecs.open(self.file_path, 'a', encoding='utf-8') as fp:
         fp.write('foo\n')
     commands.commit(self.ui, self.repo, user=b'foo', message=b'foo2')
     ctx = FileCtx(self.repo, self.changectx, self.file_name)
     self.assertEqual(ctx.date, old_date)
     self.assertTrue(ctx.mdate > old_date)
Exemple #55
0
def dosplit(ui, repo, tr, ctx, opts):
    committed = []  # [ctx]

    # Set working parent to ctx.p1(), and keep working copy as ctx's content
    if ctx.node() != repo.dirstate.p1():
        hg.clean(repo, ctx.node(), show_stats=False)
    with repo.dirstate.parentchange():
        scmutil.movedirstate(repo, ctx.p1())

    # Any modified, added, removed, deleted result means split is incomplete
    def incomplete(repo):
        st = repo.status()
        return any((st.modified, st.added, st.removed, st.deleted))

    # Main split loop
    while incomplete(repo):
        if committed:
            header = _(b'HG: Splitting %s. So far it has been split into:\n'
                       ) % short(ctx.node())
            # We don't want color codes in the commit message template, so
            # disable the label() template function while we render it.
            with ui.configoverride({(b'templatealias', b'label(l,x)'): b"x"},
                                   b'split'):
                for c in committed:
                    summary = cmdutil.format_changeset_summary(ui, c, b'split')
                    header += _(b'HG: - %s\n') % summary
            header += _(
                b'HG: Write commit message for the next split changeset.\n')
        else:
            header = _(b'HG: Splitting %s. Write commit message for the '
                       b'first split changeset.\n') % short(ctx.node())
        opts.update({
            b'edit': True,
            b'interactive': True,
            b'message': header + ctx.description(),
        })
        commands.commit(ui, repo, **pycompat.strkwargs(opts))
        newctx = repo[b'.']
        committed.append(newctx)

    if not committed:
        raise error.InputError(_(b'cannot split an empty revision'))

    scmutil.cleanupnodes(
        repo,
        {ctx.node(): [c.node() for c in committed]},
        operation=b'split',
        fixphase=True,
    )

    return committed[-1]
Exemple #56
0
    def commit_results(self, msg_id, submission_tuple, results):
        """ INTERNAL: Commit the results of a submission to the local repo. """

        print "RESULTS: ", results
        if len(results[3]) > 0 and sum([len(results[index]) for index in
                                        (0, 1, 2, 4)]) == 0: #HACK, fix order!
            raise NoChangesError()

        assert sum([len(results[index]) for index in (0, 1, 2, 4)]) > 0

        wikitext_dir = os.path.join(self.full_base_path(), 'wikitext')
        raised = True
        # grrr pylint gives spurious
        #pylint: disable-msg=E1101
        self.ui_.pushbuffer()
        try:
            # hg add new files.
            for name in results[0]:
                full_path = os.path.join(wikitext_dir, name)
                commands.add(self.ui_, self.repo, full_path)

            # hg add fork files
            for name in results[4]:
                full_path = os.path.join(wikitext_dir, name)
                commands.add(self.ui_, self.repo, full_path)

            # hg remove removed files.
            for name in results[2]:
                full_path = os.path.join(wikitext_dir, name)
                commands.remove(self.ui_, self.repo, full_path)

            # Writes to/prunes special file used to generate RemoteChanges.
            self.update_change_log(msg_id, submission_tuple, results, True)

            # REDFLAG: LATER, STAKING? later allow third field for staker.
            # fms_id|chk
            commit_msg = "%s|%s" % (submission_tuple[0],
                                    submission_tuple[3])
            # hg commit
            commands.commit(self.ui_, self.repo,
                            logfile=None, addremove=None, user=None,
                            date=None,
                            message=commit_msg)
            self.fixup_accepted_log() # Fix version in accepted.txt
            self.notify_committed(True)
            raised = False
        finally:
            text = self.ui_.popbuffer()
            if raised:
                self.logger.debug("commit_results -- popped log:\n%s" % text)
Exemple #57
0
 def _get_model(self, content):
     file_dir = os.path.join(self.repo_path, 'content')
     file_path = os.path.join(file_dir, 'stub.rst')
     if not os.path.isdir(file_dir):
         os.makedirs(file_dir)
     with codecs.open(file_path, 'w', encoding='utf-8') as fp:
         fp.write(content)
     commands.commit(self.ui,
                     self.repo,
                     file_path,
                     message='foo',
                     user='******',
                     addremove=True)
     ctx = FileCtx(self.repo, self.repo[None], 'content/stub.rst')
     return self.model(ctx, 'content', '.rst', 2)