本文整理汇总了Python中mercurial.commands.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit_multi
def commit_multi(proj, asset, filenames, text, username=None):
"""Commit multiple files to the repository and returns the revision id."""
repo_path = os.path.join(G.REPOSITORY, proj)
repo = repo_get(proj)
if not isinstance(filenames, list):
raise SPAMRepoError('expected a list of files for asset %s' % asset.id)
text = 'asset %s - %s' % (asset.id, text)
encodedtext = text.encode('utf-8')
target_sequence_path = asset.path.replace('#', '%04d')
targets = []
for i, filename in enumerate(filenames):
n = i + 1
uploadedfile = os.path.join(G.UPLOAD, filename)
target_path = (target_sequence_path % n).encode()
target_repo_path = os.path.join(repo_path, target_path)
if not os.path.exists(os.path.dirname(target_repo_path)):
os.makedirs(os.path.dirname(target_repo_path))
shutil.move(uploadedfile, target_repo_path)
if not target_path in repo['tip']:
commands.add(repo_ui, repo, target_repo_path)
targets.append(target_path)
matched = match.exact(repo.root, repo.getcwd(), targets)
commit_id = repo.commit(encodedtext, user=username, match=matched)
if commit_id:
return repo[commit_id].hex()
else:
return None
示例2: test_branch
def test_branch(self):
''' Test 'clone --branch' '''
ui = self.ui()
_dispatch(ui, ['init', self.wc_path])
repo = self.repo
repo.ui.setconfig('ui', 'username', 'anonymous')
fpath = os.path.join(self.wc_path, 'it')
f = file(fpath, 'w')
f.write('C1')
f.flush()
commands.add(ui, repo)
commands.branch(ui, repo, label="B1")
commands.commit(ui, repo, message="C1")
f.write('C2')
f.flush()
commands.branch(ui, repo, label="default")
commands.commit(ui, repo, message="C2")
f.write('C3')
f.flush()
commands.branch(ui, repo, label="B2")
commands.commit(ui, repo, message="C3")
self.assertEqual(len(repo), 3)
branch = 'B1'
_dispatch(ui, ['clone', self.wc_path, self.wc_path + '2',
'--branch', branch])
repo2 = hg.repository(ui, self.wc_path + '2')
self.assertEqual(repo[branch].hex(), repo2['.'].hex())
示例3: endWrite
def endWrite(self, withErrors):
"""Called when PUT has finished writing.
See DAVResource.endWrite()
"""
if not withErrors:
commands.add(self.provider.ui, self.provider.repo, self.localHgPath)
示例4: test_reload_changectx_working_dir
def test_reload_changectx_working_dir(self):
app = create_app(repo_path=self.repo_path,
revision_id=REVISION_WORKING_DIR)
client = app.test_client()
rv = client.get('/')
self.assertTrue('post/lorem-ipsum' in rv.data)
self.assertTrue('post/example-post' in rv.data)
commands.add(self.ui, self.repo)
rv = client.get('/')
self.assertTrue('post/lorem-ipsum' in rv.data)
self.assertTrue('post/example-post' in rv.data)
commands.commit(self.ui, self.repo, message='foo', user='foo')
rv = client.get('/')
self.assertTrue('post/lorem-ipsum' in rv.data)
self.assertTrue('post/example-post' in rv.data)
with codecs.open(os.path.join(self.repo_path,
app.config['CONTENT_DIR'], 'about.rst'),
'a', encoding='utf-8') as fp:
fp.write('\n\nTHIS IS A TEST!\n')
rv = client.get('/about/')
self.assertTrue('THIS IS A TEST!' in rv.data)
commands.commit(self.ui, self.repo, message='foo', user='foo')
rv = client.get('/about/')
self.assertTrue('THIS IS A TEST!' in rv.data)
with codecs.open(os.path.join(self.repo_path,
app.config['CONTENT_DIR'], 'about.rst'),
'a', encoding='utf-8') as fp:
fp.write('\n\nTHIS IS another TEST!\n')
rv = client.get('/about/')
self.assertTrue('THIS IS another TEST!' in rv.data)
commands.commit(self.ui, self.repo, message='foo', user='foo')
rv = client.get('/about/')
self.assertTrue('THIS IS another TEST!' in rv.data)
示例5: test_update
def test_update(self):
''' Test 'clone --updaterev' '''
ui = self.ui()
_dispatch(ui, ['init', self.wc_path])
repo = self.repo
repo.ui.setconfig('ui', 'username', 'anonymous')
fpath = os.path.join(self.wc_path, 'it')
f = file(fpath, 'w')
f.write('C1')
f.flush()
commands.add(ui, repo)
commands.commit(ui, repo, message="C1")
f.write('C2')
f.flush()
commands.commit(ui, repo, message="C2")
f.write('C3')
f.flush()
commands.commit(ui, repo, message="C3")
self.assertEqual(len(repo), 3)
updaterev = 1
_dispatch(ui, ['clone', self.wc_path, self.wc_path + '2',
'--updaterev=%s' % updaterev])
repo2 = hg.repository(ui, self.wc_path + '2')
self.assertEqual(str(repo[updaterev]), str(repo2['.']))
示例6: create_test_changesets
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='Test Runner <[email protected]>')
示例7: hg_add
def hg_add(self, single=None):
"""Adds all files to Mercurial when the --watch options is passed
This only happens one time. All consequent files are not auto added
to the watch list."""
repo = hg.repository(ui.ui(), self.path)
if single is None:
commands.add(ui.ui(), repo=repo)
hg_log.debug('added files to repo %s' % self.path)
else:
commands.add(ui.ui(), repo, single)
hg_log.debug('added files to repo %s' % self.path)
示例8: commit_results
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)
示例9: createCollection
def createCollection(self, name):
"""Create a new collection as member of self.
A dummy member is created, because Mercurial doesn't handle folders.
"""
assert self.isCollection
self._checkWriteAccess()
collpath = self._getFilePath(name)
os.mkdir(collpath)
filepath = self._getFilePath(name, ".directory")
f = open(filepath, "w")
f.write("Created by WsgiDAV.")
f.close()
commands.add(self.provider.ui, self.provider.repo, filepath)
示例10: setUp
def setUp(self):
self.repo_path = mkdtemp()
self.ui = ui.ui()
self.ui.setconfig('ui', 'username', 'foo <[email protected]>')
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='foo')
示例11: createEmptyResource
def createEmptyResource(self, name):
"""Create and return an empty (length-0) resource as member of self.
See DAVResource.createEmptyResource()
"""
assert self.isCollection
self._checkWriteAccess()
filepath = self._getFilePath(name)
f = open(filepath, "w")
f.close()
commands.add(self.provider.ui, self.provider.repo, filepath)
# getResourceInst() won't work, because the cached manifest is outdated
# return self.provider.getResourceInst(self.path.rstrip("/")+"/"+name, self.environ)
return HgResource(self.path.rstrip("/")+"/"+name, False,
self.environ, self.rev, self.localHgPath+"/"+name)
示例12: test_reload_changectx_default
def test_reload_changectx_default(self):
app = create_app(repo_path=self.repo_path, autoinit=False)
commands.add(self.ui, self.repo)
commands.forget(self.ui, self.repo,
os.path.join(self.repo_path,
app.config['CONTENT_DIR']))
commands.commit(self.ui, self.repo, message='foo', user='foo')
app.blohg.init_repo(REVISION_DEFAULT)
client = app.test_client()
rv = client.get('/')
self.assertFalse('post/lorem-ipsum' in rv.data)
self.assertFalse('post/example-post' in rv.data)
commands.add(self.ui, self.repo)
rv = client.get('/')
self.assertFalse('post/lorem-ipsum' in rv.data)
self.assertFalse('post/example-post' in rv.data)
commands.commit(self.ui, self.repo, message='foo', user='foo')
rv = client.get('/')
self.assertTrue('post/lorem-ipsum' in rv.data)
self.assertTrue('post/example-post' in rv.data)
with codecs.open(os.path.join(self.repo_path,
app.config['CONTENT_DIR'],
'about.rst'),
'a', encoding='utf-8') as fp:
fp.write('\n\nTHIS IS A TEST!\n')
rv = client.get('/about/')
self.assertFalse('THIS IS A TEST!' in rv.data)
commands.commit(self.ui, self.repo, message='foo', user='foo')
rv = client.get('/about/')
self.assertTrue('THIS IS A TEST!' in rv.data)
with codecs.open(os.path.join(self.repo_path,
app.config['CONTENT_DIR'],
'about.rst'),
'a', encoding='utf-8') as fp:
fp.write('\n\nTHIS IS another TEST!\n')
rv = client.get('/about/')
self.assertTrue('THIS IS A TEST!' in rv.data)
self.assertFalse('THIS IS another TEST!' in rv.data)
commands.commit(self.ui, self.repo, message='foo', user='foo')
rv = client.get('/about/')
self.assertTrue('THIS IS A TEST!' in rv.data)
self.assertTrue('THIS IS another TEST!' in rv.data)
示例13: repo_init
def repo_init(proj):
"""Init a new mercurial repository for ``proj``."""
repo_path = os.path.join(G.REPOSITORY, proj)
try:
repo = repo_get(proj)
except SPAMRepoNotFound:
commands.init(repo_ui, repo_path)
repo = repo_get(proj)
hgignore_path = os.path.join(G.REPOSITORY, proj, '.hgignore')
if not os.path.exists(hgignore_path):
hgignore = open(hgignore_path, 'w')
hgignore.write('syntax: regexp\n')
hgignore.write('^.previews/')
hgignore.close()
if not '.hgignore' in repo['tip']:
commands.add(repo_ui, repo, hgignore_path)
matched = match.exact(repo.root, repo.getcwd(), ['.hgignore'])
commit_id = repo.commit('add .hgignore', user='system', match=matched)
示例14: add_file
def add_file(self, path):
if self.vcs_type == 'git':
# git wants a relative path
path = path[len(self.path) + 1:]
self.r.stage(path.encode('utf-8'))
# FIXME: does not work if there was an
# issue with other uncommitted things
self.r.do_commit(
message='commit {0}'.format(path.encode('utf-8')))
elif self.vcs_type == 'hg':
#_lock = self.r.lock()
print '=' * 35
print self.r.root
print path
print '=' * 35
hg.add(self.ui, self.r, path.encode('utf-8'))
hg.commit(
self.ui,
self.r,
path.encode('utf-8'),
message='commit {0}'.format(path))
示例15: writeIgnoreFile
def writeIgnoreFile(self):
eol = self.doseoln and '\r\n' or '\n'
out = eol.join(self.ignorelines) + eol
hasignore = os.path.exists(self.repo.join(self.ignorefile))
try:
f = util.atomictempfile(self.ignorefile, 'wb', createmode=None)
f.write(out)
f.close()
if not hasignore:
ret = qtlib.QuestionMsgBox(_('New file created'),
_('TortoiseHg has created a new '
'.hgignore file. Would you like to '
'add this file to the source code '
'control repository?'), parent=self)
if ret:
commands.add(ui.ui(), self.repo, self.ignorefile)
shlib.shell_notify([self.ignorefile])
self.ignoreFilterUpdated.emit()
except EnvironmentError, e:
qtlib.WarningMsgBox(_('Unable to write .hgignore file'),
hglib.tounicode(str(e)), parent=self)