From 1e238a216332130ed68cf4cafea8adf76626e898 Mon Sep 17 00:00:00 2001 From: Justin Newberry Date: Thu, 21 Mar 2024 12:47:26 -0400 Subject: [PATCH] git commands: more parameterization on path (#31942) * more cwd * here top * and here * basedir old-commit-hash: 806f743e126b4bfcccec0b0b8458b5473da9c1b4 --- common/git.py | 14 +++++++------- system/version.py | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/common/git.py b/common/git.py index 1ab8b87099..bfb18ce25d 100644 --- a/common/git.py +++ b/common/git.py @@ -24,18 +24,18 @@ def get_branch(cwd: str = None) -> str: @cache -def get_origin() -> str: +def get_origin(cwd: str = None) -> str: try: - local_branch = run_cmd(["git", "name-rev", "--name-only", "HEAD"]) - tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"]) - return run_cmd(["git", "config", "remote." + tracking_remote + ".url"]) + local_branch = run_cmd(["git", "name-rev", "--name-only", "HEAD"], cwd=cwd) + tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"], cwd=cwd) + return run_cmd(["git", "config", "remote." + tracking_remote + ".url"], cwd=cwd) except subprocess.CalledProcessError: # Not on a branch, fallback - return run_cmd_default(["git", "config", "--get", "remote.origin.url"]) + return run_cmd_default(["git", "config", "--get", "remote.origin.url"], cwd=cwd) @cache -def get_normalized_origin() -> str: - return get_origin() \ +def get_normalized_origin(cwd: str = None) -> str: + return get_origin(cwd) \ .replace("git@", "", 1) \ .replace(".git", "", 1) \ .replace("https://", "", 1) \ diff --git a/system/version.py b/system/version.py index 8866026152..7b3ea940f4 100755 --- a/system/version.py +++ b/system/version.py @@ -37,8 +37,8 @@ def get_short_version() -> str: return get_version().split('-')[0] @cache -def is_prebuilt() -> bool: - return os.path.exists(os.path.join(BASEDIR, 'prebuilt')) +def is_prebuilt(path: str = BASEDIR) -> bool: + return os.path.exists(os.path.join(path, 'prebuilt')) @cache @@ -56,23 +56,23 @@ def is_release_branch() -> bool: return get_short_branch() in RELEASE_BRANCHES @cache -def is_dirty() -> bool: - origin = get_origin() - branch = get_branch() +def is_dirty(cwd: str = BASEDIR) -> bool: + origin = get_origin(cwd) + branch = get_branch(cwd) if not origin or not branch: return True dirty = False try: # Actually check dirty files - if not is_prebuilt(): + if not is_prebuilt(cwd): # This is needed otherwise touched files might show up as modified try: - subprocess.check_call(["git", "update-index", "--refresh"]) + subprocess.check_call(["git", "update-index", "--refresh"], cwd=cwd) except subprocess.CalledProcessError: pass - dirty = (subprocess.call(["git", "diff-index", "--quiet", branch, "--"]) != 0) + dirty = (subprocess.call(["git", "diff-index", "--quiet", branch, "--"], cwd=cwd)) != 0 except subprocess.CalledProcessError: cloudlog.exception("git subprocess failed while checking dirty") dirty = True