def assert_new_commit(self):
     from gitpy import LocalRepository
     from os import curdir
     repository = LocalRepository(curdir)
     head = repository.getHead().hash
     yield
     self.assertNotEquals(head, repository.getHead().hash)
def assert_no_uncommitted_changes():
    repository = LocalRepository(curdir)
    changes = repository.getChangedFiles() + repository.getStagedFiles()
    if changes:
        message = "There are changes pending commit, cannot continue. please commit or checkout those changes:\n"
        logger.error(message+repr(changes))
        raise AssertionError()
 def assert_new_commit(self):
     from gitpy import LocalRepository
     from os import curdir
     repository = LocalRepository(curdir)
     head = repository.getHead().hash
     yield
     self.assertNotEquals(head, repository.getHead().hash)
示例#4
0
def assert_develop_branch_on_top_of_master():
    repository = LocalRepository(curdir)
    develop = repository.getBranchByName("develop")
    master = repository.getBranchByName("master")
    if develop.getMergeBase(master) != master:
        logger.error("{} is not on top of {}, please rebase".format(develop, master))
        raise SystemExit(1)
示例#5
0
def assert_no_uncommitted_changes():
    repository = LocalRepository(curdir)
    changes = repository.getChangedFiles() + repository.getStagedFiles()
    if changes:
        message = "There are changes pending commit, cannot continue. please commit or stash them:\n"
        logger.error(message + repr(changes))
        raise SystemExit(1)
    def test_add_and_remove(self, development_flag, package_name):
        from infi.projector.plugins.builtins.requirements import RequirementsPlugin
        from gitpy import LocalRepository
        from os import curdir

        plugin = RequirementsPlugin()
        plugin.arguments = {"--development": development_flag}
        with self.temporary_directory_context():
            self.projector("repository init a.b.c none short long")
            repository = LocalRepository(".")
            self.assertTrue(repository.isWorkingDirectoryClean())
            self.projector(
                "requirements add {} {} --commit-changes".format(
                    package_name, "--development" if development_flag else ""
                )
            )
            self.assertTrue(repository.isWorkingDirectoryClean())
            self.assertTrue(package_name in plugin.get_package_set().get())
            self.projector(
                "requirements remove {} {} --commit-changes".format(
                    package_name, "--development" if development_flag else ""
                )
            )
            self.assertTrue(repository.isWorkingDirectoryClean())
            self.assertFalse(package_name in plugin.get_package_set().get())
def assert_no_uncommitted_changes():
    repository = LocalRepository(curdir)
    changes = repository.getChangedFiles() + repository.getStagedFiles()
    if changes:
        message = "There are changes pending commit, cannot continue. please commit or checkout those changes:\n"
        logger.error(message + repr(changes))
        raise AssertionError()
示例#8
0
def assert_no_uncommitted_changes():
    repository = LocalRepository(curdir)
    changes = repository.getChangedFiles() + repository.getStagedFiles()
    if changes:
        message = "There are changes pending commit, cannot continue. please commit or stash them:\n"
        logger.error(message+repr(changes))
        raise SystemExit(1)
示例#9
0
def assert_develop_branch_on_top_of_master():
    repository = LocalRepository(curdir)
    develop = repository.getBranchByName("develop")
    master = repository.getBranchByName("master")
    if develop.getMergeBase(master) != master:
        logger.error("{} is not on top of {}, please rebase".format(develop, master))
        raise SystemExit(1)
示例#10
0
 def _apply_close_on_upgrade_or_removal(self, value):
     from gitpy import LocalRepository
     from infi.recipe.application_packager.utils.buildout import open_buildout_configfile
     with open_buildout_configfile(write_on_exit=True) as buildout:
         buildout.set("pack", "close-on-upgrade-or-removal", value)
     repository = LocalRepository('.')
     repository.add('buildout.cfg')
     repository.commit('HOSTDEV-1922 testing close-on-upgrade-or-removal={}'.format(value))
示例#11
0
 def test_release__not_on_develop_branch(self):
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts")
         repository = LocalRepository(curdir)
         repository.checkout("master")
         with self.assertRaises(SystemExit):
             self.projector("version release 1.2.3 --no-fetch --no-upload --no-push-changes")
 def test_release__not_on_develop_branch(self):
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts")
         repository = LocalRepository(curdir)
         repository.checkout("master")
         with self.assertRaises(SystemExit):
             self.projector("version release 1.2.3 --no-fetch --no-upload --no-push-changes")
