summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-01-28 10:26:06 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2025-01-29 16:05:35 +0100
commit967434c8d6ab0bf3cedd6a25e65bf2b0059d0901 (patch)
treea47a196b778e512651fd61d8aee5c9e6bcf5a24b /bin
parentcfd04ad2d7fee5d4a3fb3c6df16e611a7c9fc6ab (diff)
downloadjustbuild-967434c8d6ab0bf3cedd6a25e65bf2b0059d0901.tar.gz
just-lock: Run commit check command only on existing repositories
While there, improve docstrings of methods operating on Git repositories to specify when the underlying Git repositories are expected to be present.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/just-lock.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/bin/just-lock.py b/bin/just-lock.py
index 7e108d27..54d7a0fb 100755
--- a/bin/just-lock.py
+++ b/bin/just-lock.py
@@ -242,7 +242,8 @@ def git_root(*, upstream: Optional[str]) -> str:
def git_keep(commit: str, *, upstream: Optional[str],
fail_context: str) -> None:
- """Keep commit by tagging it."""
+ """Keep commit by tagging it. It is a user error if the referenced Git
+ repository does not exist."""
git_env = {**os.environ, **GIT_NOBODY_ENV}
run_cmd(g_LAUNCHER + [
g_GIT, "tag", "-f", "-m", "Keep referenced tree alive",
@@ -276,11 +277,14 @@ def ensure_git_init(*,
def git_commit_present(commit: str, *, upstream: Optional[str]) -> bool:
- """Check if commit is present in specified Git repository."""
- return run_cmd(g_LAUNCHER + [g_GIT, "show", "--oneline", commit],
- stdout=subprocess.DEVNULL,
- cwd=git_root(upstream=upstream),
- fail_context=None)[1] == 0
+ """Check if commit is present in specified Git repository. Does not require
+ the repository to exist, in which case it returns false."""
+ root: str = git_root(upstream=upstream)
+ return (os.path.exists(root)
+ and run_cmd(g_LAUNCHER + [g_GIT, "show", "--oneline", commit],
+ stdout=subprocess.DEVNULL,
+ cwd=root,
+ fail_context=None)[1] == 0)
def git_url_is_path(url: str) -> Optional[str]:
@@ -299,7 +303,8 @@ def git_fetch(*, from_repo: Optional[str], to_repo: Optional[str],
fetchable: str, fail_context: Optional[str]) -> bool:
"""Fetch from a given repository a fetchable object (branch or commit) into
another repository. A None value for a repository means the Git cache
- repository is used. Returns success flag of fetch command."""
+ repository is used. Returns success flag of fetch command. It is a user
+ error if the referenced Git repositories do not exist."""
if from_repo is None:
from_repo = git_root(upstream=None)
else:
@@ -452,7 +457,8 @@ def import_to_git(target: str, *, repo_type: str, content_id: str,
def git_subtree(*, tree: str, subdir: str, upstream: Optional[str],
fail_context: str) -> str:
- """Get Git-tree identifier in a Git tree by subdirectory path."""
+ """Get Git-tree identifier in a Git tree by subdirectory path. It is a user
+ error if the referenced Git repository does not exist."""
if os.path.normpath(subdir) == ".":
return tree
return run_cmd(