Fixed setups

This commit is contained in:
Henner M. Kruse
2026-08-04 11:15:24 +02:00
parent e485d33f00
commit 6c6fc35a1f
9 changed files with 609 additions and 288 deletions
+36 -24
View File
@@ -17,41 +17,53 @@ is_allowed_subcommand() {
return 1
}
# Resolve a repo's absolute path.
# Resolve a repo's absolute path. Only ever looks at configured repos —
# never falls back to the current working directory, regardless of
# whether it happens to be a git repo itself. This is deliberate: the
# current directory being a git repo is not a signal this script acts on.
# - If a name is given, look it up in the config file's "repos" array.
# - If no name is given, default to $PWD, but only if it's actually inside
# a git work tree.
# Never accepts a raw path from the caller directly — named repos always go
# through the config file, so the whitelisted script can't be pointed at an
# arbitrary directory outside what's configured (or the current project
# directory Claude Code itself already scoped the session to).
# - If no name is given, look at the config: exactly one registered repo
# is used automatically; zero or more than one is an error requiring an
# explicit --repo.
# Never accepts a raw path from the caller directly — only ever a name
# resolved through the config file, so the whitelisted script can't be
# pointed at an arbitrary directory outside what's configured.
resolve_repo_path() {
local repo_name="${1:-}"
if [ -n "$repo_name" ]; then
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: no configuration found at $CONFIG_FILE. Run setup first, or omit the repo name to use the current directory." >&2
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "Error: python3 is required to parse the config file." >&2
exit 1
fi
python3 - "$CONFIG_FILE" "$repo_name" << 'PYEOF'
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: no configuration found at $CONFIG_FILE. Register at least one repo first (run setup, or ask to register one)." >&2
exit 1
fi
if ! command -v python3 >/dev/null 2>&1; then
echo "Error: python3 is required to parse the config file." >&2
exit 1
fi
python3 - "$CONFIG_FILE" "$repo_name" << 'PYEOF'
import json, sys
config_file, repo_name = sys.argv[1], sys.argv[2]
with open(config_file) as f:
cfg = json.load(f)
repos = cfg.get("repos", [])
match = [r for r in repos if r.get("name") == repo_name]
if not match:
sys.stderr.write(f"Error: no repo named '{repo_name}' in config.\n")
if repo_name:
match = [r for r in repos if r.get("name") == repo_name]
if not match:
names = ", ".join(r.get("name", "?") for r in repos) or "(none)"
sys.stderr.write(f"Error: no repo named '{repo_name}' in config. Registered: {names}\n")
sys.exit(1)
print(match[0]["path"])
elif len(repos) == 1:
print(repos[0]["path"])
elif len(repos) == 0:
sys.stderr.write("Error: no repos registered in config. Register at least one first.\n")
sys.exit(1)
else:
names = ", ".join(r.get("name", "?") for r in repos)
sys.stderr.write(f"Error: multiple repos configured ({names}); specify one with --repo <name>.\n")
sys.exit(1)
print(match[0]["path"])
PYEOF
else
echo "$PWD"
fi
}
# Validate that a resolved path is a real, existing directory that is