def test_push_to_non_tip(self):
        self.test_push_to_branch(push=False)
        wc2path = self.wc_path + '_clone'
        u = self.repo.ui
        hg.clone(self.repo.ui, self.wc_path, wc2path, update=False)
        res = self.pushrevisions()
        self.assertEqual(0, res)
        oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'))
        hgrc = oldf.read()
        oldf.close()
        shutil.rmtree(self.wc_path)
        hg.clone(u, wc2path, self.wc_path, update=False)
        oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'), 'w')
        oldf.write(hgrc)
        oldf.close()

        # do a commit here
        self.commitchanges([('foobaz', 'foobaz', 'This file is added on default.', ),
                            ],
                           parent='default',
                           message='commit to default')
        from hgsubversion import svncommands
        svncommands.rebuildmeta(u,
                                self.repo,
                                args=[test_util.fileurl(self.repo_path)])


        hg.update(self.repo, self.repo['tip'].node())
        oldnode = self.repo['tip'].hex()
        self.pushrevisions(expected_extra_back=1)
        self.assertNotEqual(oldnode, self.repo['tip'].hex(), 'Revision was not pushed.')
Exemple #2
0
    def test_branchmap_rebuildmeta(self):
        '''test rebuildmeta on a branchmapped clone'''
        repo_path = self.load_svndump('branchmap.svndump')
        branchmap = open(self.branchmap, 'w')
        branchmap.write("badname = dit\n")
        branchmap.write("feature = dah\n")
        branchmap.close()
        ui = self.ui()
        ui.setconfig('hgsubversion', 'branchmap', self.branchmap)
        commands.clone(ui,
                       test_util.fileurl(repo_path),
                       self.wc_path,
                       branchmap=self.branchmap)
        originfo = self.repo.svnmeta().branches

        # clone & rebuild
        ui = self.ui()
        src, dest = test_util.hgclone(ui,
                                      self.wc_path,
                                      self.wc_path + '_clone',
                                      update=False)
        src = test_util.getlocalpeer(src)
        dest = test_util.getlocalpeer(dest)
        svncommands.rebuildmeta(ui, dest, args=[test_util.fileurl(repo_path)])

        # just check the keys; assume the contents are unaffected by the branch
        # map and thus properly tested by other tests
        self.assertEquals(sorted(src.svnmeta().branches),
                          sorted(dest.svnmeta().branches))
 def test_info_output(self, custom=False):
     if custom:
         config = {
             'hgsubversionbranch.default': 'trunk',
             'hgsubversionbranch.the_branch': 'branches/the_branch',
             }
     else:
         config = {}
     repo, repo_path = self.load_and_fetch('two_heads.svndump', config=config)
     hg.update(self.repo, 'the_branch')
     u = self.ui()
     u.pushbuffer()
     svncommands.info(u, self.repo)
     actual = u.popbuffer()
     expected = (expected_info_output %
                 {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
                  'repourl': repourl(repo_path),
                  'branch': 'branches/the_branch',
                  'rev': 5,
                  })
     self.assertMultiLineEqual(actual, expected)
     hg.update(self.repo, 'default')
     u.pushbuffer()
     svncommands.info(u, self.repo)
     actual = u.popbuffer()
     expected = (expected_info_output %
                 {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
                  'repourl': repourl(repo_path),
                  'branch': 'trunk',
                  'rev': 6,
                  })
     self.assertMultiLineEqual(actual, expected)
     hg.update(self.repo, 'default')
     u.pushbuffer()
     svncommands.info(u, self.repo, rev=3)
     actual = u.popbuffer()
     expected = (expected_info_output %
                 {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
                  'repourl': repourl(repo_path),
                  'branch': 'branches/the_branch',
                  'rev': 5,
                  })
     self.assertMultiLineEqual(actual, expected)
     destpath = self.wc_path + '_clone'
     test_util.hgclone(u, self.repo, destpath)
     repo2 = hg.repository(u, destpath)
     repo2.ui.setconfig('paths', 'default-push',
                        self.repo.ui.config('paths', 'default'))
     hg.update(repo2, 'default')
     svncommands.rebuildmeta(u, repo2, [])
     u.pushbuffer()
     svncommands.info(u, repo2)
     actual = u.popbuffer()
     expected = (expected_info_output %
                 {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
                  'repourl': repourl(repo_path),
                  'branch': 'trunk',
                  'rev': 6,
                  })
     self.assertMultiLineEqual(actual, expected)
    def test_branchmap_rebuildmeta(self):
        '''test rebuildmeta on a branchmapped clone'''
        repo_path = self.load_svndump('branchmap.svndump')
        branchmap = open(self.branchmap, 'w')
        branchmap.write("badname = dit\n")
        branchmap.write("feature = dah\n")
        branchmap.close()
        ui = self.ui()
        ui.setconfig('hgsubversion', 'branchmap', self.branchmap)
        commands.clone(ui, test_util.fileurl(repo_path),
                       self.wc_path, branchmap=self.branchmap)
        originfo = self.repo.svnmeta().branches

        # clone & rebuild
        ui = self.ui()
        src, dest = test_util.hgclone(ui, self.wc_path, self.wc_path + '_clone',
                                      update=False)
        src = test_util.getlocalpeer(src)
        dest = test_util.getlocalpeer(dest)
        svncommands.rebuildmeta(ui, dest,
                                args=[test_util.fileurl(repo_path)])

        # just check the keys; assume the contents are unaffected by the branch
        # map and thus properly tested by other tests
        self.assertEquals(sorted(src.svnmeta().branches),
                          sorted(dest.svnmeta().branches))