示例#13
0
def get_latest_version():
    from os import curdir
    from gitpy import LocalRepository
    from pkg_resources import parse_version
    repository = LocalRepository(curdir)
    version_tags = [tag.name for tag in repository.getTags()
                    if tag.name.startswith('v') and not tag.name.endswith('-develop')]
    version_tags.sort(key=lambda ver: parse_version(ver))
    return version_tags[-1]
示例#14
0
def assert_develop_and_master_not_behind_origin():
    repository = LocalRepository(curdir)
    branches = [repository.getBranchByName(branch_name) for branch_name in ['master', 'develop']]
    branches_with_remote = [branch for branch in branches if branch.getRemoteBranch() is not None]
    for branch in branches_with_remote:
        remote_branch = branch.getRemoteBranch()
        if branch.getMergeBase(remote_branch) != remote_branch:
            logger.error("local branch {} is not on top of origin, please rebase".format(branch))
            raise SystemExit(1)
示例#15
0
def assert_develop_and_master_not_behind_origin():
    repository = LocalRepository(curdir)
    branches = [repository.getBranchByName(branch_name) for branch_name in ['master', 'develop']]
    branches_with_remote = [branch for branch in branches if branch.getRemoteBranch() is not None]
    for branch in branches_with_remote:
        remote_branch = branch.getRemoteBranch()
        if branch.getMergeBase(remote_branch) != remote_branch:
            logger.error("local branch {} is not on top of origin, please rebase".format(branch))
            raise SystemExit(1)
示例#16
0
def get_latest_version():
    from os import curdir
    from gitpy import LocalRepository
    from pkg_resources import parse_version
    repository = LocalRepository(curdir)
    version_tags = [
        tag.name for tag in repository.getTags()
        if tag.name.startswith('v') and not tag.name.endswith('-develop')
    ]
    version_tags.sort(key=lambda ver: parse_version(ver))
    return version_tags[-1]
示例#17
0
 def fetch_origin(self):
     from gitpy import LocalRepository
     from gitpy.exceptions import GitCommandFailedException
     from os import curdir
     repository = LocalRepository(curdir)
     try:
         repository.fetch()
     except (TypeError, GitCommandFailedException), error:
         logger.error("Failed to fetch origin: {}".format(getattr(error, 'msg', error.message)))
         logger.info("Either fix this or run with --no-fetch")
         raise SystemExit(1)
示例#18
0
 def fetch_origin(self):
     from gitpy import LocalRepository
     from gitpy.exceptions import GitCommandFailedException
     from os import curdir
     repository = LocalRepository(curdir)
     try:
         repository.fetch()
     except (TypeError, GitCommandFailedException) as error:
         logger.error("Failed to fetch origin: {}".format(getattr(error, 'msg', error.message)))
         logger.info("Either fix this or run with --no-fetch")
         raise SystemExit(1)
示例#19
0
 def testCloneModifyPush(self):
     new_repo = LocalRepository(utils.get_temporary_location())        
     new_repo.clone(self.repo)
     #checkout a different branch to comply with git 1.7.0
     prev_branch = self.repo.getCurrentBranch()
     self.repo.checkout(self.repo.createBranch('temp'))        
     self.assertReposEqual(self.repo, new_repo)
     utils.commit_change(new_repo)
     new_repo.push()
     self.repo.checkout(prev_branch)        
     self.assertReposEqual(self.repo, new_repo)        
     utils.delete_repository(new_repo)
示例#20
0
def _get_issue_key_and_message_from_commit(commit_string):
    from gitpy import LocalRepository
    from json import dumps
    git = LocalRepository(".")
    commit = git._getCommitByPartialHash(commit_string)
    describe = git._getOutputAssertSuccess("git describe --tags {0}".format(commit.name)).strip()
    subject = '{0} '.format(commit.getSubject())
    key, message = subject.split(' ', 1)
    body = commit.getMessageBody()
    template = """\nresolved in commit:\n{{noformat}}\n{}\n{{noformat}}"""
    value = dict(hash=commit.name, describe=describe, summary=message, body=body)
    return key, template.format(dumps(value, indent=True))
