mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-22 23:33:36 +05:00
feat: show actual current branch in settings menu (#588)
Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -24,6 +24,7 @@ from core.constants import (
|
||||
from core.logger import DialogType, Logger
|
||||
from core.types import ComponentStatus, StatusCode
|
||||
from utils.git_utils import (
|
||||
get_current_branch,
|
||||
get_local_commit,
|
||||
get_local_tags,
|
||||
get_remote_commit,
|
||||
@@ -103,7 +104,12 @@ def get_install_status(
|
||||
"""
|
||||
from utils.instance_utils import get_instances
|
||||
|
||||
checks = [repo_dir.exists()]
|
||||
checks = []
|
||||
branch: str = ""
|
||||
|
||||
if repo_dir.exists():
|
||||
checks.append(True)
|
||||
branch = get_current_branch(repo_dir)
|
||||
|
||||
if env_dir is not None:
|
||||
checks.append(env_dir.exists())
|
||||
@@ -131,6 +137,7 @@ def get_install_status(
|
||||
instances=instances,
|
||||
owner=org,
|
||||
repo=repo,
|
||||
branch=branch,
|
||||
local=get_local_commit(repo_dir),
|
||||
remote=get_remote_commit(repo_dir),
|
||||
)
|
||||
|
||||
@@ -87,12 +87,29 @@ def get_repo_name(repo: Path) -> Tuple[str, str]:
|
||||
orga: str = substrings[0] if substrings[0] else "-"
|
||||
name: str = substrings[1] if substrings[1] else "-"
|
||||
|
||||
return orga, name
|
||||
return orga, name.replace(".git", "")
|
||||
|
||||
except CalledProcessError:
|
||||
return "-", "-"
|
||||
|
||||
|
||||
def get_current_branch(repo: Path) -> str:
|
||||
"""
|
||||
Get the current branch of a local Git repository
|
||||
:param repo: Path to the local Git repository
|
||||
:return: Current branch
|
||||
"""
|
||||
try:
|
||||
cmd = ["git", "branch", "--show-current"]
|
||||
result: str = check_output(cmd, stderr=DEVNULL, cwd=repo).decode(
|
||||
encoding="utf-8"
|
||||
)
|
||||
return result.strip()
|
||||
|
||||
except CalledProcessError:
|
||||
return ""
|
||||
|
||||
|
||||
def get_local_tags(repo_path: Path, _filter: str | None = None) -> List[str]:
|
||||
"""
|
||||
Get all tags of a local Git repository
|
||||
@@ -209,8 +226,8 @@ def get_local_commit(repo: Path) -> str | None:
|
||||
return None
|
||||
|
||||
try:
|
||||
cmd = f"cd {repo} && git describe HEAD --always --tags | cut -d '-' -f 1,2"
|
||||
return check_output(cmd, shell=True, text=True).strip()
|
||||
cmd = "git describe HEAD --always --tags | cut -d '-' -f 1,2"
|
||||
return check_output(cmd, shell=True, text=True, cwd=repo).strip()
|
||||
except CalledProcessError:
|
||||
return None
|
||||
|
||||
@@ -220,12 +237,15 @@ def get_remote_commit(repo: Path) -> str | None:
|
||||
return None
|
||||
|
||||
try:
|
||||
# get locally checked out branch
|
||||
branch_cmd = f"cd {repo} && git branch | grep -E '\*'"
|
||||
branch = check_output(branch_cmd, shell=True, text=True)
|
||||
branch = branch.split("*")[-1].strip()
|
||||
cmd = f"cd {repo} && git describe 'origin/{branch}' --always --tags | cut -d '-' -f 1,2"
|
||||
return check_output(cmd, shell=True, text=True).strip()
|
||||
branch = get_current_branch(repo)
|
||||
cmd = f"git describe 'origin/{branch}' --always --tags | cut -d '-' -f 1,2"
|
||||
return check_output(
|
||||
cmd,
|
||||
shell=True,
|
||||
text=True,
|
||||
cwd=repo,
|
||||
stderr=DEVNULL,
|
||||
).strip()
|
||||
except CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user