def _do_case(self, name, stupid, single):
    subdir = test_util.subdir.get(name, '')
    layout = 'auto'
    if single:
        layout = 'single'
    self._load_fixture_and_fetch(name, subdir=subdir, stupid=stupid, layout=layout)
    assert len(self.repo) > 0
    wc2_path = self.wc_path + '_clone'
    u = ui.ui()
    src, dest = hg.clone(u, self.wc_path, wc2_path, update=False)

    # insert a wrapper that prevents calling changectx.children()
    def failfn(orig, ctx):
        self.fail('calling %s is forbidden; it can cause massive slowdowns '
                  'when rebuilding large repositories' % orig)

    origchildren = getattr(context.changectx, 'children')
    extensions.wrapfunction(context.changectx, 'children', failfn)

    try:
        svncommands.rebuildmeta(u, dest,
                                args=[test_util.fileurl(self.repo_path +
                                                        subdir), ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
                    'no .hg/svn directory in the source!')
    self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
                    'no .hg/svn directory in the destination!')
    dest = hg.repository(u, os.path.dirname(dest.path))
    for tf in ('rev_map', 'uuid', 'tagmap', 'layout', 'subdir', ):
        stf = os.path.join(src.path, 'svn', tf)
        self.assertTrue(os.path.isfile(stf), '%r is missing!' % stf)
        dtf = os.path.join(dest.path, 'svn', tf)
        self.assertTrue(os.path.isfile(dtf), '%r is missing!' % tf)
        old, new = open(stf).read(), open(dtf).read()
        self.assertMultiLineEqual(old, new)
        self.assertEqual(src.branchtags(), dest.branchtags())
    srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info')))
    destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info')))
    self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys()))
    revkeys = svnmeta.SVNMeta(dest).revmap.keys()
    for branch in destbi:
        srcinfo = srcbi[branch]
        destinfo = destbi[branch]
        if srcinfo[:2] == (None, 0) or destinfo[:2] == (None, 0):
            self.assertTrue(srcinfo[2] <= destinfo[2],
                            'Latest revision for %s decreased from %d to %d!'
                            % (branch or 'default', srcinfo[2], destinfo[2]))
            self.assertEqual(srcinfo[0], destinfo[0])
        else:
            pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1],
                        revkeys), reverse=True)[0][0]
            self.assertEqual(pr, destinfo[1])
            self.assertEqual(srcinfo[2], destinfo[2])
 def test_svnrebuildmeta(self):
     otherpath = self.load_svndump('binaryfiles-broken.svndump')
     otherurl = test_util.fileurl(otherpath)
     self.load_and_fetch('replace_trunk_with_branch.svndump')
     # rebuildmeta with original repo
     svncommands.rebuildmeta(self.ui(), repo=self.repo, args=[])
     # rebuildmeta with unrelated repo
     self.assertRaises(hgutil.Abort,
                       svncommands.rebuildmeta,
                       self.ui(), repo=self.repo, args=[otherurl])
     # rebuildmeta --unsafe-skip-uuid-check with unrelated repo
     svncommands.rebuildmeta(self.ui(), repo=self.repo, args=[otherurl],
                             unsafe_skip_uuid_check=True)
 def test_svnrebuildmeta(self):
     otherpath = self.load_svndump('binaryfiles-broken.svndump')
     otherurl = test_util.fileurl(otherpath)
     self.load_and_fetch('replace_trunk_with_branch.svndump')
     # rebuildmeta with original repo
     svncommands.rebuildmeta(self.ui(), repo=self.repo, args=[])
     # rebuildmeta with unrelated repo
     self.assertRaises(hgerror.Abort,
                       svncommands.rebuildmeta,
                       self.ui(),
                       repo=self.repo,
                       args=[otherurl])
     # rebuildmeta --unsafe-skip-uuid-check with unrelated repo
     svncommands.rebuildmeta(self.ui(),
                             repo=self.repo,
                             args=[otherurl],
                             unsafe_skip_uuid_check=True)
