mirror of https://github.com/commaai/openpilot.git
git commands: more parameterization on path (#31942)
* more cwd * here top * and here * basedir
This commit is contained in:
parent
35b31df7f7
commit
806f743e12
|
@ -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) \
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue