本文整理汇总了Python中util.hg.mercurial函数的典型用法代码示例。如果您正苦于以下问题:Python mercurial函数的具体用法?Python mercurial怎么用?Python mercurial使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mercurial函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clone_branch
def clone_branch(branch, branch_url):
"""
Clone tip of the specified branch.
"""
remote = branch_url
# Set up the clean repository if it doesn't exist,
# otherwise, it will be updated.
clean = os.path.join('clean')
clean_repo = os.path.join(clean, branch)
if not os.access(clean, os.F_OK):
log_msg(os.getcwd())
os.mkdir(clean)
try:
mercurial(remote, clean_repo)
except subprocess.CalledProcessError as error:
log_msg('[Clone] error cloning \'%s\' into clean repository:\n%s'
% (remote, error))
return None
# Clone that clean repository to active and return that revision
active = os.path.join('active')
active_repo = os.path.join(active, branch)
if not os.access(active, os.F_OK):
os.mkdir(active)
elif os.access(active_repo, os.F_OK):
shutil.rmtree(active_repo)
try:
print 'Cloning from %s -----> %s' % (clean_repo, active_repo)
revision = mercurial(clean_repo, active_repo)
log_msg('[Clone] Cloned revision %s' %(revision), log.info)
except subprocess.CalledProcessError as error:
log_msg('[Clone] error cloning \'%s\' into active repository:\n%s'
% (remote, error))
return None
return revision
示例2: testMercurialWithShareAndBundle
def testMercurialWithShareAndBundle(self):
# First create the bundle
bundle = os.path.join(self.tmpdir, 'bundle')
run_cmd(['hg', 'bundle', '-a', bundle], cwd=self.repodir)
# Create a commit
open(os.path.join(self.repodir, 'test.txt'), 'w').write('hello!')
run_cmd(['hg', 'add', 'test.txt'], cwd=self.repodir)
run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=self.repodir)
# Wrap unbundle so we can tell if it got called
orig_unbundle = unbundle
try:
called = []
def new_unbundle(*args, **kwargs):
called.append(True)
return orig_unbundle(*args, **kwargs)
hg.unbundle = new_unbundle
shareBase = os.path.join(self.tmpdir, 'share')
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
mercurial(
self.repodir, self.wc, shareBase=shareBase, bundles=[bundle])
self.assertEquals(called, [True])
self.assertEquals(
getRevisions(self.repodir), getRevisions(self.wc))
self.assertEquals(
getRevisions(self.repodir), getRevisions(sharerepo))
finally:
hg.unbundle = orig_unbundle
示例3: tagOtherRepo
def tagOtherRepo(config, repo, reponame, revision, pushAttempts):
remote = make_hg_url(HG, repo)
mercurial(remote, reponame)
def tagRepo(repo, attempt, config, revision, tags):
# set totalChangesets=1 because tag() generates exactly 1 commit
totalChangesets = 1
# update to the desired revision first, then to the tip of revision's
# branch to avoid new head creation
update(repo, revision=revision)
update(repo)
tag(repo, revision, tags, config['hgUsername'])
outgoingRevs = retry(out, kwargs=dict(src=reponame, remote=remote,
ssh_username=config[
'hgUsername'],
ssh_key=config['hgSshKey']))
if len(outgoingRevs) != totalChangesets:
raise Exception("Wrong number of outgoing revisions")
pushRepo = make_hg_url(HG, repo, protocol='ssh')
def tag_wrapper(r, n):
tagRepo(r, n, config, revision, tags)
def cleanup_wrapper():
cleanOutgoingRevs(reponame, pushRepo, config['hgUsername'],
config['hgSshKey'])
retry(apply_and_push, cleanup=cleanup_wrapper,
args=(reponame, pushRepo, tag_wrapper, pushAttempts),
kwargs=dict(ssh_username=config['hgUsername'],
ssh_key=config['hgSshKey']))
示例4: clone_branch
def clone_branch(branch):
"""
Clone the tip of the specified branch.
"""
remote = '%s%s' % (config['hg_base_url'], branch)
# Set up the local/clean repository if it doesn't exist,
# otherwise, it will update.
clean = 'clean/%s' % (branch)
if not os.access('clean', os.F_OK):
os.mkdir('clean')
try:
mercurial(remote, clean)
except subprocess.CalledProcessError as error:
log_msg('[Clone] error cloning \'%s\' into local repository :\n%s'
%(remote,error))
return None
# Clone that local repository and return that revision
active = 'active/%s' % (branch)
if not os.access('active', os.F_OK):
os.mkdir('active')
elif os.access(active, os.F_OK):
shutil.rmtree(active)
try:
revision = mercurial(clean, active)
log_msg('[Clone] Cloned revision %s' % (revision))
except subprocess.CalledProcessError as error:
log_msg('[Clone] error cloning \'%s\' into active repository :\n%s'
%(remote,error))
return None
return revision
示例5: testMercurialWithNewShare
def testMercurialWithNewShare(self):
shareBase = os.path.join(self.tmpdir, 'share')
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
mercurial(self.repodir, self.wc, shareBase=shareBase)
self.assertEquals(getRevisions(self.repodir), getRevisions(self.wc))
self.assertEquals(getRevisions(self.repodir), getRevisions(sharerepo))
示例6: testMercurialChangeRepo
def testMercurialChangeRepo(self):
# Create a new repo
old_env = os.environ.copy()
if 'HG_SHARE_BASE_DIR' in os.environ:
del os.environ['HG_SHARE_BASE_DIR']
try:
repo2 = os.path.join(self.tmpdir, 'repo2')
run_cmd(['%s/init_hgrepo.sh' % os.path.dirname(__file__), repo2])
self.assertNotEqual(self.revisions, getRevisions(repo2))
# Clone the original repo
mercurial(self.repodir, self.wc)
self.assertEquals(getRevisions(self.wc), self.revisions)
open(os.path.join(self.wc, 'test.txt'), 'w').write("hello!")
# Clone the new one
mercurial(repo2, self.wc)
self.assertEquals(getRevisions(self.wc), getRevisions(repo2))
# Make sure our local file went away
self.failUnless(
not os.path.exists(os.path.join(self.wc, 'test.txt')))
finally:
os.environ.clear()
os.environ.update(old_env)
示例7: testMercurialWithShareAndBundle
def testMercurialWithShareAndBundle(self):
# First create the bundle
bundle = os.path.join(self.tmpdir, "bundle")
run_cmd(["hg", "bundle", "-a", bundle], cwd=self.repodir)
# Create a commit
open(os.path.join(self.repodir, "test.txt"), "w").write("hello!")
run_cmd(["hg", "add", "test.txt"], cwd=self.repodir)
run_cmd(["hg", "commit", "-m", "adding changeset"], cwd=self.repodir)
# Wrap unbundle so we can tell if it got called
orig_unbundle = unbundle
try:
called = []
def new_unbundle(*args, **kwargs):
called.append(True)
return orig_unbundle(*args, **kwargs)
hg.unbundle = new_unbundle
shareBase = os.path.join(self.tmpdir, "share")
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
mercurial(self.repodir, self.wc, shareBase=shareBase, bundles=[bundle])
self.assertEquals(called, [True])
self.assertEquals(getRevisions(self.repodir), getRevisions(self.wc))
self.assertEquals(getRevisions(self.repodir), getRevisions(sharerepo))
finally:
hg.unbundle = orig_unbundle
示例8: testOutofSyncMirrorFailingMaster
def testOutofSyncMirrorFailingMaster(self):
# First create the mirror
mirror = os.path.join(self.tmpdir, "repo2")
clone(self.repodir, mirror)
shareBase = os.path.join(self.tmpdir, "share")
os.mkdir(shareBase)
mercurial(self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror])
# Create a bundle
bundle = os.path.join(self.tmpdir, "bundle")
run_cmd(["hg", "bundle", "-a", bundle], cwd=self.repodir)
# Move our repodir out of the way so that pulling/cloning from it fails
os.rename(self.repodir, self.repodir + "-bad")
# Try and update to a non-existent revision using our mirror and
# bundle, with the master failing. We should fail
self.assertRaises(
subprocess.CalledProcessError,
mercurial,
self.repodir,
self.wc,
shareBase=shareBase,
mirrors=[mirror],
bundles=[bundle],
revision="1234567890",
)
示例9: testMercurialSkipPull
def testMercurialSkipPull(self):
# Clone once into our working copy
mercurial(self.repodir, self.wc)
# The second clone should avoid calling pull()
with patch('util.hg.pull') as patched_pull:
mercurial(self.repodir, self.wc, revision=self.revisions[-1])
self.assertEquals(patched_pull.call_count, 0)
示例10: testMercurialUpdateRev
def testMercurialUpdateRev(self):
rev = mercurial(self.repodir, self.wc, revision=self.revisions[-1])
self.assertEquals(rev, self.revisions[-1])
open(os.path.join(self.wc, 'test.txt'), 'w').write("hello!")
rev = mercurial(self.repodir, self.wc, revision=self.revisions[0])
self.assertEquals(rev, self.revisions[0])
# Make sure our local file didn't go away
self.failUnless(os.path.exists(os.path.join(self.wc, 'test.txt')))
示例11: tagRepo
def tagRepo(config, repo, reponame, revision, tags, bumpFiles, relbranch,
pushAttempts, defaultBranch='default'):
remote = make_hg_url(HG, repo)
mercurial(remote, reponame)
def bump_and_tag(repo, attempt, config, relbranch, revision, tags,
defaultBranch):
# set relbranchChangesets=1 because tag() generates exactly 1 commit
relbranchChangesets = 1
defaultBranchChangesets = 0
if relbranch in get_branches(reponame):
update(reponame, revision=relbranch)
else:
update(reponame, revision=revision)
run_cmd(['hg', 'branch', relbranch], cwd=reponame)
if len(bumpFiles) > 0:
# Bump files on the relbranch, if necessary
bump(reponame, bumpFiles, 'version')
run_cmd(['hg', 'diff'], cwd=repo)
try:
get_output(['hg', 'commit', '-u', config['hgUsername'],
'-m', getBumpCommitMessage(config['productName'], config['version'])],
cwd=reponame)
relbranchChangesets += 1
except subprocess.CalledProcessError, e:
# We only want to ignore exceptions caused by having nothing to
# commit, which are OK. We still want to raise exceptions caused
# by any other thing.
if e.returncode != 1 or "nothing changed" not in e.output:
raise
# We always want our tags pointing at the tip of the relbranch
# so we need to grab the current revision after we've switched
# branches and bumped versions.
revision = get_revision(reponame)
# Create the desired tags on the relbranch
tag(repo, revision, tags, config['hgUsername'])
# This is the bump of the version on the default branch
# We do it after the other one in order to get the tip of the
# repository back on default, thus avoiding confusion.
if len(bumpFiles) > 0:
update(reponame, revision=defaultBranch)
bump(reponame, bumpFiles, 'nextVersion')
run_cmd(['hg', 'diff'], cwd=repo)
try:
get_output(['hg', 'commit', '-u', config['hgUsername'],
'-m', getBumpCommitMessage(config['productName'], config['version'])],
cwd=reponame)
defaultBranchChangesets += 1
except subprocess.CalledProcessError, e:
if e.returncode != 1 or "nothing changed" not in e.output:
raise
示例12: testMercurialWithExistingShare
def testMercurialWithExistingShare(self):
shareBase = os.path.join(self.tmpdir, 'share')
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
mercurial(self.repodir, sharerepo)
open(os.path.join(self.repodir, 'test.txt'), 'w').write('hello!')
run_cmd(['hg', 'add', 'test.txt'], cwd=self.repodir)
run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=self.repodir)
mercurial(self.repodir, self.wc, shareBase=shareBase)
self.assertEquals(getRevisions(self.repodir), getRevisions(self.wc))
self.assertEquals(getRevisions(self.repodir), getRevisions(sharerepo))
示例13: testMercurialWithShareBaseInEnv
def testMercurialWithShareBaseInEnv(self):
shareBase = os.path.join(self.tmpdir, "share")
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
try:
os.environ["HG_SHARE_BASE_DIR"] = shareBase
mercurial(self.repodir, self.wc)
self.assertEquals(getRevisions(self.repodir), getRevisions(self.wc))
self.assertEquals(getRevisions(self.repodir), getRevisions(sharerepo))
finally:
del os.environ["HG_SHARE_BASE_DIR"]
示例14: testMercurialShareOutgoing
def testMercurialShareOutgoing(self):
# ensure that outgoing changesets in a shared clone affect the shared history
repo5 = os.path.join(self.tmpdir, 'repo5')
repo6 = os.path.join(self.tmpdir, 'repo6')
mercurial(self.repodir, repo5)
share(repo5, repo6)
open(os.path.join(repo6, 'test.txt'), 'w').write("hello!")
# modify the history of the new clone
run_cmd(['hg', 'add', 'test.txt'], cwd=repo6)
run_cmd(['hg', 'commit', '-m', 'adding changeset'], cwd=repo6)
self.assertNotEquals(self.revisions, getRevisions(repo6))
self.assertNotEquals(self.revisions, getRevisions(repo5))
self.assertEquals(getRevisions(repo5), getRevisions(repo6))
示例15: testMercurialByRevWithShareAndMirror
def testMercurialByRevWithShareAndMirror(self):
# First create the mirror
mirror = os.path.join(self.tmpdir, 'repo2')
clone(self.repodir, mirror)
shareBase = os.path.join(self.tmpdir, 'share')
sharerepo = os.path.join(shareBase, self.repodir.lstrip("/"))
os.mkdir(shareBase)
mercurial(self.repodir, self.wc, shareBase=shareBase, mirrors=[mirror], clone_by_rev=True, revision=self.revisions[-1])
# We should only have the one revision
self.assertEquals(getRevisions(sharerepo), self.revisions[-1:])
self.assertEquals(getRevisions(self.wc), self.revisions[-1:])