示例#21
0
 def setUp(self):
     path1 = utils.get_temporary_location()
     path2 = utils.get_temporary_location()
     path2 = os.path.join(path2, "repo")
     self.repo1 = LocalRepository(path1)
     self.repo1.init()
     for i in range(10):
         with open(os.path.join(self.repo1.path, "file_%s.txt" % i), "wb") as output:
             print >>output, "This is file", i
     self.repo1.addAll()
     self.repo1.commit(message="init")
     self.repo2 = LocalRepository(path2)
     self.repo2.clone(self.repo1)
     self.assertTrue(os.path.isdir(self.repo2.path))
 def test_add_and_remove(self, package_name):
     from infi.projector.plugins.builtins.js_requirements import JSRequirementsPlugin
     from gitpy import LocalRepository
     plugin = JSRequirementsPlugin()
     with self.temporary_directory_context() as dir_path:
         self.projector("repository init a.b.c none short long")
         repository = LocalRepository(dir_path)
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.projector("js-requirements add {} --commit-changes".format(package_name))
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.assertTrue(package_name in plugin.get_package_set().get())
         self.projector("js-requirements remove {} --commit-changes".format(package_name))
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.assertFalse(package_name in plugin.get_package_set().get())
示例#23
0
 def test_add_and_remove(self, package_name):
     from infi.projector.plugins.builtins.js_requirements import JSRequirementsPlugin
     from gitpy import LocalRepository
     plugin = JSRequirementsPlugin()
     with self.temporary_directory_context() as dir_path:
         self.projector("repository init a.b.c none short long")
         repository = LocalRepository(dir_path)
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.projector(
             "js-requirements add {} --commit-changes".format(package_name))
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.assertTrue(package_name in plugin.get_package_set().get())
         self.projector("js-requirements remove {} --commit-changes".format(
             package_name))
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.assertFalse(package_name in plugin.get_package_set().get())
 def test_local_behind_origin__no_fetch(self):
     from os import curdir
     from os.path import abspath, basename
     from infi.projector.helper.utils import chdir
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts")
         origin = abspath(curdir)
         with self.temporary_directory_context():
             self.projector("repository clone {}".format(origin))
             with chdir(basename(origin)):
                 self.projector("devenv build --no-scripts")
                 with chdir(origin):
                     repository = LocalRepository(curdir)
                     repository.checkout("master")
                     repository.commit("empty commit", allowEmpty=True)
                 self.projector("version release 1.2.3 --no-fetch --no-upload  --no-push-changes")
示例#25
0
def revert_if_failed(keep_leftovers):
    from gitpy import LocalRepository
    from os import curdir
    repository = LocalRepository(curdir)
    ops = RevertIfFailedOperations(repository)
    before = ops.get_status()
    try:
        yield
    except:
        if keep_leftovers:
            raise
        repository.checkout('develop')
        now = ops.get_status()
        ops.delete_new_tags(before, now)
        ops.delete_new_branches(before, now)
        ops.reset_master_and_develop(before, now)
        raise
示例#26
0
def revert_if_failed(keep_leftovers):
    from gitpy import LocalRepository
    from os import curdir
    repository = LocalRepository(curdir)
    ops = RevertIfFailedOperations(repository)
    before = ops.get_status()
    try:
        yield
    except:
        if keep_leftovers:
            raise
        repository.checkout('develop')
        now = ops.get_status()
        ops.delete_new_tags(before, now)
        ops.delete_new_branches(before, now)
        ops.reset_master_and_develop(before, now)
        raise
示例#27
0
 def test_release__master_diverged(self):
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts")
         repository = LocalRepository(curdir)
         repository.checkout("master")
         repository.commit("empty commit", allowEmpty=True)
         repository.checkout("develop")
         with self.assertRaises(SystemExit):
             self.projector("version release 1.2.3 --no-fetch --no-upload --no-push-changes")
示例#28
0
文件: test_basic.py 项目: tepas/gitpy
class EmptyRepositoryTest(unittest.TestCase):
    def setUp(self):
        self.dirname = get_temporary_location()
        self.repo = LocalRepository(self.dirname)
        self.assertFalse(os.path.exists(self.dirname))
        self.assertFalse(self.repo.isValid())
    def tearDown(self):
        if os.path.exists(self.dirname):
            delete_repository(self.repo)
