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))
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)
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")
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 _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))
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!")
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
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")
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")
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")
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")
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 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)
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")
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")
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" )
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")
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")
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 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")
def mess_things_up_and_raise(): repository = LocalRepository('.') repository.commit("message", allowEmpty=True) repository.createTag("test-tag") repository.createBranch("new-branch") raise Messup()
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)
def do_an_empty_commit(): from gitpy import LocalRepository repository = LocalRepository('.') repository.commit("TRIVIAL empty commit for testing upgrades", allowEmpty=True)