feat: allow configuration of multiple repos in kiauh.cfg (#668)

* remove existing simple_config_parser directory

* Squashed 'kiauh/core/submodules/simple_config_parser/' content from commit da22e6a

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: da22e6ad9ca4bc121c39dc3bc6c63175a72e78a2

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from da22e6a..9ae5749

9ae5749 fix: comment out file writing in test
1ac4e3d refactor: improve section writing

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 9ae574930dfe82107a3712c7c72b3aa777588996

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 9ae5749..53e8408

53e8408 fix: do not add a blank line before writing a section header
dc77569 test: add test for removing option before writing

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 53e840853f12318dcac68196fb74c1843cb75808

* Squashed 'kiauh/core/submodules/simple_config_parser/' changes from 53e8408..4a6e5f2

4a6e5f2 refactor: full rework of the internal storage of the parsed config

git-subtree-dir: kiauh/core/submodules/simple_config_parser
git-subtree-split: 4a6e5f23cb1f298f0a3efbf042186b16c91763c7

* refactor!: switching repos now offers list of repositories to choose from

this rework aligns more with the feature provided in kiauh v5.

Signed-off-by: Dominik Willner <th33xitus@gmail.com>

---------

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2025-03-29 16:18:20 +01:00
committed by GitHub
parent b99e6612e2
commit 88742ab496
28 changed files with 876 additions and 377 deletions

View File

@@ -29,6 +29,7 @@ from utils.git_utils import (
get_local_tags,
get_remote_commit,
get_repo_name,
get_repo_url,
)
from utils.instance_utils import get_instances
from utils.sys_utils import (
@@ -133,11 +134,14 @@ def get_install_status(
status = 1 # incomplete
org, repo = get_repo_name(repo_dir)
repo_url = get_repo_url(repo_dir) if repo_dir.exists() else None
return ComponentStatus(
status=status,
instances=instances,
owner=org,
repo=repo,
repo_url=repo_url,
branch=branch,
local=get_local_commit(repo_dir),
remote=get_remote_commit(repo_dir),

View File

@@ -58,15 +58,17 @@ def git_clone_wrapper(
raise GitException(f"Error removing existing repository: {e.strerror}")
def git_pull_wrapper(repo: str, target_dir: Path) -> None:
# !todo: remove url parameter, as it is not really required. may be a reason to remove this function completely
def git_pull_wrapper(url: str, target_dir: Path) -> None:
"""
A function that updates a repository using git pull.
:param repo: The repository to update.
:param url: The repo url - only used for logging.
:param target_dir: The directory of the repository.
:return: None
"""
Logger.print_status(f"Updating repository '{repo}' ...")
_repo = f"'{url}'" if url else ""
Logger.print_status(f"Updating repository {_repo}...")
try:
git_cmd_pull(target_dir)
except CalledProcessError:
@@ -337,3 +339,25 @@ def rollback_repository(repo_dir: Path, instance: Type[InstanceType]) -> None:
Logger.print_error(f"An error occured during repo rollback:\n{e}")
InstanceManager.start_all(instances)
def get_repo_url(repo_dir: Path) -> str | None:
"""
Get the remote repository URL for a git repository
:param repo_dir: Path to the git repository
:return: URL of the remote repository or None if not found
"""
if not repo_dir.exists():
return None
try:
result = run(
["git", "config", "--get", "remote.origin.url"],
cwd=repo_dir,
capture_output=True,
text=True,
check=True,
)
return result.stdout.strip()
except CalledProcessError:
return None