示例#29
0
def git_checkout(branch_name_or_tag):
    from os import curdir
    from gitpy import LocalRepository
    logger.info("checking out '{}'".format(branch_name_or_tag))
    try:
        LocalRepository(curdir).checkout(branch_name_or_tag)
    except Exception:  # pragma: no cover
        logger.error("failed to checkout {}".format(branch_name_or_tag))
        raise SystemExit(1)
 def test_add_and_remove(self, development_flag, package_name):
     from infi.projector.plugins.builtins.requirements import RequirementsPlugin
     from gitpy import LocalRepository
     from os import curdir
     plugin = RequirementsPlugin()
     plugin.arguments = {'--development': development_flag}
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         repository = LocalRepository('.')
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.projector("requirements add {} {} --commit-changes".format(
             package_name, '--development' if development_flag else ''))
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.assertTrue(package_name in plugin.get_package_set().get())
         self.projector("requirements remove {} {} --commit-changes".format(
             package_name, '--development' if development_flag else ''))
         self.assertTrue(repository.isWorkingDirectoryClean())
         self.assertFalse(package_name in plugin.get_package_set().get())
示例#31
0
 def unfreeze(self):
     from infi.projector.helper.utils import unfreeze_versions
     from gitpy import LocalRepository
     from os import curdir
     unfreeze_versions(self.arguments.get("--with-install-requires", False))
     if self.arguments.get("--commit-changes", False):
         repository = LocalRepository(curdir)
         repository.add("buildout.cfg")
         repository.commit("Unfreezing dependencies")
     push_changes = self.arguments.get("--push-changes", False)
     if push_changes:
         repository._executeGitCommandAssertSuccess("git push")
示例#32
0
 def test_revert_if_failed(self):
     from infi.projector.helper.utils import revert_if_failed
     from gitpy import LocalRepository
     from os import curdir
     class Messup(Exception):
         pass
     def mess_things_up_and_raise():
         repository = LocalRepository('.')
         repository.commit("message", allowEmpty=True)
         repository.createTag("test-tag")
         repository.createBranch("new-branch")
         raise Messup()
     with self.temporary_directory_context():
         self.projector("repository init test None a b")
         with self.assertRaises(Messup):
             with revert_if_failed(False):
                 mess_things_up_and_raise()
         repository = LocalRepository('.')
         self.assertEquals(2, len(repository.getBranches()))
         self.assertEquals(1, len(repository.getTags()), repository.getTags())
 def test_local_behind_origin(self):
     from os import curdir
     from os.path import abspath, basename
     from infi.projector.helper.utils import chdir
     if is_windows:
         raise SkipTest("skipping test on windows")
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts --no-readline")
         origin = abspath(curdir)
         with self.temporary_directory_context():
             self.projector("repository clone {}".format(origin))
             with chdir(basename(origin)):
                 self.projector("devenv build --no-scripts --no-readline")
                 with chdir(origin):
                     repository = LocalRepository(curdir)
                     repository.checkout("master")
                     repository.commit("empty commit", allowEmpty=True)
                 with self.assertRaises(SystemExit):
                     self.projector("version release 1.2.3 --no-upload --no-push-changes")
示例#34
0
 def extract_version_tag_from_git():
     from gitpy import LocalRepository
     from os import curdir, path
     repository = LocalRepository(curdir)
     branch = repository.getCurrentBranch()
     head = repository.getHead()
     if branch is None:
         return get_commit_describe(head)
     current_branch = branch.name
     stripped_branch = current_branch.split('/')[0]
     if stripped_branch in ('release', 'support', 'hotfix'):
         return get_commit_describe(head)
     if 'master' in stripped_branch:
         return get_commit_describe(head)
     else:
         try:
             return get_commit_describe(head, 'v*')
         except:
             pass
         return get_commit_describe(head)
     pass
 def test_release__master_diverged(self):
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts")
         repository = LocalRepository(curdir)
         repository.checkout("master")
         repository.commit("empty commit", allowEmpty=True)
         repository.checkout("develop")
         with self.assertRaises(SystemExit):
             self.projector("version release 1.2.3 --no-fetch --no-upload --no-push-changes")
示例#36
0
文件: utils.py 项目: tepas/gitpy
def create_repo():
    returned = LocalRepository(get_temporary_location())
    returned.init()
    for i in range(10):
        filename = "file_%s.txt" % i
        full_filename = os.path.join(returned.path, filename)
        with open(full_filename, "wb") as f:
            print >>f, "initial content"
        returned.add(filename)
    returned.commit(message="initial")
    return returned
