diff --git a/requirements/dev-requirements.in b/requirements/dev-requirements.in index 6d3e09d1a1b0..9c218ce1833d 100644 --- a/requirements/dev-requirements.in +++ b/requirements/dev-requirements.in @@ -12,6 +12,7 @@ wheel==0.29.0 transifex-client==0.12.4 modernize gnureadline==6.3.8 +git-build-branch # documentation Sphinx~=2.2.1 @@ -21,6 +22,5 @@ sphinxcontrib-django~=0.5 recommonmark graphviz==0.13.1 - # linting flake8 diff --git a/requirements/dev-requirements.txt b/requirements/dev-requirements.txt index 682248e32aee..f79ddeb28d90 100644 --- a/requirements/dev-requirements.txt +++ b/requirements/dev-requirements.txt @@ -22,13 +22,13 @@ git+git://github.com/dimagi/celery@dc7253614fd8500af78b09d1ceb79c50f1baac8d#egg= certifi==2019.9.11 # via requests, sentry-sdk cffi==1.13.2 # via cairocffi, csiphash, weasyprint chardet==3.0.4 # via ghdiff, requests -click==7.0 # via pip-tools +click==7.0 # via git-build-branch, pip-tools cloudant==2.12.0 # via jsonobject-couchdbkit colorama==0.4.1 # via sniffer commcaretranslationchecker==0.9.7 # via -r requirements/requirements.in commonmark==0.9.1 # via recommonmark concurrent-log-handler==0.9.12 # via -r requirements/requirements.in -contextlib2==0.5.5 # via schema +contextlib2==0.5.5 # via git-build-branch, schema coverage==4.5.1 # via -r requirements/test-requirements.in csiphash==0.0.5 # via -r requirements/requirements.in cssselect2==0.2.2 # via cairosvg, weasyprint @@ -86,9 +86,10 @@ fixture==1.5.11 # via -r requirements/dev-requirements.in flake8==3.7.9 # via -r requirements/dev-requirements.in flaky==3.6.0 # via -r requirements/test-requirements.in freezegun==0.3.12 # via -r requirements/test-requirements.in -gevent==1.4.0 # via -r requirements/requirements.in, django-websocket-redis, gipc +gevent==1.4.0 # via -r requirements/requirements.in, django-websocket-redis, gipc, git-build-branch ghdiff==0.4 # via -r requirements/requirements.in gipc==1.0.1 # via -r requirements/requirements.in +git-build-branch==0.1.9 # via -r requirements/dev-requirements.in gnureadline==6.3.8 # via -r requirements/dev-requirements.in graphviz==0.13.1 # via -r requirements/dev-requirements.in greenlet==0.4.15 # via -r requirements/requirements.in, django-websocket-redis, gevent @@ -110,7 +111,7 @@ jmespath==0.9.4 # via boto3, botocore json-delta==2.0 # via -r requirements/requirements.in jsonfield==2.1.1 # via -r requirements/requirements.in, django-prbac jsonobject-couchdbkit==1.0.1 # via -r requirements/requirements.in -jsonobject==0.9.9 # via -r requirements/requirements.in, jsonobject-couchdbkit +jsonobject==0.9.9 # via -r requirements/requirements.in, git-build-branch, jsonobject-couchdbkit jsonpath-rw==1.4.0 # via -r requirements/requirements.in kafka-python==1.4.7 # via -r requirements/requirements.in kombu==4.2.2.post1 # via -r requirements/requirements.in, celery @@ -167,7 +168,7 @@ python-magic==0.4.15 # via -r requirements/requirements.in python-mimeparse==1.6.0 # via django-tastypie python-termstyle==0.1.10 # via sniffer pytz==2019.3 # via -r requirements/requirements.in, babel, celery, django, jenkinsapi, twilio -pyyaml==5.1.2 # via -r requirements/requirements.in +pyyaml==5.1.2 # via -r requirements/requirements.in, git-build-branch pyzxcvbn==0.8.0 # via -r requirements/requirements.in qrcode==4.0.4 # via -r requirements/requirements.in, django-two-factor-auth quickcache==0.5.4 # via -r requirements/requirements.in @@ -183,7 +184,7 @@ rjsmin==1.0.12 # via django-compressor s3transfer==0.2.1 # via boto3 schema==0.7.1 # via -r requirements/requirements.in sentry-sdk==0.14.4 # via -r requirements/requirements.in -sh==1.09 # via -r requirements/requirements.in +sh==1.09 # via -r requirements/requirements.in, git-build-branch simpleeval==0.9.8 # via -r requirements/requirements.in simplejson==3.16.0 # via -r requirements/requirements.in, datadog, django-prbac six==1.13.0 # via -r requirements/requirements.in, django-appconf, django-extensions, django-prbac, django-simple-captcha, django-statici18n, django-transfer, django-websocket-redis, dropbox, ethiopian-date-converter, eulxml, faker, fixture, freezegun, ghdiff, html5lib, jsonfield, jsonobject, jsonobject-couchdbkit, jsonpath-rw, mock, packaging, pip-tools, python-dateutil, pyzxcvbn, qrcode, quickcache, requests-mock, sqlalchemy-postgres-copy, traitlets, transifex-client, twilio, unittest2 diff --git a/scripts/checkyaml.py b/scripts/checkyaml.py deleted file mode 100644 index 8a6913ebc136..000000000000 --- a/scripts/checkyaml.py +++ /dev/null @@ -1,22 +0,0 @@ -import sys -import yaml - - -def checkyaml(filename): - try: - yaml.safe_load(open(filename, encoding='utf-8')) - except yaml.YAMLError as e: - print("Error in file {}".format(filename), end=' ') - if hasattr(e, "problem_mark"): - mark = e.problem_mark - print("on line {} (column {}):".format(mark.line + 1, mark.column + 1)) - f = open(filename, encoding='utf-8') - for _ in range(mark.line + 1): - print(' ' + f.readline().rstrip('\n')) - print(' ' + (' ' * mark.column) + '^') - exit(1) - - -if __name__ == '__main__': - filename = sys.argv[1] - checkyaml(filename) diff --git a/scripts/commit-staging b/scripts/commit-staging index 93141110ea49..b96adad1d82b 100755 --- a/scripts/commit-staging +++ b/scripts/commit-staging @@ -1,60 +1,3 @@ #!/bin/bash -function get_branch() { - git branch | grep '^\*' | sed 's/* //' -} - -function abort () { - echo $1 - echo "Aborting." - exit 1 -} - -filename=scripts/staging.yaml -branch=$(get_branch) -COMMIT_MESSAGE='update staging.yaml' - -if [[ $branch != 'master' ]] -then - abort "You may only commit staging.yaml changes to master." -fi - -# add staging.yaml if the user hasn't -git add $filename - - -# make sure the only thing about to be committed is scripts/staging.yaml -staged_files=$(git diff --staged --stat | grep '|' | cut -d '|' -f1 | cut -d ' ' -f2) -if [[ 'scripts/staging.yaml' != $staged_files ]] -then - if [[ '' = $staged_files ]] - then - abort "You have no changes to commit." - else - abort "You have staged changes to more files than just $filename." - fi -fi - - -# make sure staging.yaml parses as yaml -python scripts/checkyaml.py $filename -if [[ $? -ne 0 ]] -then - abort "Fix staging.yml and try again" -fi - -# make sure local is not ahead of origin -git fetch -if [[ -n $(git log --max-count=1 origin/$branch..$branch) ]] -then - abort "Your local $branch is ahead of origin/$branch." -fi - -# have the commit follow a certain template -git commit --edit --message="$COMMIT_MESSAGE" --message "[ci skip]" - -# push if using --push option -if [[ $1 = '--push' ]] -then - git push origin $branch -fi +safe-commit-files scripts/staging.yaml diff --git a/scripts/gitutils.py b/scripts/gitutils.py deleted file mode 100644 index 35f3c31bff75..000000000000 --- a/scripts/gitutils.py +++ /dev/null @@ -1,178 +0,0 @@ -import re -import sh -from sh_verbose import ShVerbose - - -def get_git(path=None): - return sh.git.bake(_tty_out=False, _cwd=path) - - -def get_grep(): - return sh.grep.bake(_tty_out=False) - - -def get_tail(): - return sh.tail.bake(_tty_out=False) - - -class OriginalBranch(object): - def __init__(self, git=None): - self.git = git or get_git() - self.original_branch = None - - def __enter__(self): - self.original_branch = git_current_branch(self.git) - return self.original_branch - - def __exit__(self, exc_type, exc_val, exc_tb): - try: - self.git.checkout(self.original_branch) - except Exception as err: - print("cannot checkout '{}': {}".format(self.original_branch, err)) - - -def git_current_branch(git=None): - git = git or get_git() - grep = get_grep() - branch = grep(git.branch(), '^* ').strip()[2:] - if branch.startswith('('): - branch = git.log('--pretty=oneline', n=1).strip().split(' ')[0] - return branch - - -def git_recent_tags(grep_string="production-deploy"): - git, grep, tail = get_git(), get_grep(), get_tail() - last_tags = tail(grep(git.tag('--sort=committerdate'), grep_string), n=4) - return last_tags - - -def git_submodules(git=None): - git = git or get_git() - submodules = [] - for line in git.submodule().split('\n')[:-1]: - path = line[1:].split()[1] - submodules.append(path) - return submodules - - -def git_check_merge(branch1, branch2, git=None): - """ - returns True if branch1 would auto-merge cleanly into branch2, - False if the merge requires human assistance - - Thanks to http://stackoverflow.com/a/501461/240553 - - """ - git = git or get_git() - with ShVerbose(False): - orig_branch = git_current_branch(git) - git.checkout(branch2) - is_behind = git.log('{0}..{1}'.format(branch2, branch1), - max_count=1).strip() - clean_merge = True - if is_behind: - try: - git.merge('--no-commit', '--no-ff', branch1).strip() - except sh.ErrorReturnCode_1: - # git merge returns 1 when there's a conflict - clean_merge = False - git.merge('--abort') - git.checkout(orig_branch) - return clean_merge - - -def has_merge_conflict(branch1, branch2, git): - return not git_check_merge(branch1, branch2, git=git) - - -def git_bisect_merge_conflict(branch1, branch2, git=None): - """ - return the branch2 commit that prevents branch1 from being merged in - - """ - git = git or get_git() - grep = get_grep() - with OriginalBranch(git): - try: - base = git('merge-base', branch1, branch2).strip() - if git_check_merge(branch1, branch2, git): - return None - assert git_check_merge(branch1, base, git) - git.bisect('reset') - txt = git.bisect('start', branch2, base, '--') - while 'is the first bad commit' not in txt: - commit = git_current_branch(git) - if git_check_merge(branch1, commit, git): - txt = git.bisect('good') - else: - txt = git.bisect('bad') - try: - # txt has a line that's like " is the first bad commit" - return grep(txt, ' is the first bad commit$').strip().split(' ')[0] - except sh.ErrorReturnCode_1: - raise Exception('Error finding offending commit: ' - '"^commit" does not match\n{}'.format(txt)) - finally: - git.bisect('reset') - - -def _left_pad(padding, text): - return padding + ('\n' + padding).join(text.split('\n')) - - -def print_one_way_merge_details(branch1, branch2, git, known_branches=None): - def format_branch(remote, branch): - return branch if remote == 'origin' else '{}/{}'.format(remote, branch) - - if known_branches is None: - # make `foo in known_branches` always return True - class InfiniteSet(object): - def __contains__(self, item): - return True - known_branches = InfiniteSet() - - commit = git_bisect_merge_conflict(branch1, branch2, git) - if commit: - print(' * First conflicting commit on {0}:\n'.format(branch2)) - print(_left_pad(' ' * 4, git.log('-n1', commit))) - branches = git.branch('--remote', '--contains', commit) - other_branches = [ - format_branch(*b) - for b in re.findall(r'([a-zA-Z0-9-]*)/([\w+-]*)', str(branches)) - if b[0] != 'origin' or (b[1] != branch2 and b[1] in known_branches - and b[1] != 'HEAD') - ] - if other_branches: - msg = 'This commit also appears on these branches:' - print(_left_pad(' ' * 4, msg)) - for branch in other_branches: - print(_left_pad(' ' * 4, '* {}'.format(branch))) - else: - print(' * No conflicting commits on {0}'.format(branch2)) - - -def print_merge_details(branch1, branch2, git, known_branches=None): - print_one_way_merge_details(branch1, branch2, git, - known_branches=known_branches) - print_one_way_merge_details(branch2, branch1, git, - known_branches=known_branches) - - -if __name__ == '__main__': - import sys - args = sys.argv[1:] - options = ['show-conflict'] - try: - option = args.pop(0) - except IndexError: - option = None - if option == 'show-conflict': - if len(args) == 2: - print_merge_details(*args, git=get_git()) - else: - print ('usage: python scripts/gitutils.py ' - 'show-conflict ') - else: - print('usage: python scripts/gitutils.py [args...]\n') - print('Available commands:') - print(_left_pad(' ', '\n'.join(options))) diff --git a/scripts/rebuildstaging b/scripts/rebuildstaging index 0bdd4982da29..188d2e5fb16f 100755 --- a/scripts/rebuildstaging +++ b/scripts/rebuildstaging @@ -11,7 +11,6 @@ rebuild staging from yaml configuration (scripts/staging.yaml) --deploy deploy after rebuild is complete --no-push do not push changes (cannot be used with --deploy) --skip-fetch assume local copy is already update date with remote - --enterprise rebuild the enterprise branch EOF } @@ -39,10 +38,6 @@ do no_push=y echo no-push ;; - --enterprise) - enterprise=y - echo enterprise - ;; *) usage exit 1 @@ -52,13 +47,13 @@ done function rebuildstaging() { echo "rebuilding staging branch, this might take a while..." - python scripts/rebuildstaging.py scripts/staging.yaml "$@" + git-build-branch scripts/staging.yaml "$@" } args='' [[ $verbose = 'y' ]] && args="$args -v" -[[ $no_push = 'y' ]] && args="$args --no-push" +[[ -z "$no_push" || $no_push != 'y' ]] && args="$args --push" [[ $skip_fetch = 'y' ]] && args="$args sync rebuild" @@ -71,7 +66,7 @@ then exit 1 fi -if [[ $deploy = 'y' && $no_push != 'y' && $enterprise != 'y' ]] +if [[ $deploy = 'y' && $no_push != 'y' ]] then rebuildstaging $args && { which commcare-cloud \ diff --git a/scripts/rebuildstaging.py b/scripts/rebuildstaging.py deleted file mode 100644 index d1f3374ce872..000000000000 --- a/scripts/rebuildstaging.py +++ /dev/null @@ -1,390 +0,0 @@ -""" -This file is meant to be used in the following manner: - -$ python rebuildstaging.py < staging.yaml [-v] [--no-push] [fetch] [sync] [rebuild] - -Where staging.yaml looks as follows: - - trunk: master - name: autostaging - branches: - - feature1 - - feature2 - - forkowner:feature3 # branch from fork of repository - submodules: - submodules/module1: - branches: - - feature1 - - forkowner:feature2 # branch from fork of repository - submodules/module2: - trunk: develop - branches: - - feature2 - -When not specified, a submodule's trunk and name inherit from the parent -""" - -from gevent import monkey -monkey.patch_all() - -import os -import re -import sys -from contextlib import ExitStack - -import gevent -import jsonobject -import sh - -from gitutils import ( - OriginalBranch, - get_git, - git_recent_tags, - has_merge_conflict, - print_merge_details, -) -from sh_verbose import ShVerbose - - -class BranchConfig(jsonobject.JsonObject): - trunk = jsonobject.StringProperty() - name = jsonobject.StringProperty() - branches = jsonobject.ListProperty(str) - submodules = jsonobject.DictProperty(lambda: BranchConfig) - pull_requests = jsonobject.ListProperty(str) - - def normalize(self): - for submodule, subconfig in self.submodules.items(): - subconfig.trunk = subconfig.trunk or self.trunk - subconfig.name = subconfig.name or self.name - subconfig.normalize() - - def span_configs(self, path=('.',)): - for submodule, subconfig in self.submodules.items(): - for item in subconfig.span_configs(path + (submodule,)): - yield item - yield os.path.join(*path), self - - def check_trunk_is_recent(self): - # if it doesn't match our tag format - if re.match(r'[\d-]+_[\d\.]+-\w+-deploy', self.trunk) is None: - return True - - return self.trunk in git_recent_tags() - - -def fetch_remote(base_config, name="origin"): - jobs = [] - seen = set() - fetched = set() - for path, config in base_config.span_configs(): - if path in seen: - continue - seen.add(path) - git = get_git(path) - remotes = set(git.remote().split()) - print(" [{cwd}] fetching {name}".format(cwd=path, name=name)) - jobs.append(gevent.spawn(git.fetch, name)) - for branch in (b for b in config.branches if ":" in b): - remote, branch = branch.split(":", 1) - if remote not in remotes: - url = remote_url(git, remote) - print(" [{path}] adding remote: {remote} -> {url}" - .format(**locals())) - git.remote("add", remote, url) - remotes.add(remote) - print(" [{path}] fetching {remote} {branch}".format(**locals())) - jobs.append(gevent.spawn(git.fetch, remote, branch)) - fetched.add(remote) - - for pr in config.pull_requests: - print(" [{path}] fetching pull request {pr}".format(**locals())) - pr = 'pull/{pr}/head:enterprise-{pr}'.format(pr=pr) - jobs.append(gevent.spawn(git.fetch, 'origin', pr)) - - gevent.joinall(jobs) - print("fetched {}".format(", ".join(['origin'] + sorted(fetched)))) - - -def remote_url(git, remote, original="origin"): - origin_url = sh.grep(git.remote("-v"), original).split()[1] - repo_name = origin_url.rsplit("/", 1)[1] - return "https://github.com/{}/{}".format(remote, repo_name) - - -def has_ref(git, ref): - """Return true if the named branch exists""" - try: - out = git("show-ref", "--verify", "--quiet", ref) - except sh.ErrorReturnCode: - return False - return out.exit_code == 0 - - -def has_local(git, branch): - """Return true if the named local branch exists""" - return has_ref(git, "refs/heads/{}".format(branch)) - - -def has_remote(git, ref): - """Return true if the named remote branch exists - - :param ref: Remote ref (example: origin/branch-name) - """ - return has_ref(git, "refs/remotes/{}".format(ref)) - - -def origin(branch): - return "origin/{}".format(branch) - - -def sync_local_copies(config, push=True): - base_config = config - unpushed_branches = [] - - def _count_commits(compare_spec): - return int(sh.wc(git.log(compare_spec, '--oneline', _piped=True), '-l')) - - for path, config in base_config.span_configs(): - git = get_git(path) - with OriginalBranch(git): - for branch in [config.trunk] + config.branches: - if ":" in branch or not has_local(git, branch): - continue - git.checkout(branch) - unpushed = _count_commits('origin/{0}..{0}'.format(branch)) - unpulled = _count_commits('{0}..origin/{0}'.format(branch)) - if unpulled or unpushed: - print((" [{cwd}] {branch}: {unpushed} ahead " - "and {unpulled} behind origin").format( - cwd=path, - branch=branch, - unpushed=unpushed, - unpulled=unpulled, - )) - else: - print(" [{cwd}] {branch}: Everything up-to-date.".format( - cwd=path, - branch=branch, - )) - if unpushed: - unpushed_branches.append((path, branch)) - elif unpulled: - print(" Fastforwarding your branch to origin") - git.merge('--ff-only', origin(branch)) - if unpushed_branches and push: - print("The following branches have commits that need to be pushed:") - for path, branch in unpushed_branches: - print(" [{cwd}] {branch}".format(cwd=path, branch=branch)) - exit(1) - else: - print("All branches up-to-date.") - - -def rebuild_staging(config, print_details=True, push=True): - merge_conflicts = [] - not_found = [] - all_configs = list(config.span_configs()) - with ExitStack() as stack: - for path, _ in all_configs: - stack.enter_context(OriginalBranch(get_git(path))) - for path, config in all_configs: - git = get_git(path) - try: - git.checkout('-B', config.name, origin(config.trunk), '--no-track') - except Exception: - git.checkout('-B', config.name, config.trunk, '--no-track') - for branch in config.branches: - remote = ":" in branch - if remote or not has_local(git, branch): - if remote: - remote_branch = branch.replace(":", "/", 1) - else: - remote_branch = origin(branch) - if not has_remote(git, remote_branch): - not_found.append((path, branch)) - print(" [{cwd}] {branch} NOT FOUND".format( - cwd=format_cwd(path), - branch=branch, - )) - continue - branch = remote_branch - print(" [{cwd}] Merging {branch} into {name}".format( - cwd=path, - branch=branch, - name=config.name - ), end=' ') - try: - git.merge(branch, '--no-edit') - except sh.ErrorReturnCode_1: - merge_conflicts.append((path, branch, config)) - try: - git.merge("--abort") - except sh.ErrorReturnCode_128: - pass - print("FAIL") - else: - print("ok") - for pr in config.pull_requests: - branch = "enterprise-{pr}".format(pr=pr) - print(" [{cwd}] Merging {pr} into {name}".format( - cwd=path, - pr=pr, - name=config.name - ), end=' ') - try: - git.merge(branch, '--no-edit') - except sh.ErrorReturnCode_1: - merge_conflicts.append((path, branch, config)) - try: - git.merge("--abort") - except sh.ErrorReturnCode_128: - pass - print("FAIL") - else: - print("ok") - if config.submodules: - for submodule in config.submodules: - git.add(submodule) - git.commit('-m', "update submodule refs", '--no-edit', - '--allow-empty') - if push and not (merge_conflicts or not_found): - for path, config in all_configs: - # stupid safety check - assert config.name != 'master', path - print(" [{cwd}] Force pushing to origin {name}".format( - cwd=path, - name=config.name, - )) - force_push(get_git(path), config.name) - - if not_found: - print("You must remove the following branches before rebuilding:") - for cwd, branch in not_found: - print(" [{cwd}] {branch}".format( - cwd=format_cwd(cwd), - branch=branch, - )) - if merge_conflicts: - print("You must fix the following merge conflicts before rebuilding:") - for cwd, branch, config in merge_conflicts: - print("\n[{cwd}] {branch} => {name}".format( - cwd=format_cwd(cwd), - branch=branch, - name=config.name, - )) - git = get_git(cwd) - if print_details: - print_conflicts(branch, config, git) - - if merge_conflicts or not_found: - exit(1) - - -def print_conflicts(branch, config, git): - if has_merge_conflict(branch, config.trunk, git): - print(red("{} conflicts with {}".format(branch, config.trunk))) - return - - conflict_found = False - for other_branch in config.branches: - if has_merge_conflict(branch, other_branch, git): - print(red("{} conflicts with {}".format(branch, other_branch))) - conflict_found = True - - if not conflict_found: - print_merge_details(branch, config.name, git, - known_branches=config.branches) - - -def force_push(git, branch): - try: - git.push('origin', branch, '--force') - except sh.ErrorReturnCode_128 as e: - # oops we're using a read-only URL, so change to the suggested url - try: - line = sh.grep(git.remote("-v"), - '-E', r'^origin.(https|git)://github\.com/.*\(push\)$') - except sh.ErrorReturnCode_1: - raise e - old_url = line.strip().split()[1] - prefix = "git" if old_url.startswith("git:") else "https" - new_url = old_url.replace(prefix + "://github.com/", "git@github.com:") - print(" {} -> {}".format(old_url, new_url)) - git.remote('set-url', 'origin', new_url) - git.push('origin', branch, '--force') - - -def format_cwd(cwd): - return os.path.join(cwd) if cwd else '.' - - -class DisableGitHooks(object): - already_disabled = None - - def __init__(self, path='.git/hooks'): - import uuid - self.path = path - self.guid = uuid.uuid4().hex - - @property - def hidden_path(self): - return self.path + '-' + self.guid - - def __enter__(self): - try: - sh.test('-d', self.path) - self.already_disabled = False - except sh.ErrorReturnCode_1: - self.already_disabled = True - else: - sh.mv(self.path, self.hidden_path) - - def __exit__(self, exc_type, exc_val, exc_tb): - if not self.already_disabled: - sh.mv(self.hidden_path, self.path) - - -def _wrap_with(code): - - def inner(text, bold=False): - c = code - - if bold: - c = "1;%s" % c - return "\033[%sm%s\033[0m" % (c, text) - return inner - - -red = _wrap_with('31') - - -def main(): - import yaml - with open(sys.argv[1]) as staging_yaml: - config = yaml.safe_load(staging_yaml) - config = BranchConfig.wrap(config) - config.normalize() - if not config.check_trunk_is_recent(): - print("The trunk is not based on a very recent commit") - print("Consider using one of the following:") - print(git_recent_tags()) - exit(1) - args = set(sys.argv[2:]) - verbose = '-v' in args - do_push = '--no-push' not in args - args.discard('-v') - args.discard('--no-push') - if not args: - args = set('fetch sync rebuild'.split()) - with DisableGitHooks(), ShVerbose(verbose): - if 'fetch' in args: - fetch_remote(config) - if 'sync' in args: - sync_local_copies(config, push=do_push) - if 'rebuild' in args: - rebuild_staging(config, push=do_push) - - -if __name__ == '__main__': - main() diff --git a/scripts/sh_verbose.py b/scripts/sh_verbose.py deleted file mode 100644 index 6900514b38cb..000000000000 --- a/scripts/sh_verbose.py +++ /dev/null @@ -1,45 +0,0 @@ -import os -import sh -import sys - - -def format_cwd(cwd): - return os.path.join(cwd) if cwd else '.' - - -_original_init = sh.RunningCommand.__init__ - - -def _verbose_init(self, cmd, call_args, stdin, stdout, stderr): - print("[{cwd}]$ {command}".format( - cwd=format_cwd(call_args['cwd']), - command=' '.join(cmd[0].rsplit('/', 1)[1:] + cmd[1:]), - )) - try: - _original_init(self, cmd, call_args, stdin, stdout, stderr) - except sh.ErrorReturnCode as e: - sys.stdout.write(e.stdout) - sys.stderr.write(e.stderr) - raise - else: - sys.stdout.write(self.stdout) - sys.stderr.write(self.stderr) - - -def patch_sh_verbose(): - sh.RunningCommand.__init__ = _verbose_init - - -class ShVerbose(object): - def __init__(self, verbose=True): - self.verbose = verbose - self.start_init = None - - def __enter__(self): - # record whatever the current __init__ is so we can reset it later - self.start_init = sh.RunningCommand.__init__ - sh.RunningCommand.__init__ = (_verbose_init if self.verbose - else _original_init) - - def __exit__(self, exc_type, exc_val, exc_tb): - sh.RunningCommand.__init__ = self.start_init diff --git a/scripts/vellum-to-hq b/scripts/vellum-to-hq index c7938570219c..fdd7eb3b2ae9 100755 --- a/scripts/vellum-to-hq +++ b/scripts/vellum-to-hq @@ -22,11 +22,14 @@ from argparse import ArgumentParser, RawDescriptionHelpFormatter from os.path import abspath, dirname, exists, join import sh -from gitutils import get_git VELLUM_TAR = "vellum.tar.gz" +def get_git(path=None): + return sh.git.bake(_tty_out=False, _cwd=path) + + def main(): parser = ArgumentParser(description=__doc__, formatter_class=RawDescriptionHelpFormatter) parser.add_argument("mode", choices=["staging", "master"],