def initialize_git_repository() -> None: """Prepare the git repository.""" print(" * Initializing the project git repository") try: git.init() git.remote( "add", "origin", "[email protected]:{{ cookiecutter.github_user }}/" "{{ cookiecutter.project_slug }}.git", ) git.add(".") git.commit("-m", "feat: create initial project structure") git.checkout("-b", "gh-pages") git.checkout("-b", "feat/initial_iteration") print(" * Pushing initial changes to master") git.push("--force", "--set-upstream", "origin", "master") git.push("--force", "--set-upstream", "origin", "gh-pages") git.push("--force", "--set-upstream", "origin", "feat/initial_iteration") git.push("--force") except sh.ErrorReturnCode as error: print("There was an error creating the Git repository.") print(str(error.stderr, "utf8")) sys.exit(1)
def set_remote(self, chdir=False): # init remote = WALIKI_DATA_DIR + '_remote' git.clone(WALIKI_DATA_DIR, remote) os.chdir(remote) git.config("user.email", '*****@*****.**') git.config("user.name", 'I am me, yo') os.chdir(WALIKI_DATA_DIR) git.remote('add', 'origin', remote) if chdir: os.chdir(remote) return remote
def main(): config = yaml.load(open('.covio.yml')) _prepare_project(config) maybe_project = list(git.remote('-v'))[0].split(':')[1].split(' ')[0][:-4] if maybe_project == '//': maybe_project = '/'.join( re.match(r'.*[/:](.*)/(.*).git \(.*\)', list(git.remote('-v'))[0]).groups()) elif maybe_project.find('/') == 0: maybe_project = '/'.join(maybe_project.split('/')[3:]) request = { 'project': config.get('project', maybe_project), 'service': get_service(config), 'violations': [ _create_violation_dict(name, data) for name, data in _iterate_violations(config) ], 'commit': { 'hash': gitlog('%H'), 'branch': get_branch(), 'author': gitlog('%aN'), 'summary': gitlog('%s'), } } response = requests.post( config.get( 'endpoint', 'https://coviolations.io/api/v1/tasks/raw/', ), data=json.dumps(request), headers={ 'Content-type': 'application/json', 'Accept': 'text/plain', }, ) if check_status(response): print('Violations sent::{}::{}'.format( response.status_code, response.text, )) else: sys.exit(1)
def ensure_i18n_remote(self, args: argparse.Namespace) -> None: """ Make sure we have a git remote for the i18n repo. """ k = {"_cwd": args.root} if b"i18n" not in git.remote(**k).stdout: git.remote.add("i18n", args.url, **k) git.fetch("i18n", **k)
def main(): config = yaml.load(open('.covio.yml')) _prepare_project(config) maybe_project = list(git.remote('-v'))[0].split(':')[1].split(' ')[0][:-4] if maybe_project == '//': maybe_project = '/'.join(re.match( r'.*[/:](.*)/(.*).git \(.*\)', list(git.remote('-v'))[0] ).groups()) elif maybe_project.find('/') == 0: maybe_project = '/'.join(maybe_project.split('/')[3:]) request = { 'project': config.get('project', maybe_project), 'service': get_service(config), 'violations': [ _create_violation_dict(name, data) for name, data in _iterate_violations(config) ], 'commit': { 'hash': gitlog('%H'), 'branch': get_branch(), 'author': gitlog('%aN'), 'summary': gitlog('%s'), } } response = requests.post( config.get( 'endpoint', 'https://coviolations.io/api/v1/tasks/raw/', ), data=json.dumps(request), headers={ 'Content-type': 'application/json', 'Accept': 'text/plain', }, ) if check_status(response): print('Violations sent::{}::{}'.format( response.status_code, response.text, )) else: sys.exit(1)
def delete(version_number): heading1("Deleting version " + version_number + "\n") cd(base_dir) heading2("Removing branch from git.") print(git.checkout("master")) print(git.branch("-D", version_number)) print(git.remote("prune", "origin")) heading2("Deleting files.") print(rm("-rf", base_dir + "/fedora-kickstarts"))
def pull(self, branch, tag, sourceDir): if not path.exists(sourceDir): msgwarn("Source directory {} non-existing".format(sourceDir)) cp("-R", blenderSourceDir, sourceDir) cd(sourceDir) msgcmd("Update branch {}".format(branch)) #git.rebase("--abort") git.clean("-fd", _out=debugSh) git.checkout(".", _out=debugSh) try: git.checkout("-t", "origin/" + branch, _out=debugSh) except: pass git.checkout(branch) git.pull("origin", branch, "--rebase", _out=debugSh) git.remote("prune", "origin") git.pull("--rebase", _out=debugSh) if tag is not "": git.checkout(tag, _out=debugSh) git.submodule.foreach("--recursive", "git", "checkout", "master", _out=debugSh) git.submodule.foreach("git", "reset", "HEAD", "--hard", _out=debugSh) git.submodule.update("--init", "--recursive", _out=debugSh) git.submodule.foreach("--recursive", "git", "pull", "--rebase", "origin", "master", _out=debugSh)
def main(): config = yaml.load(open('.covio.yml')) maybe_project = list(git.remote('-v'))[0].split(':')[1].split(' ')[0][:-4] if maybe_project.find('/') == 0: maybe_project = '/'.join(maybe_project.split('/')[3:]) request = { 'project': config.get('project', maybe_project), 'service': get_service(config), 'violations': [{ 'name': name, 'raw': _read_violation(command), } for name, command in config['violations'].items()], 'commit': { 'hash': gitlog('%H'), 'branch': os.environ.get('TRAVIS_BRANCH', git('rev-parse', '--abbrev-ref', 'HEAD').strip()), 'author': gitlog('%aN'), 'summary': gitlog('%s'), } } response = requests.post( config.get( 'endpoint', 'http://coviolations.io/api/v1/tasks/', ), data=json.dumps(request), headers={ 'Content-type': 'application/json', 'Accept': 'text/plain', }, ) print('Violations sent::{}::{}'.format( response.status_code, response.text, ))
def git_info(self): """ A hash of Git data that can be used to display more information to users. Example: "git": { "head": { "id": "5e837ce92220be64821128a70f6093f836dd2c05", "author_name": "Wil Gieseler", "author_email": "*****@*****.**", "committer_name": "Wil Gieseler", "committer_email": "*****@*****.**", "message": "depend on simplecov >= 0.7" }, "branch": "master", "remotes": [{ "name": "origin", "url": "https://github.com/lemurheavy/coveralls-ruby.git" }] } """ git_info = { 'git': { 'head': { 'id': gitlog('%H'), 'author_name': gitlog('%aN'), 'author_email': gitlog('%ae'), 'committer_name': gitlog('%cN'), 'committer_email': gitlog('%ce'), 'message': gitlog('%s'), }, 'branch': os.environ.get('CIRCLE_BRANCH') or os.environ.get( 'TRAVIS_BRANCH', git('rev-parse', '--abbrev-ref', 'HEAD').strip()), #origin [email protected]:coagulant/coveralls-python.git (fetch) 'remotes': [{ 'name': line.split()[0], 'url': line.split()[1] } for line in git.remote('-v') if '(fetch)' in line] } } return git_info
def main(): config = yaml.load(open('.covio.yml')) maybe_project = list(git.remote('-v'))[0].split(':')[1].split(' ')[0][:-4] if maybe_project.find('/') == 0: maybe_project = '/'.join(maybe_project.split('/')[3:]) request = { 'project': config.get('project', maybe_project), 'service': get_service(config), 'violations': [ { 'name': name, 'raw': _read_violation(command), } for name, command in config['violations'].items() ], 'commit': { 'hash': gitlog('%H'), 'branch': os.environ.get( 'TRAVIS_BRANCH', git('rev-parse', '--abbrev-ref', 'HEAD').strip()), 'author': gitlog('%aN'), 'summary': gitlog('%s'), } } response = requests.post( config.get( 'endpoint', 'http://coviolations.io/api/v1/tasks/', ), data=json.dumps(request), headers={ 'Content-type': 'application/json', 'Accept': 'text/plain', }, ) print('Violations sent::{}::{}'.format( response.status_code, response.text, ))
def git_info(self): """ A hash of Git data that can be used to display more information to users. Example: "git": { "head": { "id": "5e837ce92220be64821128a70f6093f836dd2c05", "author_name": "Wil Gieseler", "author_email": "*****@*****.**", "committer_name": "Wil Gieseler", "committer_email": "*****@*****.**", "message": "depend on simplecov >= 0.7" }, "branch": "master", "remotes": [{ "name": "origin", "url": "https://github.com/lemurheavy/coveralls-ruby.git" }] } """ git_info = {'git': { 'head': { 'id': gitlog('%H'), 'author_name': gitlog('%aN'), 'author_email': gitlog('%ae'), 'committer_name': gitlog('%cN'), 'committer_email': gitlog('%ce'), 'message': gitlog('%s'), }, 'branch': os.environ.get('TRAVIS_BRANCH', git('rev-parse', '--abbrev-ref', 'HEAD').strip()), #origin [email protected]:coagulant/coveralls-python.git (fetch) 'remotes': [{'name': line.split()[0], 'url': line.split()[1]} for line in git.remote('-v') if '(fetch)' in line] }} return git_info
def gen_remotes(file_path): '''return generetor of remotes''' remotes = git.remote(_cwd=dir_path(file_path)) return remotes
def tag(obj, tag_name, remote, yes): current_branch = get_current_branch() remote_url = git.remote("get-url", remote).strip() gh, repo = obj tag = split_version(tag_name) tag_name = format_version(tag) major, minor, fix = tag with Spinner(f"Checking for milestone for tag {tag_name}"): tag_milestone = None for ms in repo.get_milestones(state="all"): if ms.title == tag_name: tag_milestone = ms break assert tag_milestone is not None, "Did not find milestone for tag" release_branch_name = f"release/v{major}.{minor:>02}.X" with Spinner("Refreshing branches"): git.fetch(all=True, prune=True) if fix == 0: # new minor release with Spinner(f"Checking out and updating {default_branch_name}"): git.checkout(default_branch_name) git.pull() assert not check_branch_exists( release_branch_name ), "For new minor: release branch CANNOT exist yet" with Spinner(f"Creating {release_branch_name}"): git.checkout("-b", release_branch_name) else: assert check_branch_exists( release_branch_name), "For new fix: release brunch MUST exist" with Spinner(f"Checking out {release_branch_name}"): git.checkout(release_branch_name) # we are not on release branch version_file = Path("version_number") assert version_file.exists(), "Version number file not found" current_version_string = version_file.read_text() print(f"Current version: [bold]{current_version_string}[/bold]") if fix == 0: assert current_version_string == "9.9.9", "Unexpected current version string found" else: assert current_version_string != f"{major}.{minor}.{fix-1}", "Unexpected current version string found" version_string = f"{major}.{minor}.{fix}" with Spinner( f"Bumping version number in '{version_file}' to '{version_string}'" ): with version_file.open("w") as fh: fh.write(version_string) with Spinner("Comitting"): git.add(version_file) git.commit(m=f"Bump version number to {version_string}") with Spinner(f"Creating tag {tag_name}"): git.tag(tag_name) print( f"I will now: push tag [bold green]{tag_name}[/bold green] and branch [bold green]{release_branch_name}[/bold green] to [bold]{remote_url}[/bold]" ) if not confirm("Continue?", yes=yes): raise SystemExit("Aborting") with Spinner(f"Pushing branch {release_branch_name}"): git.push("-u", remote, release_branch_name) with Spinner(f"Pushing tag {tag_name}"): git.push(remote, tag_name)
def _get_provisioner_repo(self): # Use the configured git repository, if any provisioner_git_repo = self.config.get('git_repo') provisioner_git_revision = self.config.get('git_revision') git_local_mirror = self._get_mirror_path(provisioner_git_repo) zabbix_repo = self.global_config.get('zabbix_repo', ZABBIX_REPO) lock_path = get_lock_path_from_repo(provisioner_git_repo) log( "Getting provisioner features from {r}".format( r=provisioner_git_repo), self._log_file) try: output = git("ls-remote", "--exit-code", provisioner_git_repo, provisioner_git_revision).strip() log( "Provisioner repository checked successfuly with output: " + output, self._log_file) except sh.ErrorReturnCode: log( "Invalid provisioner repository or invalid credentials. Please check your yaml 'config.yml' file", self._log_file) raise try: git_acquire_lock(lock_path, self._log_file) # Creates the Provisioner local mirror if not os.path.exists(git_local_mirror): log( "Creating local mirror [{r}] for the first time".format( r=git_local_mirror), self._log_file) os.makedirs(git_local_mirror) os.chdir(git_local_mirror) git.init(['--bare']) git.remote(['add', self.name, provisioner_git_repo]) git.remote(['add', 'zabbix', zabbix_repo]) log( "Fetching local mirror [{r}] remotes".format( r=git_local_mirror), self._log_file) os.chdir(git_local_mirror) git.fetch(['--all']) finally: git_release_lock(lock_path, self._log_file) log( "Cloning [{r}] repo with local mirror reference".format( r=provisioner_git_repo), self._log_file) git.clone([ '--reference', git_local_mirror, provisioner_git_repo, '-b', provisioner_git_revision, '--single-branch', self.local_repo_path + '/' ]) if os.path.exists(self.local_repo_path + '/.gitmodules'): os.chdir(self.local_repo_path) log("Re-map submodules on local git mirror", self._log_file) git_remap_submodule(self.local_repo_path, zabbix_repo, git_local_mirror, self._log_file) log("Submodule init and update", self._log_file) git.submodule('init') git.submodule('update')
def add_or_set_git_remote(remote_name, remote_uri): if remote_name in str(git.remote()).splitlines(keepends=False): git.remote("set-url", remote_name, remote_uri) else: git.remote.add(remote_name, remote_uri)
def ensure_i18n_remote(self, args): k = {'_cwd': args.root} if b'i18n' not in git.remote(**k).stdout: git.remote.add('i18n', args.url, **k) git.fetch('i18n', **k)
def lose(msg, e=None): print(msg) print("You will need to do the initialization steps manually.") print("Read scripts/first-run.py for more instructions how to do this.") if e: print( "\nHere's an additional error message which may help diagnose the problem." ) raise e sys.exit(1) try: my_repo_url = git.remote("get-url", "origin") except Exception as e: lose("Could not use git to find my own repository URL", e) m = re.match(r"(?:https://github.com/|[email protected]:)(.*)/(.*)/?", str(my_repo_url)) if not m: lose( f"My git repository URL ({my_repo_url}) didn't look what I expected - are you hosting this on github?" ) owner, reponame = m[1], m[2] if owner == BASE_OWNER and reponame == BASE_REPONAME: print("I am being run on the upstream repository (probably due to CI)") print("All I'm going to do is create the touch file and quit.")
from tester import * from tracer import * from xvfb import * from sh import git, cd import sys display = Display() cd(blenderSourceDir) git.remote("prune", "origin") git.pull("--rebase") if "--branch" in sys.argv: branch = sys.argv[sys.argv.index("--branch") + 1] else: branch = "master" args = [] script = "" if "basic" in sys.argv: script = "BasicMain" elif "error" in sys.argv: script = "PythonErrorMain" args = [pythonTestLogDir] scriptFile = pythonMainScript + script + ".py" if "valgrind" in sys.argv: tester = Valgrind(branch, scriptFile, args) elif "tracer" in sys.argv: tester = BranchTracer(branch, "0000")
def cookbook_git_url(self): os.chdir(self.cookbook_path) match = COOKBOOK_URL_RE.match(str(git.remote('-v'))) os.chdir(self.repo_path) return match.groups()[0]
def get_dokku(): remote = git.remote("get-url", "dokku").strip() m = re.match(r"(?P<user>.*)@(?P<host>.*):(?P<app>.*)", remote) return m.groups()
def init_remote(self, url): return git.remote('add','origin',url)
def ensure_i18n_remote(self, args: argparse.Namespace) -> None: k = {'_cwd': args.root} if b'i18n' not in git.remote(**k).stdout: git.remote.add('i18n', args.url, **k) git.fetch('i18n', **k)
def init_remote(self, url): return git.remote('add', 'origin', url)