示例#37
0
def commit_changes_to_buildout(message):
    from os import curdir
    from gitpy import LocalRepository
    repository = LocalRepository(curdir)
    if "buildout.cfg" not in [modified_file.filename for modified_file in repository.getChangedFiles()]:
        return
    repository.add("buildout.cfg")
    repository.commit("buildout.cfg: " + message)
示例#38
0
 def unfreeze(self):
     from infi.projector.helper.utils import unfreeze_versions
     from gitpy import LocalRepository
     from os import curdir
     versions = unfreeze_versions(self.arguments.get("--with-install-requires", False))
     if self.arguments.get("--commit-changes", False):
         repository = LocalRepository(curdir)
         repository.add("buildout.cfg")
         repository.commit("Unfreezing dependencies")
     push_changes = self.arguments.get("--push-changes", False)
     if push_changes:
         repository._executeGitCommandAssertSuccess("git push")
示例#39
0
def _release_version_with_git_flow(version_tag):
    from os import curdir
    from gitflow.core import GitFlow
    from gitpy import LocalRepository
    gitflow = GitFlow()
    gitflow.create("release", version_tag, base=None, fetch=False)
    gitflow.finish("release",
                   version_tag,
                   fetch=False,
                   rebase=False,
                   keep=False,
                   force_delete=True,
                   tagging_info=dict(sign=False, message=version_tag))
    repository = LocalRepository(curdir)
示例#40
0
def commit_changes_to_buildout(message):
    import os
    from gitpy import LocalRepository
    repository = LocalRepository(os.curdir)
    # workaround https://github.com/msysgit/git/issues/79
    os.system("git status")
    if "buildout.cfg" not in [
            modified_file.filename
            for modified_file in repository.getChangedFiles()
    ]:
        return
    repository.add("buildout.cfg")
    repository.commit("buildout.cfg: " + message)
示例#41
0
    def test_revert_if_failed(self):
        from infi.projector.helper.utils import revert_if_failed
        from gitpy import LocalRepository
        from os import curdir

        class Messup(Exception):
            pass

        def mess_things_up_and_raise():
            repository = LocalRepository('.')
            repository.commit("message", allowEmpty=True)
            repository.createTag("test-tag")
            repository.createBranch("new-branch")
            raise Messup()

        with self.temporary_directory_context():
            self.projector("repository init test None a b")
            with self.assertRaises(Messup):
                with revert_if_failed(False):
                    mess_things_up_and_raise()
            repository = LocalRepository('.')
            self.assertEquals(2, len(repository.getBranches()))
            self.assertEquals(1, len(repository.getTags()),
                              repository.getTags())
示例#42
0
def do_a_refactoring_change():
    # HOSTDEV-1781
    from gitpy import LocalRepository
    from os import rename
    scripts_dir = os.path.join("src", "infi", "recipe", "application_packager",
                               "scripts")
    refactoring_dir = os.path.join(scripts_dir, "refactoring")
    scripts_init = os.path.join(scripts_dir, "__init__.py")
    refactoring_py = "{}.py".format(refactoring_dir)
    if not os.path.exists(refactoring_dir):
        return
    # move the file
    rename(os.path.join(refactoring_dir, "__init__.py"), refactoring_py)

    # change the files
    apply_change_in_file(refactoring_py)
    apply_change_in_file(scripts_init)

    # commit the changes
    repository = LocalRepository('.')
    repository.delete(refactoring_dir, recursive=True, force=True)
    repository.add(refactoring_py)
    repository.add(scripts_init)
    repository.commit("HOSTDEV-1781 refactoring scripts/refactoring")
示例#43
0
 def build_and_upload_distributions(self, version_tag_with_v):
     from infi.projector.helper.utils import execute_with_buildout, git_checkout
     from infi.projector.plugins.builtins.devenv import DevEnvPlugin
     from infi.projector.scripts import projector
     from gitpy import LocalRepository
     from os import curdir
     repository = LocalRepository(curdir)
     for distribution in self.arguments.get("--distributions").split(','):
         for pypi in self.arguments.get("--pypi-servers").split(','):
             git_checkout(version_tag_with_v)
             DevEnvPlugin().create_setup_py()
             setup_cmd = "setup . register -r {pypi} {distribution} upload -r {pypi}"
             setup_cmd = setup_cmd.format(pypi=pypi,
                                          distribution=distribution)
             execute_with_buildout(setup_cmd)