Exemple #8
0
 def test_most_recent_is_edited(self, stupid=False):
     repo = self._load_fixture_and_fetch('most-recent-is-edit-tag.svndump',
                                         stupid=stupid)
     self.repo.ui.status(
         "Note: this test failing may be because of a rebuildmeta failure.\n"
         "You should check that before assuming issues with this test.\n")
     wc2_path = self.wc_path + '2'
     src, dest = hg.clone(repo.ui, self.wc_path, wc2_path, update=False)
     svncommands.rebuildmeta(repo.ui,
                            dest,
                            args=[test_util.fileurl(self.repo_path), ])
     commands.pull(self.repo.ui, self.repo, stupid=stupid)
     dtags, srctags = dest.tags(), self.repo.tags()
     dtags.pop('tip')
     srctags.pop('tip')
     self.assertEqual(dtags, srctags)
     self.assertEqual(dest.heads(), self.repo.heads())
def _do_case(self, name, stupid, single):
    subdir = test_util.subdir.get(name, '')
    layout = 'auto'
    if single:
        layout = 'single'
    self._load_fixture_and_fetch(name, subdir=subdir, stupid=stupid, layout=layout)
    assert len(self.repo) > 0
    wc2_path = self.wc_path + '_clone'
    u = ui.ui()
    src, dest = hg.clone(u, self.wc_path, wc2_path, update=False)
    svncommands.rebuildmeta(u,
                            dest,
                            args=[test_util.fileurl(self.repo_path +
                                                    subdir), ])
    self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
                    'no .hg/svn directory in the source!')
    self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')),
                    'no .hg/svn directory in the destination!')
    dest = hg.repository(u, os.path.dirname(dest.path))
    for tf in ('rev_map', 'uuid', 'tagmap', 'layout', ):
        stf = os.path.join(src.path, 'svn', tf)
        self.assertTrue(os.path.isfile(stf), '%r is missing!' % stf)
        dtf = os.path.join(dest.path, 'svn', tf)
        self.assertTrue(os.path.isfile(dtf), '%r is missing!' % tf)
        old, new = open(stf).read(), open(dtf).read()
        # uncomment next line for easy-ish debugging.
        # os.system('diff -u %s %s' % (stf, dtf))
        self.assertEqual(old, new)
        self.assertEqual(src.branchtags(), dest.branchtags())
    srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info')))
    destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info')))
    self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys()))
    revkeys = svnmeta.SVNMeta(dest).revmap.keys()
    for branch in destbi:
        srcinfo = srcbi[branch]
        destinfo = destbi[branch]
        if srcinfo[:2] == (None, 0) or destinfo[:2] == (None, 0):
            self.assert_(srcinfo[2] <= destinfo[2])
            self.assertEqual(srcinfo[0], destinfo[0])
        else:
            pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1],
                        revkeys), reverse=True)[0][0]
            self.assertEqual(pr, destinfo[1])
            self.assertEqual(srcinfo[2], destinfo[2])
