Ejemplo n.º 1
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))
Ejemplo n.º 2
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)
Ejemplo n.º 3
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")
Ejemplo n.º 4
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)
 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")
Ejemplo n.º 6
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))
Ejemplo n.º 7
0
class CollaborationTest(unittest.TestCase):
    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 tearDown(self):
        utils.delete_repository(self.repo1)
        utils.delete_repository(self.repo2)

    def testRemotePushBranches(self):
        b = self.repo2.createBranch("branch")
        self.repo1.createBranch('remote_branch')
        self.repo2.fetch()
        remote_branch = self.repo2.getRemoteByName('origin').getBranchByName('remote_branch')
        b.setRemoteBranch(remote_branch)
        self.assertEquals(b.getRemoteBranch(), remote_branch)
        b.setRemoteBranch(None)
        self.assertEquals(b.getRemoteBranch(), None)
        # try setting to None multiple times
        b.setRemoteBranch(None)
    def testCollaboration(self):
        new_file_base_name = "new_file.txt"
        new_filename = os.path.join(self.repo1.path, new_file_base_name)
        with open(new_filename, "wb") as f:
            print >> f, "hello there!"
        self.assertTrue(new_file_base_name in self.repo1.getUntrackedFiles())
        self.repo1.addAll()
        self.assertTrue(any(f.filename == new_file_base_name for f in self.repo1.getStagedFiles()))
        c = self.repo1.commit(message="add file")
        self.assertFalse(os.path.exists(os.path.join(self.repo2.path, new_file_base_name)))
        self.repo2.pull()
        self.assertTrue(os.path.exists(os.path.join(self.repo2.path, new_file_base_name)))
        self.assertTrue(c in self.repo2)
    def testRemoteBranchDeletion(self):
        self.repo1.createBranch("testme")
        self.repo2.fetch()
        remote_branch = self.repo2.getRemoteByName("origin").getBranchByName("testme")
        self.assertEquals(remote_branch.getHead(), self.repo1.getBranchByName("testme").getHead())
        remote_branch.delete()
        try:
            self.repo1.getBranchByName("testme")
        except NonexistentRefException:
            pass
        else:
            self.fail("Did not fail!")
Ejemplo n.º 8
0
Archivo: utils.py Proyecto: 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
Ejemplo n.º 9
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")
Ejemplo n.º 10
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")
Ejemplo n.º 11
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)
 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")
Ejemplo n.º 13
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")
Ejemplo n.º 14
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")
Ejemplo n.º 15
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")
Ejemplo n.º 16
0
 def testAddingRemotes(self):
     new_repo = LocalRepository(utils.get_temporary_location())
     new_repo.init()
     with open(os.path.join(new_repo.path, "some_file"), "wb") as f:
         print >> f, "new file"
     new_repo.addAll()
     new_repo.commit(message="initial change")
     REMOTE_NAME = 'remote'
     remote = new_repo.addRemote(REMOTE_NAME, self.repo.path)
     self.assertEquals(remote.name, REMOTE_NAME)
     self.assertEquals(remote.url, self.repo.path)
     self.assertFalse(new_repo.containsCommit(self.repo.getHead()))
     remote.fetch()
     remote.prune()
     self.assertTrue(new_repo.containsCommit(self.repo.getHead()))
     branches = list(remote.getBranches())
     self.assertTrue(len(branches) > 0)
     for branch in branches:
         self.assertTrue(type(branch in new_repo.getHead()) is bool)
Ejemplo n.º 17
0
 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")
Ejemplo n.º 18
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")
Ejemplo n.º 19
0
 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"
                     )
Ejemplo n.º 20
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")
Ejemplo n.º 21
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")
Ejemplo n.º 22
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")
Ejemplo n.º 23
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")
Ejemplo n.º 24
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")
Ejemplo n.º 25
0
 def mess_things_up_and_raise():
     repository = LocalRepository('.')
     repository.commit("message", allowEmpty=True)
     repository.createTag("test-tag")
     repository.createBranch("new-branch")
     raise Messup()
Ejemplo n.º 26
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)
Ejemplo n.º 27
0
 def mess_things_up_and_raise():
     repository = LocalRepository('.')
     repository.commit("message", allowEmpty=True)
     repository.createTag("test-tag")
     repository.createBranch("new-branch")
     raise Messup()
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
def do_an_empty_commit():
    from gitpy import LocalRepository
    repository = LocalRepository('.')
    repository.commit("TRIVIAL empty commit for testing upgrades", allowEmpty=True)
Ejemplo n.º 30
0
def do_an_empty_commit():
    from gitpy import LocalRepository
    repository = LocalRepository('.')
    repository.commit("TRIVIAL empty commit for testing upgrades",
                      allowEmpty=True)