示例#44
0
def commit_changes_to_buildout(message):
    import os
    from gitpy import LocalRepository
    repository = LocalRepository(os.curdir)
    # workaround https://github.com/msysgit/git/issues/79
    os.system("git status")
    if "buildout.cfg" not in [modified_file.filename for modified_file in repository.getChangedFiles()]:
        return
    repository.add("buildout.cfg")
    repository.commit("buildout.cfg: " + message)
示例#45
0
 def _apply_close_on_upgrade_or_removal(self, value):
     from gitpy import LocalRepository
     from infi.recipe.application_packager.utils.buildout import open_buildout_configfile
     with open_buildout_configfile(write_on_exit=True) as buildout:
         buildout.set("pack", "close-on-upgrade-or-removal", value)
     repository = LocalRepository('.')
     repository.add('buildout.cfg')
     repository.commit(
         'HOSTDEV-1922 testing close-on-upgrade-or-removal={}'.format(
             value))
示例#46
0
 def test_release_with_push(self):
     from infi.projector.helper.utils import chdir
     from os import path, curdir
     from gitpy import LocalRepository
     with self.mock_build_and_upload_distributions():
         with self.temporary_directory_context() as origin_location:
             self.projector("repository init a.b.c none short long")
             self.projector("devenv build --no-scripts")
             self.projector("version release minor --no-fetch --pypi-servers= --no-push-changes")
             git_config = path.join(".git", "config")
             LocalRepository(curdir)._executeGitCommandAssertSuccess("git config -f {} receive.denyCurrentBranch ignore".format(git_config))
             with self.temporary_directory_context():
                 self.projector("repository clone {}".format(origin_location))
                 with chdir(path.basename(origin_location)):
                     self.projector("devenv build --no-scripts")
                     self.projector("version release minor --pypi-servers=")
示例#47
0
    def unfreeze(self):
        from gitpy import LocalRepository
        from os import curdir
        with open_buildout_configfile(write_on_exit=True) as buildout_cfg:
            if not buildout_cfg.has_section('js-requirements'):
                print("Missing js-requirements section")
                return
            buildout_cfg.remove_option("buildout", "js_versions")
            buildout_cfg.remove_section("js_versions")

        # Git operations
        repository = LocalRepository(curdir)
        if self.arguments.get("--commit-changes", False):
            repository.add("buildout.cfg")
            repository.commit("Unfreezing javascript dependencies")
        push_changes = self.arguments.get("--push-changes", False)
        if push_changes:
            repository._executeGitCommandAssertSuccess("git push")
示例#48
0
 def freeze(self):
     from infi.projector.helper.utils import freeze_versions, buildout_parameters_context, open_tempfile
     from infi.projector.plugins.builtins.devenv import DevEnvPlugin
     from gitpy import LocalRepository
     from os import curdir
     from re import sub, findall, MULTILINE
     plugin = DevEnvPlugin()
     plugin.arguments = {
         '--newest': self.arguments.get("--newest", False),
         '--use-isolated-python': True
     }
     with open_tempfile() as tempfile:
         with buildout_parameters_context([
                 "buildout:update-versions-file={0}".format(tempfile),
                 "buildout:versions="
         ]):
             plugin.build()
         with open(tempfile) as fd:
             content = fd.read()
         post_releases = findall(r'^[^#].* = .*\.post.*', content,
                                 MULTILINE)
         if post_releases:
             if self.arguments.get('--allow-post-releases'):
                 pass
             elif self.arguments.get('--strip-suffix-from-post-releases'):
                 content = sub(r'\.post\d+', '', content)
             else:
                 msg = "freeze found the follwing post-releases, see the dependency tree above:\n{}"
                 formatted_post_releases = "\n".join(
                     item for item in post_releases)
                 logger.info(content)
                 logger.error(msg.format(formatted_post_releases))
                 raise SystemExit(1)
         with open(tempfile, 'w') as fd:
             fd.write("[versions]\n" + "\n".join(set(content.splitlines())))
         freeze_versions(
             tempfile, self.arguments.get("--with-install-requires", False))
     if self.arguments.get("--commit-changes", False):
         repository = LocalRepository(curdir)
         repository.add("buildout.cfg")
         repository.commit("Freezing dependencies", allowEmpty=True)
     push_changes = self.arguments.get("--push-changes", False)
     if push_changes:
         repository._executeGitCommandAssertSuccess("git push")