Exemple #10
0
 def test_most_recent_is_edited(self):
     repo, repo_path = self.load_and_fetch(
         'most-recent-is-edit-tag.svndump')
     self.repo.ui.status(
         "Note: this test failing may be because of a rebuildmeta failure.\n"
         "You should check that before assuming issues with this test.\n")
     wc2_path = self.wc_path + '2'
     src, dest = test_util.hgclone(repo.ui,
                                   self.wc_path,
                                   wc2_path,
                                   update=False)
     dest = test_util.getlocalpeer(dest)
     svncommands.rebuildmeta(repo.ui,
                             dest,
                             args=[
                                 test_util.fileurl(repo_path),
                             ])
     commands.pull(self.repo.ui, self.repo)
     dtags, srctags = dest.tags(), self.repo.tags()
     dtags.pop('tip')
     srctags.pop('tip')
     self.assertEqual(dtags, srctags)
     self.assertEqual(dest.heads(), self.repo.heads())
    def test_push_to_non_tip(self):
        self.test_push_to_branch(push=False)
        wc2path = self.wc_path + '_clone'
        u = self.repo.ui
        test_util.hgclone(self.repo.ui, self.wc_path, wc2path, update=False)
        res = self.pushrevisions()
        self.assertEqual(0, res)
        oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'))
        hgrc = oldf.read()
        oldf.close()
        shutil.rmtree(self.wc_path)
        test_util.hgclone(u, wc2path, self.wc_path, update=False)
        oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'), 'w')
        oldf.write(hgrc)
        oldf.close()

        # do a commit here
        self.commitchanges([
            (
                'foobaz',
                'foobaz',
                'This file is added on default.',
            ),
        ],
                           parent='default',
                           message='commit to default')
        from hgsubversion import svncommands
        svncommands.rebuildmeta(u,
                                self.repo,
                                args=[test_util.fileurl(self.repo_path)])

        hg.update(self.repo, revsymbol(self.repo, 'tip').node())
        oldnode = revsymbol(self.repo, 'tip').hex()
        self.pushrevisions(expected_extra_back=1)
        self.assertNotEqual(oldnode,
                            revsymbol(self.repo, 'tip').hex(),
                            'Revision was not pushed.')
 def test_info_output(self, custom=False):
     if custom:
         config = {
             'hgsubversionbranch.default': 'trunk',
             'hgsubversionbranch.the_branch': 'branches/the_branch',
         }
     else:
         config = {}
     repo, repo_path = self.load_and_fetch('two_heads.svndump',
                                           config=config)
     hg.update(self.repo, revsymbol(self.repo, 'the_branch'))
     u = self.ui()
     u.pushbuffer()
     svncommands.info(u, self.repo)
     actual = u.popbuffer()
     expected = (expected_info_output % {
         'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
         'repourl': repourl(repo_path),
         'branch': 'branches/the_branch',
         'rev': 5,
     })
     self.assertMultiLineEqual(actual, expected)
     hg.update(self.repo, revsymbol(self.repo, 'default'))
     u.pushbuffer()
     svncommands.info(u, self.repo)
     actual = u.popbuffer()
     expected = (expected_info_output % {
         'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
         'repourl': repourl(repo_path),
         'branch': 'trunk',
         'rev': 6,
     })
     self.assertMultiLineEqual(actual, expected)
     hg.update(self.repo, revsymbol(self.repo, 'default'))
     u.pushbuffer()
     svncommands.info(u, self.repo, rev=3)
     actual = u.popbuffer()
     expected = (expected_info_output % {
         'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
         'repourl': repourl(repo_path),
         'branch': 'branches/the_branch',
         'rev': 5,
     })
     self.assertMultiLineEqual(actual, expected)
     destpath = self.wc_path + '_clone'
     test_util.hgclone(u, self.repo, destpath)
     repo2 = hg.repository(u, destpath)
     repo2.ui.setconfig('paths', 'default-push',
                        self.repo.ui.config('paths', 'default'))
     hg.update(repo2, revsymbol(self.repo, 'default'))
     svncommands.rebuildmeta(u, repo2, [])
     u.pushbuffer()
     svncommands.info(u, repo2)
     actual = u.popbuffer()
     expected = (expected_info_output % {
         'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
         'repourl': repourl(repo_path),
         'branch': 'trunk',
         'rev': 6,
     })
     self.assertMultiLineEqual(actual, expected)
