def clone( url: str, dest: pathlib.Path = None, committish: str = "master", force: bool = False, depth: int = None, ) -> pathlib.Path: if dest is None: dest = cache.get_cache_dir() dest = dest / pathlib.Path(url).stem if force and dest.exists(): shutil.rmtree(dest) if not dest.exists(): cmd = ["git", "clone", url, dest] if depth is not None: cmd.extend(["--depth", str(depth)]) shell.run(cmd) else: shell.run(["git", "pull"], cwd=str(dest)) shell.run(["git", "reset", "--hard", committish], cwd=str(dest)) # track all git repositories _tracked_paths.add(dest) return dest
def format_code(path: str, version: str = DEFAULT_FORMAT_VERSION) -> None: """ Runs the google-java-format jar against all .java files found within the provided path. """ jar_name = f"google-java-format-{version}.jar" jar = cache.get_cache_dir() / jar_name if not jar.exists(): _download_formatter(version, jar) # Find all .java files in path and run the formatter on them files = list(glob.iglob(os.path.join(path, "**/*.java"), recursive=True)) # Run the formatter as a jar file log.info("Running java formatter on {} files".format(len(files))) shell.run(["java", "-jar", str(jar), "--replace"] + files)
def clone( url: str, dest: pathlib.Path = None, committish: str = "master", force: bool = False, depth: int = None, ) -> pathlib.Path: if dest is None: dest = cache.get_cache_dir() dest = dest / pathlib.Path(url).stem if force and dest.exists(): shutil.rmtree(dest) if not dest.exists(): cmd = ["git", "clone", url, dest] if depth is not None: cmd.extend(["--depth", str(depth)]) shell.run(cmd) else: shell.run(["git", "pull"], cwd=str(dest)) shell.run(["git", "reset", "--hard", committish], cwd=str(dest)) # track all git repositories _tracked_paths.add(dest) # add repo to metadata sha, message = get_latest_commit(dest) commit_metadata = extract_commit_message_metadata(message) metadata.add_git_source( name=dest.name, remote=url, sha=sha, internal_ref=commit_metadata.get("PiperOrigin-RevId"), ) return dest
def clone( url: str, dest: pathlib.Path = None, committish: str = None, force: bool = False, ) -> pathlib.Path: """Clones a remote git repo. Will not actually clone the repo if it's already local via two ways: 1. It's in the cache (the default destitination). 2. It was supplied via the preconfig file. Arguments: url {str} -- Url pointing to remote git repo. Keyword Arguments: dest {pathlib.Path} -- Local folder where repo should be cloned. (default: {None}) committish {str} -- The commit hash to check out. (default: {None}) force {bool} -- Wipe out and reclone if it already exists it the cache. (default: {False}) Returns: pathlib.Path -- Local directory where the repo was cloned. """ preclone = get_preclone(url) if preclone: logger.debug(f"Using precloned repo {preclone}") dest = pathlib.Path(preclone) else: if dest is None: dest = cache.get_cache_dir() dest = dest / pathlib.Path(url).stem if force and dest.exists(): shutil.rmtree(dest) if not dest.exists(): cmd = [ "git", "clone", "--recurse-submodules", "--single-branch", url, dest ] shell.run(cmd, check=True) else: shell.run(["git", "checkout", "master"], cwd=str(dest), check=True) shell.run(["git", "pull"], cwd=str(dest), check=True) committish = committish or "master" if committish: shell.run(["git", "reset", "--hard", committish], cwd=str(dest)) # track all git repositories _tracked_paths.add(dest) # add repo to metadata sha, message = get_latest_commit(dest) commit_metadata = extract_commit_message_metadata(message) metadata.add_git_source( name=dest.name, remote=url, sha=sha, internal_ref=commit_metadata.get("PiperOrigin-RevId"), local_path=str(dest), ) return dest