示例#49
0
def do_a_refactoring_change():
    # HOSTDEV-1781
    from gitpy import LocalRepository
    from os import rename
    scripts_dir = os.path.join("src", "infi", "recipe", "application_packager", "scripts")
    refactoring_dir = os.path.join(scripts_dir, "refactoring")
    scripts_init = os.path.join(scripts_dir, "__init__.py")
    refactoring_py = "{}.py".format(refactoring_dir)
    if not os.path.exists(refactoring_dir):
        return
    # move the file
    rename(os.path.join(refactoring_dir, "__init__.py"), refactoring_py)

    # change the files
    apply_change_in_file(refactoring_py)
    apply_change_in_file(scripts_init)

    # commit the changes
    repository = LocalRepository('.')
    repository.delete(refactoring_dir, recursive=True, force=True)
    repository.add(refactoring_py)
    repository.add(scripts_init)
    repository.commit("HOSTDEV-1781 refactoring scripts/refactoring")
示例#50
0
    def freeze(self):
        from gitpy import LocalRepository
        from os import curdir
        import json

        # Read/write the buildout.cfg
        with open_buildout_configfile(write_on_exit=True) as buildout_cfg:
            if not buildout_cfg.has_section('js-requirements'):
                print("Missing js-requirements section")
                return
            packages_path = buildout_cfg.get(
                'js-requirements', 'js-directory') or self.DEFAULT_DIRECTORY
            try:
                with open(os.path.join(packages_path, '.package-lock.json'),
                          'r') as pljson:
                    selected_versions = json.load(pljson)
                    if buildout_cfg.has_section("js_versions"):
                        buildout_cfg.remove_section("js_versions")
                    buildout_cfg.add_section("js_versions")
                for key in sorted(selected_versions.keys(),
                                  key=lambda s: s.lower()):
                    buildout_cfg.set("js_versions", key,
                                     selected_versions[key])
                buildout_cfg.set('buildout', 'js_versions', 'True')
            except IOError as e:
                import errno
                print(str(e))
                if hasattr(e, 'errno') and e.errno == errno.ENOENT:
                    print(
                        '.package-lock.json file is missing, try running projector devenv build to create the file'
                    )

        # Git operations
        repository = LocalRepository(curdir)
        if self.arguments.get("--commit-changes", False):
            repository.add("buildout.cfg")
            repository.commit("Freezing javascript dependencies")
        push_changes = self.arguments.get("--push-changes", False)
        if push_changes:
            repository._executeGitCommandAssertSuccess("git push")
示例#51
0
 def test_local_behind_origin__no_fetch(self):
     from os import curdir
     from os.path import abspath, basename
     from infi.projector.helper.utils import chdir
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts")
         origin = abspath(curdir)
         with self.temporary_directory_context():
             self.projector("repository clone {}".format(origin))
             with chdir(basename(origin)):
                 self.projector("devenv build --no-scripts")
                 with chdir(origin):
                     repository = LocalRepository(curdir)
                     repository.checkout("master")
                     repository.commit("empty commit", allowEmpty=True)
                 self.projector("version release 1.2.3 --no-fetch --no-upload  --no-push-changes")
示例#52
0
 def freeze(self):
     from infi.projector.helper.utils import freeze_versions, buildout_parameters_context, open_tempfile
     from infi.projector.plugins.builtins.devenv import DevEnvPlugin
     from gitpy import LocalRepository
     from os import curdir
     plugin = DevEnvPlugin()
     plugin.arguments = {'--newest': self.arguments.get("--newest", False)}
     with open_tempfile() as tempfile:
         with buildout_parameters_context(
             ["buildout:update-versions-file={0}".format(tempfile)]):
             plugin.build()
         with open(tempfile) as fd:
             content = fd.read()
         with open(tempfile, 'w') as fd:
             fd.write("[versions]\n" + content)
         freeze_versions(
             tempfile, self.arguments.get("--with-install-requires", False))
     if self.arguments.get("--commit-changes", False):
         repository = LocalRepository(curdir)
         repository.add("buildout.cfg")
         repository.commit("Freezing dependencies")
     push_changes = self.arguments.get("--push-changes", False)
     if push_changes:
         repository._executeGitCommandAssertSuccess("git push")
