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, u2hg(os.path.join(self.repo_path, app.config['CONTENT_DIR']))) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') app.blohg.init_repo(REVISION_DEFAULT) client = app.test_client() rv = client.get('/') self.assertFalse(b'post/lorem-ipsum' in rv.data) self.assertFalse(b'post/example-post' in rv.data) commands.add(self.ui, self.repo) rv = client.get('/') self.assertFalse(b'post/lorem-ipsum' in rv.data) self.assertFalse(b'post/example-post' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/') self.assertTrue(b'post/lorem-ipsum' in rv.data) self.assertTrue(b'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(b'THIS IS A TEST!' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/about/') self.assertTrue(b'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(b'THIS IS A TEST!' in rv.data) self.assertFalse(b'THIS IS another TEST!' in rv.data) commands.commit(self.ui, self.repo, message=b'foo', user=b'foo') rv = client.get('/about/') self.assertTrue(b'THIS IS A TEST!' in rv.data) self.assertTrue(b'THIS IS another TEST!' in rv.data)
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='******') 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='******') 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='******') 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='******') rv = client.get('/about/') self.assertTrue('THIS IS A TEST!' in rv.data) self.assertTrue('THIS IS another TEST!' in rv.data)
def forget(parent, ui, repo, files): commands.forget(ui, repo, *files) return True
def add_latest_rev_and_toolshed(repo, **kwargs): """ Iterating over all, but the ignored mercurial files. If a file is called tool_dependencies.xml or repository_dependencies.xml we check if 'changeset_revision' and/or 'toolshed' is not set or empty and insert the latest revision of the corresponding repo (repo-name/owner/tooshed). The default tool_shed url is hardcoded and can be changed. This hook creates a backup of the original file, replaces revision number and toolshed and commit the adopted changes. To restore the backup files use the additional script (toolshed_pretxncommit_hook.py) as pretxncommit-hook. Add the following to your .hgrc: [hooks] pre-commit = python:.hg/toolshed_pre-commit_hook.py:add_latest_rev_and_toolshed """ toolshed_url = "http://testtoolshed.g2.bx.psu.edu/" # to force a commit the user can add a temporary file called: force_pre-commit_hook_temp_file # we will forget that file, because it should only force the execution of that function commands.forget( ui.ui(), repo, 'force_pre-commit_hook_temp_file' ) logging.info('Emtering pre-commit Hook: Updating "toolshed" and/or "changeset_revision" attribute.') filename_categories = repo.status( clean=True ) filepaths = [item for sublist in filename_categories for item in sublist] backup_files = list() for filepath in filepaths: if os.path.split( filepath )[-1] in ['tool_dependencies.xml', 'repository_dependencies.xml']: tree = ET.parse( filepath, parser = CommentedTreeBuilder() ) root = tree.getroot() change = False for repo_dep in root.iter('repository'): if repo_dep.attrib.get('changeset_revision', '') == '': logging.info('Change *changeset_revision* of [%s]\n in file: %s\n and repository: %s' % ('%s :: %s' % (repo_dep.attrib['owner'], repo_dep.attrib['name']), filepath, repo.url())) tip = get_latest_repo_rev( '%srepos/%s/%s' % (toolshed_url, repo_dep.attrib['owner'], repo_dep.attrib['name']) ) repo_dep.attrib.update({'changeset_revision': "%s" % tip}) change = True if repo_dep.attrib.get('toolshed', '') == '': logging.info('Change *toolshed* of [%s]\n in file: %s\n and repository: %s' % ('%s :: %s' % (repo_dep.attrib['owner'], repo_dep.attrib['name']), filepath, repo.url())) repo_dep.attrib.update({'toolshed': "http://testtoolshed.g2.bx.psu.edu/"}) change = True if change: backup_filepath = '%s.pre-commit-backup' % filepath backup_files.append( backup_filepath ) shutil.move( filepath, backup_filepath ) tree.write( filepath, xml_declaration=True, encoding='utf-8' ) logging.info('Add %s to repository: %s' % (filepath, repo.url())) commands.add( ui.ui(), repo, filepath ) # check if there is anything to commit if not [diff for diff in patch.diff(repo)]: logging.info( 'Nothing to commit for repository: %s.' % repo.url() ) # if nothing to commit, restore the original files # these is necessary because I could not find a 'nothing to commit'-hook for backup_file in backup_files: if os.path.split( backup_file )[-1] in ['tool_dependencies.xml.pre-commit-backup', 'repository_dependencies.xml.pre-commit-backup']: ori_filepath = backup_file.replace('.pre-commit-backup', '') if os.path.split( ori_filepath )[-1] in ['tool_dependencies.xml', 'repository_dependencies.xml']: os.remove( ori_filepath ) shutil.move( backup_file, ori_filepath ) # abort the commit, because nothing is to commit sys.exit(1)
def add_latest_rev_and_toolshed(repo, **kwargs): """ Iterating over all, but the ignored mercurial files. If a file is called tool_dependencies.xml or repository_dependencies.xml we check if 'changeset_revision' and/or 'toolshed' is not set or empty and insert the latest revision of the corresponding repo (repo-name/owner/tooshed). The default tool_shed url is hardcoded and can be changed. This hook creates a backup of the original file, replaces revision number and toolshed and commit the adopted changes. To restore the backup files use the additional script (toolshed_pretxncommit_hook.py) as pretxncommit-hook. Add the following to your .hgrc: [hooks] pre-commit = python:.hg/toolshed_pre-commit_hook.py:add_latest_rev_and_toolshed """ toolshed_url = "http://testtoolshed.g2.bx.psu.edu/" # to force a commit the user can add a temporary file called: force_pre-commit_hook_temp_file # we will forget that file, because it should only force the execution of that function commands.forget(ui.ui(), repo, 'force_pre-commit_hook_temp_file') logging.info( 'Emtering pre-commit Hook: Updating "toolshed" and/or "changeset_revision" attribute.' ) filename_categories = repo.status(clean=True) filepaths = [item for sublist in filename_categories for item in sublist] backup_files = list() for filepath in filepaths: if os.path.split(filepath)[-1] in [ 'tool_dependencies.xml', 'repository_dependencies.xml' ]: tree = ET.parse(filepath, parser=CommentedTreeBuilder()) root = tree.getroot() change = False for repo_dep in root.iter('repository'): if repo_dep.attrib.get('changeset_revision', '') == '': logging.info( 'Change *changeset_revision* of [%s]\n in file: %s\n and repository: %s' % ('%s :: %s' % (repo_dep.attrib['owner'], repo_dep.attrib['name']), filepath, repo.url())) tip = get_latest_repo_rev( '%srepos/%s/%s' % (toolshed_url, repo_dep.attrib['owner'], repo_dep.attrib['name'])) repo_dep.attrib.update({'changeset_revision': "%s" % tip}) change = True if repo_dep.attrib.get('toolshed', '') == '': logging.info( 'Change *toolshed* of [%s]\n in file: %s\n and repository: %s' % ('%s :: %s' % (repo_dep.attrib['owner'], repo_dep.attrib['name']), filepath, repo.url())) repo_dep.attrib.update( {'toolshed': "http://testtoolshed.g2.bx.psu.edu/"}) change = True if change: backup_filepath = '%s.pre-commit-backup' % filepath backup_files.append(backup_filepath) shutil.move(filepath, backup_filepath) tree.write(filepath, xml_declaration=True, encoding='utf-8') logging.info('Add %s to repository: %s' % (filepath, repo.url())) commands.add(ui.ui(), repo, filepath) # check if there is anything to commit if not [diff for diff in patch.diff(repo)]: logging.info('Nothing to commit for repository: %s.' % repo.url()) # if nothing to commit, restore the original files # these is necessary because I could not find a 'nothing to commit'-hook for backup_file in backup_files: if os.path.split(backup_file)[-1] in [ 'tool_dependencies.xml.pre-commit-backup', 'repository_dependencies.xml.pre-commit-backup' ]: ori_filepath = backup_file.replace('.pre-commit-backup', '') if os.path.split(ori_filepath)[-1] in [ 'tool_dependencies.xml', 'repository_dependencies.xml' ]: os.remove(ori_filepath) shutil.move(backup_file, ori_filepath) # abort the commit, because nothing is to commit sys.exit(1)
def hg_forget(self, files): wfiles = [self.stat.repo.wjoin(x) for x in files] commands.forget(self.stat.ui, self.stat.repo, *wfiles) self.stat.reload_status()