def _do_case(self, name, layout):
    subdir = test_util.subdir.get(name, '')
    single = layout == 'single'
    u = test_util.testui()
    config = {}
    if layout == 'custom':
        for branch, path in test_util.custom.get(name, {}).iteritems():
            config['hgsubversionbranch.%s' % branch] = path
            u.setconfig('hgsubversionbranch', branch, path)
    repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout)
    assert test_util.repolen(self.repo) > 0
    wc2_path = self.wc_path + '_clone'
    src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False)
    src = test_util.getlocalpeer(src)
    dest = test_util.getlocalpeer(dest)

    # insert a wrapper that prevents calling changectx.children()
    def failfn(orig, ctx):
        self.fail('calling %s is forbidden; it can cause massive slowdowns '
                  'when rebuilding large repositories' % orig)

    origchildren = getattr(context.changectx, 'children')
    extensions.wrapfunction(context.changectx, 'children', failfn)

    try:
        svncommands.rebuildmeta(u,
                                dest,
                                args=[
                                    test_util.fileurl(repo_path + subdir),
                                ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    self._run_assertions(name, single, src, dest, u)

    wc3_path = self.wc_path + '_partial'
    src, dest = test_util.hgclone(u,
                                  self.wc_path,
                                  wc3_path,
                                  update=False,
                                  rev=['0'])
    srcrepo = test_util.getlocalpeer(src)
    dest = test_util.getlocalpeer(dest)

    # insert a wrapper that prevents calling changectx.children()
    extensions.wrapfunction(context.changectx, 'children', failfn)

    try:
        svncommands.rebuildmeta(u,
                                dest,
                                args=[
                                    test_util.fileurl(repo_path + subdir),
                                ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    if hgutil.safehasattr(localrepo.localrepository, 'pull'):
        dest.pull(src)
    else:
        # Mercurial >= 3.2
        from mercurial import exchange
        exchange.pull(dest, src)

    # insert a wrapper that prevents calling changectx.children()
    extensions.wrapfunction(context.changectx, 'children', failfn)
    try:
        svncommands.updatemeta(u,
                               dest,
                               args=[
                                   test_util.fileurl(repo_path + subdir),
                               ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    self._run_assertions(name, single, srcrepo, dest, u)
def _do_case(self, name, layout):
    subdir = test_util.subdir.get(name, '')
    single = layout == 'single'
    u = ui.ui()
    config = {}
    if layout == 'custom':
        for branch, path in test_util.custom.get(name, {}).iteritems():
            config['hgsubversionbranch.%s' % branch] = path
            u.setconfig('hgsubversionbranch', branch, path)
    repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout)
    assert test_util.repolen(self.repo) > 0
    wc2_path = self.wc_path + '_clone'
    src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False)
    src = test_util.getlocalpeer(src)
    dest = test_util.getlocalpeer(dest)

    # insert a wrapper that prevents calling changectx.children()
    def failfn(orig, ctx):
        self.fail('calling %s is forbidden; it can cause massive slowdowns '
                  'when rebuilding large repositories' % orig)

    origchildren = getattr(context.changectx, 'children')
    extensions.wrapfunction(context.changectx, 'children', failfn)

    try:
        svncommands.rebuildmeta(u, dest,
                                args=[test_util.fileurl(repo_path +
                                                        subdir), ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    self._run_assertions(name, single, src, dest, u)

    wc3_path = self.wc_path + '_partial'
    src, dest = test_util.hgclone(u,
                                  self.wc_path,
                                  wc3_path,
                                  update=False,
                                  rev=[0])
    srcrepo = test_util.getlocalpeer(src)
    dest = test_util.getlocalpeer(dest)

    # insert a wrapper that prevents calling changectx.children()
    extensions.wrapfunction(context.changectx, 'children', failfn)

    try:
        svncommands.rebuildmeta(u, dest,
                                args=[test_util.fileurl(repo_path +
                                                        subdir), ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    if hgutil.safehasattr(localrepo.localrepository, 'pull'):
        dest.pull(src)
    else:
        # Mercurial >= 3.2
        from mercurial import exchange
        exchange.pull(dest, src)

    # insert a wrapper that prevents calling changectx.children()
    extensions.wrapfunction(context.changectx, 'children', failfn)
    try:
        svncommands.updatemeta(u, dest,
                               args=[test_util.fileurl(repo_path +
                                                        subdir), ])
    finally:
        # remove the wrapper
        context.changectx.children = origchildren

    self._run_assertions(name, single, srcrepo, dest, u)