示例#53
0
 def freeze(self):
     from infi.projector.helper.utils import freeze_versions, buildout_parameters_context, open_tempfile
     from infi.projector.plugins.builtins.devenv import DevEnvPlugin
     from gitpy import LocalRepository
     from os import curdir
     plugin = DevEnvPlugin()
     plugin.arguments = {'--newest': self.arguments.get("--newest", False)}
     with open_tempfile() as tempfile:
         with buildout_parameters_context(["buildout:update-versions-file={0}".format(tempfile)]):
             plugin.build()
         with open(tempfile) as fd:
             content = fd.read()
         with open(tempfile, 'w') as fd:
             fd.write("[versions]\n" + content)
         freeze_versions(tempfile, self.arguments.get("--with-install-requires", False))
     if self.arguments.get("--commit-changes", False):
         repository = LocalRepository(curdir)
         repository.add("buildout.cfg")
         repository.commit("Freezing dependencies")
     push_changes = self.arguments.get("--push-changes", False)
     if push_changes:
         repository._executeGitCommandAssertSuccess("git push")
示例#54
0
 def freeze(self):
     from infi.projector.helper.utils import freeze_versions, buildout_parameters_context, open_tempfile
     from infi.projector.plugins.builtins.devenv import DevEnvPlugin
     from gitpy import LocalRepository
     from os import curdir
     from re import sub, findall, MULTILINE
     plugin = DevEnvPlugin()
     plugin.arguments = {'--newest': self.arguments.get("--newest", False),
                         '--use-isolated-python': True}
     with open_tempfile() as tempfile:
         with buildout_parameters_context(["buildout:update-versions-file={0}".format(tempfile),
                                           "buildout:versions="]):
             plugin.build()
         with open(tempfile) as fd:
             content = fd.read()
         post_releases = findall(r'^[^#].* = .*\.post.*', content, MULTILINE)
         if post_releases:
             if self.arguments.get('--allow-post-releases'):
                 pass
             elif self.arguments.get('--strip-suffix-from-post-releases'):
                 content = sub(r'\.post\d+', '', content)
             else:
                 msg = "freeze found the follwing post-releases, see the dependency tree above:\n{}"
                 formatted_post_releases = "\n".join(item for item in post_releases)
                 logger.info(content)
                 logger.error(msg.format(formatted_post_releases))
                 raise SystemExit(1)
         with open(tempfile, 'w') as fd:
             fd.write("[versions]\n" + "\n".join(set(content.splitlines())))
         freeze_versions(tempfile, self.arguments.get("--with-install-requires", False))
     if self.arguments.get("--commit-changes", False):
         repository = LocalRepository(curdir)
         repository.add("buildout.cfg")
         repository.commit("Freezing dependencies", allowEmpty=True)
     push_changes = self.arguments.get("--push-changes", False)
     if push_changes:
         repository._executeGitCommandAssertSuccess("git push")
 def test_local_behind_origin(self):
     from os import curdir
     from os.path import abspath, basename
     from infi.projector.helper.utils import chdir
     if is_windows:
         raise SkipTest("skipping test on windows")
     with self.temporary_directory_context():
         self.projector("repository init a.b.c none short long")
         self.projector("devenv build --no-scripts --no-readline")
         origin = abspath(curdir)
         with self.temporary_directory_context():
             self.projector("repository clone {}".format(origin))
             with chdir(basename(origin)):
                 self.projector("devenv build --no-scripts --no-readline")
                 with chdir(origin):
                     repository = LocalRepository(curdir)
                     repository.checkout("master")
                     repository.commit("empty commit", allowEmpty=True)
                 with self.assertRaises(SystemExit):
                     self.projector(
                         "version release 1.2.3 --no-upload --no-push-changes"
                     )
示例#56
0
def commit_changes_to_manifest_in(message):
    from os import curdir
    from gitpy import LocalRepository
    repository = LocalRepository(curdir)
    repository.add("MANIFEST.in")
    repository.commit("MANIFEST.in: " + message)
示例#57
0
def do_an_empty_commit():
    from gitpy import LocalRepository
    repository = LocalRepository('.')
    repository.commit("TRIVIAL empty commit for testing upgrades",
                      allowEmpty=True)
示例#58
0
def do_an_empty_commit():
    from gitpy import LocalRepository
    repository = LocalRepository('.')
    repository.commit("TRIVIAL empty commit for testing upgrades", allowEmpty=True)
示例#59
0
def commit_changes_to_manifest_in(message):
    from os import curdir
    from gitpy import LocalRepository
    repository = LocalRepository(curdir)
    repository.add("MANIFEST.in")
    repository.commit("MANIFEST.in: " + message)