def gcloud_installed(): try: run_cmd('.', ['gcloud', '--version']) return True except OSError as e: logger.debug(e) return False
def _checkout(cwd, repo, branch): logger.debug(' Checking out branch {}.'.format(branch)) run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', branch]) run_cmd(cwd, ['git', 'fetch', '--tags', '--depth', '1', 'origin', branch]) tags = list_tags(cwd) # Prefer tags to branches if one exists if branch in tags: spec = 'tags/{}'.format(branch) else: spec = 'origin/{}'.format(branch) out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec]) return out, err
def _checkout(cwd, repo, branch): logger.debug(' Checking out branch {}.'.format(branch)) run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', branch]) run_cmd(cwd, ['git', 'fetch', '--tags', '--depth', '1', 'origin', branch]) tags = list_tags(cwd) # Prefer tags to branches if one exists if branch in tags: spec = 'tags/{}'.format(branch) else: spec = 'origin/{}'.format(branch) out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec], env={'LC_ALL': 'C'}) return out, err
def clone(repo, cwd, dirname=None, remove_git_dir=False, revision=None, subdirectory=None): has_revision = revision is not None is_commit = _is_commit(revision or "") clone_cmd = ['git', 'clone', '--depth', '1'] if subdirectory: logger.debug( ' Subdirectory specified: {}, using sparse checkout.'.format( subdirectory)) out, _ = run_cmd(cwd, ['git', '--version'], env={'LC_ALL': 'C'}) git_version = version.parse( re.search(r"\d+\.\d+\.\d+", out.decode("utf-8")).group(0)) if not git_version >= version.parse("2.25.0"): # 2.25.0 introduces --sparse raise RuntimeError( "Please update your git version to pull a dbt package " "from a subdirectory: your version is {}, >= 2.25.0 needed". format(git_version)) clone_cmd.extend(['--filter=blob:none', '--sparse']) if has_revision and not is_commit: clone_cmd.extend(['--branch', revision]) clone_cmd.append(repo) if dirname is not None: clone_cmd.append(dirname) result = run_cmd(cwd, clone_cmd, env={'LC_ALL': 'C'}) if subdirectory: run_cmd(os.path.join(cwd, dirname or ''), ['git', 'sparse-checkout', 'set', subdirectory]) if remove_git_dir: rmdir(os.path.join(dirname, '.git')) return result
def clone(repo, cwd, dirname=None, remove_git_dir=False): clone_cmd = ['git', 'clone', '--depth', '1', repo] if dirname is not None: clone_cmd.append(dirname) result = run_cmd(cwd, clone_cmd) if remove_git_dir: rmdir(os.path.join(dirname, '.git')) return result
def clone(repo, cwd, dirname=None, remove_git_dir=False): clone_cmd = ['git', 'clone', '--depth', '1', repo] if dirname is not None: clone_cmd.append(dirname) result = run_cmd(cwd, clone_cmd, env={'LC_ALL': 'C'}) if remove_git_dir: rmdir(os.path.join(dirname, '.git')) return result
def checkout(cwd, repo, branch=None): if branch is None: branch = 'master' logger.debug(' Checking out branch {}.'.format(branch)) run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', branch]) run_cmd(cwd, ['git', 'fetch', '--tags', '--depth', '1', 'origin', branch]) tags = list_tags(cwd) # Prefer tags to branches if one exists if branch in tags: spec = 'tags/{}'.format(branch) else: spec = 'origin/{}'.format(branch) out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec]) stderr = err.decode('utf-8').strip() if stderr.startswith('fatal:'): dbt.exceptions.bad_package_spec(repo, branch, stderr) else: return out, err
def clone(repo, cwd, dirname=None, remove_git_dir=False, branch=None): clone_cmd = ['git', 'clone', '--depth', '1'] if branch is not None: clone_cmd.extend(['--branch', branch]) clone_cmd.append(repo) if dirname is not None: clone_cmd.append(dirname) result = run_cmd(cwd, clone_cmd, env={'LC_ALL': 'C'}) if remove_git_dir: rmdir(os.path.join(dirname, '.git')) return result
def _checkout(cwd, repo, revision): logger.debug(' Checking out revision {}.'.format(revision)) fetch_cmd = ["git", "fetch", "origin", "--depth", "1"] if _is_commit(revision): run_cmd(cwd, fetch_cmd + [revision]) else: run_cmd(cwd, ['git', 'remote', 'set-branches', 'origin', revision]) run_cmd(cwd, fetch_cmd + ["--tags", revision]) if _is_commit(revision): spec = revision # Prefer tags to branches if one exists elif revision in list_tags(cwd): spec = 'tags/{}'.format(revision) else: spec = 'origin/{}'.format(revision) out, err = run_cmd(cwd, ['git', 'reset', '--hard', spec], env={'LC_ALL': 'C'}) return out, err
def get_current_sha(cwd): out, err = run_cmd(cwd, ['git', 'rev-parse', 'HEAD'], env={'LC_ALL': 'C'}) return out.decode('utf-8')
def list_tags(cwd): out, err = run_cmd(cwd, ['git', 'tag', '--list'], env={'LC_ALL': 'C'}) tags = out.decode('utf-8').strip().split("\n") return tags
def remove_remote(cwd): return run_cmd(cwd, ['git', 'remote', 'rm', 'origin'], env={'LC_ALL': 'C'})
def remove_remote(cwd): return run_cmd(cwd, ['git', 'remote', 'rm', 'origin'])
def get_current_sha(cwd): out, err = run_cmd(cwd, ['git', 'rev-parse', 'HEAD']) return out.decode('utf-8')
def setup_default_credentials(): if gcloud_installed(): run_cmd('.', ["gcloud", "auth", "application-default", "login"]) else: raise dbt.exceptions.RuntimeException(NOT_INSTALLED_MSG)
def list_tags(cwd): out, err = run_cmd(cwd, ['git', 'tag', '--list']) tags = set(out.decode('utf-8').strip().split("\n")) return tags