2008-12-23 06:20:10 +03:00
|
|
|
import os
|
2008-12-24 02:45:34 +03:00
|
|
|
import unittest
|
2008-12-12 05:24:48 +03:00
|
|
|
|
2009-04-14 06:51:12 +04:00
|
|
|
from hgext import rebase
|
2008-12-12 05:24:48 +03:00
|
|
|
from mercurial import ui
|
|
|
|
from mercurial import hg
|
2008-12-23 06:20:10 +03:00
|
|
|
from mercurial import revlog
|
|
|
|
from mercurial import context
|
2008-12-24 20:12:23 +03:00
|
|
|
from mercurial import node
|
2009-05-22 17:12:31 +04:00
|
|
|
from mercurial import commands
|
2008-12-12 05:24:48 +03:00
|
|
|
|
2009-05-14 06:39:39 +04:00
|
|
|
from hgsubversion import util
|
|
|
|
from hgsubversion import utility_commands
|
2008-12-12 05:24:48 +03:00
|
|
|
import test_util
|
2009-05-14 06:39:39 +04:00
|
|
|
from hgsubversion import wrappers
|
2008-12-12 05:24:48 +03:00
|
|
|
|
2009-01-03 00:54:07 +03:00
|
|
|
expected_info_output = '''URL: %(repourl)s/%(branch)s
|
|
|
|
Repository Root: %(repourl)s
|
2008-12-12 05:24:48 +03:00
|
|
|
Repository UUID: df2126f7-00ab-4d49-b42c-7e981dde0bcf
|
|
|
|
Revision: %(rev)s
|
|
|
|
Node Kind: directory
|
|
|
|
Last Changed Author: durin
|
|
|
|
Last Changed Rev: %(rev)s
|
|
|
|
Last Changed Date: %(date)s
|
|
|
|
'''
|
|
|
|
|
|
|
|
class UtilityTests(test_util.TestBase):
|
2009-05-15 21:18:43 +04:00
|
|
|
@property
|
|
|
|
def repourl(self):
|
|
|
|
return util.normalize_url(test_util.fileurl(self.repo_path))
|
|
|
|
|
2008-12-12 05:24:48 +03:00
|
|
|
def test_info_output(self):
|
|
|
|
self._load_fixture_and_fetch('two_heads.svndump')
|
|
|
|
hg.update(self.repo, 'the_branch')
|
|
|
|
u = ui.ui()
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 01:09:59 +04:00
|
|
|
utility_commands.info(u, self.repo, self.wc_path)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
2008-12-12 05:24:48 +03:00
|
|
|
expected = (expected_info_output %
|
|
|
|
{'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)',
|
2009-05-15 21:18:43 +04:00
|
|
|
'repourl': self.repourl,
|
2008-12-12 05:24:48 +03:00
|
|
|
'branch': 'branches/the_branch',
|
|
|
|
'rev': 5,
|
|
|
|
})
|
2009-05-15 21:18:43 +04:00
|
|
|
self.assertEqual(actual, expected)
|
2008-12-12 05:24:48 +03:00
|
|
|
hg.update(self.repo, 'default')
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 01:09:59 +04:00
|
|
|
utility_commands.info(u, self.repo, self.wc_path)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
2008-12-12 05:24:48 +03:00
|
|
|
expected = (expected_info_output %
|
|
|
|
{'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)',
|
2009-05-15 21:18:43 +04:00
|
|
|
'repourl': self.repourl,
|
2008-12-12 05:24:48 +03:00
|
|
|
'branch': 'trunk',
|
|
|
|
'rev': 6,
|
|
|
|
})
|
2009-05-15 21:18:43 +04:00
|
|
|
self.assertEqual(actual, expected)
|
2008-12-12 05:24:48 +03:00
|
|
|
|
2008-12-24 20:12:23 +03:00
|
|
|
def test_parent_output(self):
|
|
|
|
self._load_fixture_and_fetch('two_heads.svndump')
|
|
|
|
u = ui.ui()
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2008-12-24 20:12:23 +03:00
|
|
|
parents = (self.repo['the_branch'].node(), revlog.nullid, )
|
|
|
|
def filectxfn(repo, memctx, path):
|
|
|
|
return context.memfilectx(path=path,
|
|
|
|
data='added',
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
|
|
|
ctx = context.memctx(self.repo,
|
|
|
|
parents,
|
|
|
|
'automated test',
|
|
|
|
['added_bogus_file', 'other_added_file', ],
|
|
|
|
filectxfn,
|
|
|
|
'testy',
|
|
|
|
'2008-12-21 16:32:00 -0500',
|
|
|
|
{'branch': 'localbranch', })
|
|
|
|
new = self.repo.commitctx(ctx)
|
|
|
|
hg.update(self.repo, new)
|
2009-04-11 07:38:29 +04:00
|
|
|
wrappers.parent(lambda x, y: None, u, self.repo, svn=True)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
|
|
|
self.assertEqual(actual,
|
2009-04-11 03:47:18 +04:00
|
|
|
'changeset: 3:4e256962fc5d\n'
|
|
|
|
'branch: the_branch\n'
|
|
|
|
'user: durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n'
|
|
|
|
'date: Wed Oct 08 01:39:05 2008 +0000\n'
|
|
|
|
'summary: add delta on the branch\n\n')
|
|
|
|
|
2008-12-24 20:12:23 +03:00
|
|
|
hg.update(self.repo, 'default')
|
2009-04-11 03:47:18 +04:00
|
|
|
# Make sure styles work
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 07:38:29 +04:00
|
|
|
wrappers.parent(lambda x, y: None, u, self.repo, svn=True, style='compact')
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
|
|
|
self.assertEqual(actual,
|
2009-04-11 03:47:18 +04:00
|
|
|
'4:1 1083037b18d8 2008-10-08 01:39 +0000 durin\n'
|
|
|
|
' Add gamma on trunk.\n\n')
|
|
|
|
# custom templates too
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 07:38:29 +04:00
|
|
|
wrappers.parent(lambda x, y: None, u, self.repo, svn=True, template='{node}\n')
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
|
|
|
self.assertEqual(actual, '1083037b18d85cd84fa211c5adbaeff0fea2cd9f\n')
|
2009-04-11 03:47:18 +04:00
|
|
|
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 07:38:29 +04:00
|
|
|
wrappers.parent(lambda x, y: None, u, self.repo, svn=True)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
|
|
|
self.assertEqual(actual,
|
2009-04-11 03:47:18 +04:00
|
|
|
'changeset: 4:1083037b18d8\n'
|
|
|
|
'parent: 1:c95251e0dd04\n'
|
|
|
|
'user: durin@df2126f7-00ab-4d49-b42c-7e981dde0bcf\n'
|
|
|
|
'date: Wed Oct 08 01:39:29 2008 +0000\n'
|
|
|
|
'summary: Add gamma on trunk.\n\n')
|
2008-12-24 20:12:23 +03:00
|
|
|
|
|
|
|
def test_outgoing_output(self):
|
|
|
|
self._load_fixture_and_fetch('two_heads.svndump')
|
|
|
|
u = ui.ui()
|
|
|
|
parents = (self.repo['the_branch'].node(), revlog.nullid, )
|
|
|
|
def filectxfn(repo, memctx, path):
|
|
|
|
return context.memfilectx(path=path,
|
|
|
|
data='added',
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
|
|
|
ctx = context.memctx(self.repo,
|
|
|
|
parents,
|
|
|
|
'automated test',
|
|
|
|
['added_bogus_file', 'other_added_file', ],
|
|
|
|
filectxfn,
|
|
|
|
'testy',
|
|
|
|
'2008-12-21 16:32:00 -0500',
|
|
|
|
{'branch': 'localbranch', })
|
|
|
|
new = self.repo.commitctx(ctx)
|
|
|
|
hg.update(self.repo, new)
|
2009-05-22 17:12:31 +04:00
|
|
|
u.pushbuffer()
|
|
|
|
commands.outgoing(u, self.repo, self.repourl)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
2009-05-22 17:12:31 +04:00
|
|
|
u.write(actual)
|
|
|
|
self.assertTrue(node.hex(self.repo['localbranch'].node())[:8] in actual)
|
|
|
|
actual = actual.splitlines()
|
|
|
|
self.assertEqual(actual[0], 'comparing with ' + self.repourl)
|
|
|
|
self.assertEqual(actual[1], 'changeset: 5:6de15430fa20')
|
|
|
|
self.assertEqual(actual[2], 'branch: localbranch')
|
|
|
|
self.assertEqual(actual[3], 'tag: tip')
|
|
|
|
self.assertEqual(actual[4], 'parent: 3:4e256962fc5d')
|
|
|
|
self.assertEqual(actual[5], 'user: testy')
|
|
|
|
self.assertEqual(actual[6], 'date: Sun Dec 21 16:32:00 2008 -0500')
|
|
|
|
self.assertEqual(actual[7], 'summary: automated test')
|
2008-12-24 20:12:23 +03:00
|
|
|
hg.update(self.repo, 'default')
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-05-22 17:12:31 +04:00
|
|
|
commands.outgoing(u, self.repo, self.repourl)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
2009-05-22 17:12:31 +04:00
|
|
|
u.write(actual)
|
|
|
|
self.assertEqual(actual.splitlines()[1], 'no changes found')
|
2008-12-12 05:41:57 +03:00
|
|
|
|
2008-12-23 06:20:10 +03:00
|
|
|
def test_rebase(self):
|
|
|
|
self._load_fixture_and_fetch('two_revs.svndump')
|
|
|
|
parents = (self.repo[0].node(), revlog.nullid, )
|
|
|
|
def filectxfn(repo, memctx, path):
|
|
|
|
return context.memfilectx(path=path,
|
|
|
|
data='added',
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
|
|
|
ctx = context.memctx(self.repo,
|
|
|
|
parents,
|
|
|
|
'automated test',
|
|
|
|
['added_bogus_file', 'other_added_file', ],
|
|
|
|
filectxfn,
|
|
|
|
'testy',
|
|
|
|
'2008-12-21 16:32:00 -0500',
|
|
|
|
{'branch': 'localbranch', })
|
|
|
|
self.repo.commitctx(ctx)
|
|
|
|
self.assertEqual(self.repo['tip'].branch(), 'localbranch')
|
|
|
|
beforerebasehash = self.repo['tip'].node()
|
|
|
|
hg.update(self.repo, 'tip')
|
2009-04-14 06:51:12 +04:00
|
|
|
wrappers.rebase(rebase.rebase, ui.ui(), self.repo, svn=True)
|
2008-12-23 06:20:10 +03:00
|
|
|
self.assertEqual(self.repo['tip'].branch(), 'localbranch')
|
|
|
|
self.assertEqual(self.repo['tip'].parents()[0].parents()[0], self.repo[0])
|
|
|
|
self.assertNotEqual(beforerebasehash, self.repo['tip'].node())
|
|
|
|
|
2009-02-24 23:30:21 +03:00
|
|
|
def test_genignore(self):
|
2009-05-15 21:18:43 +04:00
|
|
|
""" Test generation of .hgignore file. """
|
2009-05-14 06:39:39 +04:00
|
|
|
test_util.load_fixture_and_fetch('ignores.svndump', self.repo_path,
|
2009-05-15 21:18:43 +04:00
|
|
|
self.wc_path, noupdate=False)
|
2009-02-24 23:30:21 +03:00
|
|
|
u = ui.ui()
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 01:09:59 +04:00
|
|
|
utility_commands.genignore(u, self.repo, self.wc_path)
|
2009-02-24 23:30:21 +03:00
|
|
|
self.assertEqual(open(os.path.join(self.wc_path, '.hgignore')).read(),
|
|
|
|
'.hgignore\nsyntax:glob\nblah\notherblah\nbaz/magic\n')
|
|
|
|
|
2009-04-08 06:15:22 +04:00
|
|
|
def test_list_authors(self):
|
|
|
|
test_util.load_svndump_fixture(self.repo_path,
|
|
|
|
'replace_trunk_with_branch.svndump')
|
|
|
|
u = ui.ui()
|
2009-05-15 21:18:43 +04:00
|
|
|
u.pushbuffer()
|
2009-04-11 01:09:59 +04:00
|
|
|
utility_commands.listauthors(u,
|
|
|
|
args=[test_util.fileurl(self.repo_path)],
|
|
|
|
authors=None)
|
2009-05-15 21:18:43 +04:00
|
|
|
actual = u.popbuffer()
|
|
|
|
self.assertEqual(actual, 'Augie\nevil\n')
|
2009-04-08 06:15:22 +04:00
|
|
|
|
|
|
|
|
|
|
|
def test_list_authors_map(self):
|
|
|
|
test_util.load_svndump_fixture(self.repo_path,
|
|
|
|
'replace_trunk_with_branch.svndump')
|
|
|
|
author_path = os.path.join(self.repo_path, 'authors')
|
2009-04-11 01:09:59 +04:00
|
|
|
utility_commands.listauthors(ui.ui(),
|
|
|
|
args=[test_util.fileurl(self.repo_path)],
|
|
|
|
authors=author_path)
|
2009-04-08 06:15:22 +04:00
|
|
|
self.assertEqual(open(author_path).read(), 'Augie=\nevil=\n')
|
2009-04-11 03:47:18 +04:00
|
|
|
|
2008-12-24 02:45:34 +03:00
|
|
|
|
|
|
|
def suite():
|
|
|
|
all = [unittest.TestLoader().loadTestsFromTestCase(UtilityTests),
|
|
|
|
]
|
|
|
|
return unittest.TestSuite(all)
|