|
|
@ -1,7 +1,7 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
#!/usr/bin/env python3 |
|
|
|
import os |
|
|
|
import os |
|
|
|
import subprocess |
|
|
|
import subprocess |
|
|
|
from typing import List, Optional, Callable, TypeVar |
|
|
|
from typing import List, Callable, TypeVar |
|
|
|
from functools import lru_cache |
|
|
|
from functools import lru_cache |
|
|
|
|
|
|
|
|
|
|
|
from openpilot.common.basedir import BASEDIR |
|
|
|
from openpilot.common.basedir import BASEDIR |
|
|
@ -22,7 +22,7 @@ def run_cmd(cmd: List[str]) -> str: |
|
|
|
return subprocess.check_output(cmd, encoding='utf8').strip() |
|
|
|
return subprocess.check_output(cmd, encoding='utf8').strip() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[str]: |
|
|
|
def run_cmd_default(cmd: List[str], default: str = "") -> str: |
|
|
|
try: |
|
|
|
try: |
|
|
|
return run_cmd(cmd) |
|
|
|
return run_cmd(cmd) |
|
|
|
except subprocess.CalledProcessError: |
|
|
|
except subprocess.CalledProcessError: |
|
|
@ -31,17 +31,22 @@ def run_cmd_default(cmd: List[str], default: Optional[str] = None) -> Optional[s |
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
@cache |
|
|
|
def get_commit(branch: str = "HEAD") -> str: |
|
|
|
def get_commit(branch: str = "HEAD") -> str: |
|
|
|
return run_cmd_default(["git", "rev-parse", branch]) or "" |
|
|
|
return run_cmd_default(["git", "rev-parse", branch]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
|
|
|
|
def get_commit_date(commit: str = "HEAD") -> str: |
|
|
|
|
|
|
|
return run_cmd_default(["git", "show", "--no-patch", "--format='%ct %ci'", commit]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
@cache |
|
|
|
def get_short_branch() -> str: |
|
|
|
def get_short_branch() -> str: |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"]) or "" |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "HEAD"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
@cache |
|
|
|
def get_branch() -> str: |
|
|
|
def get_branch() -> str: |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]) or "" |
|
|
|
return run_cmd_default(["git", "rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
@cache |
|
|
@ -51,7 +56,7 @@ def get_origin() -> str: |
|
|
|
tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"]) |
|
|
|
tracking_remote = run_cmd(["git", "config", "branch." + local_branch + ".remote"]) |
|
|
|
return run_cmd(["git", "config", "remote." + tracking_remote + ".url"]) |
|
|
|
return run_cmd(["git", "config", "remote." + tracking_remote + ".url"]) |
|
|
|
except subprocess.CalledProcessError: # Not on a branch, fallback |
|
|
|
except subprocess.CalledProcessError: # Not on a branch, fallback |
|
|
|
return run_cmd_default(["git", "config", "--get", "remote.origin.url"]) or "" |
|
|
|
return run_cmd_default(["git", "config", "--get", "remote.origin.url"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@cache |
|
|
|
@cache |
|
|
@ -132,3 +137,4 @@ if __name__ == "__main__": |
|
|
|
print(f"Branch: {get_branch()}") |
|
|
|
print(f"Branch: {get_branch()}") |
|
|
|
print(f"Short branch: {get_short_branch()}") |
|
|
|
print(f"Short branch: {get_short_branch()}") |
|
|
|
print(f"Prebuilt: {is_prebuilt()}") |
|
|
|
print(f"Prebuilt: {is_prebuilt()}") |
|
|
|
|
|
|
|
print(f"Commit date: {get_commit_date()}") |
|
|
|