feat(dev-env): shell scripts (git-hooks, worktree, deploy, regtest, nav) and smoke test
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
7960f82494
commit
dbd9e76027
13 changed files with 2496 additions and 0 deletions
154
modules/dev-env/scripts/pr-helpers.sh
Normal file
154
modules/dev-env/scripts/pr-helpers.sh
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
#!/usr/bin/env bash
|
||||
# dev-env: upstream PR worktree helpers
|
||||
#
|
||||
# Provides prb / prc / prl. Each PR gets a throwaway worktree at
|
||||
# ${UPSTREAM_PRS_DIR}/<repo>-<branch> based on upstream/main (or
|
||||
# master), ready to push to the `github-fork` remote and open a PR.
|
||||
#
|
||||
# Ported from ~/dev/.devenv.d/90-upstream-prs.sh; reads paths from
|
||||
# /etc/dev-env/config.sh.
|
||||
|
||||
# Shared config loader (_devenv_load_config) lives in /etc/dev-env/lib.sh.
|
||||
if [[ -r /etc/dev-env/lib.sh ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
source /etc/dev-env/lib.sh
|
||||
fi
|
||||
|
||||
# Create a PR worktree at ${UPSTREAM_PRS_DIR}/<repo>-<branch>.
|
||||
#
|
||||
# Usage: git-pr-branch <repo-name> <branch-name>
|
||||
git-pr-branch() {
|
||||
_devenv_load_config
|
||||
local repo_name="${1:-}"
|
||||
local branch_name="${2:-}"
|
||||
local repos_dir="${REPOS_DIR:-$DEV_ROOT/repos}"
|
||||
local prs_dir="${UPSTREAM_PRS_DIR:-$DEV_ROOT/upstream-prs}"
|
||||
|
||||
if [[ -z "$repo_name" || -z "$branch_name" ]]; then
|
||||
echo "Usage: git-pr-branch <repo-name> <branch-name>"
|
||||
echo "Example: git-pr-branch lnbits fix-invoice-bug"
|
||||
echo ""
|
||||
echo "Creates a worktree at $prs_dir/<repo>-<branch>"
|
||||
echo "based on upstream/main, ready for an upstream PR."
|
||||
return 1
|
||||
fi
|
||||
|
||||
local bare_repo="$repos_dir/${repo_name}.git"
|
||||
local pr_path="$prs_dir/${repo_name}-${branch_name}"
|
||||
|
||||
if [[ ! -d "$bare_repo" ]]; then
|
||||
echo "Repo not found: $bare_repo"
|
||||
echo "Available repos:"
|
||||
ls -1 "$repos_dir"/*.git 2>/dev/null | xargs -n1 basename | sed 's/\.git$//'
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -d "$pr_path" ]]; then
|
||||
echo "PR worktree already exists: $pr_path"
|
||||
echo "To remove it: git-pr-cleanup $repo_name $branch_name"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Fetch upstream
|
||||
echo "Fetching upstream..."
|
||||
git -C "$bare_repo" fetch upstream 2>/dev/null || {
|
||||
echo "No 'upstream' remote on $repo_name — cannot create PR branch"
|
||||
return 1
|
||||
}
|
||||
|
||||
# Determine base branch (main or master)
|
||||
local base_branch="main"
|
||||
git -C "$bare_repo" show-ref --verify --quiet "refs/remotes/upstream/main" \
|
||||
|| base_branch="master"
|
||||
|
||||
echo "Creating branch '$branch_name' from upstream/$base_branch..."
|
||||
git -C "$bare_repo" branch "$branch_name" "upstream/$base_branch" 2>/dev/null \
|
||||
|| git -C "$bare_repo" branch -f "$branch_name" "upstream/$base_branch"
|
||||
|
||||
mkdir -p "$prs_dir"
|
||||
git -C "$bare_repo" worktree add "$pr_path" "$branch_name"
|
||||
|
||||
if ! git -C "$bare_repo" remote get-url github-fork &>/dev/null; then
|
||||
echo ""
|
||||
echo "Note: 'github-fork' remote not configured for $repo_name."
|
||||
echo "Add it with:"
|
||||
echo " git -C $bare_repo remote add github-fork git@github.com:${GITHUB_FORK_USER:-<user>}/${repo_name}.git"
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
|
||||
Ready! Your PR worktree is at:
|
||||
cd $pr_path
|
||||
|
||||
Workflow:
|
||||
1. cd $pr_path
|
||||
2. Edit, test, commit
|
||||
3. git push github-fork $branch_name
|
||||
4. Open the PR on GitHub (against upstream/$base_branch)
|
||||
5. After merge: git-pr-cleanup $repo_name $branch_name
|
||||
EOF
|
||||
}
|
||||
|
||||
# Remove a PR worktree after the PR is merged (or abandoned).
|
||||
git-pr-cleanup() {
|
||||
_devenv_load_config
|
||||
local repo_name="${1:-}"
|
||||
local branch_name="${2:-}"
|
||||
local repos_dir="${REPOS_DIR:-$DEV_ROOT/repos}"
|
||||
local prs_dir="${UPSTREAM_PRS_DIR:-$DEV_ROOT/upstream-prs}"
|
||||
|
||||
if [[ -z "$repo_name" || -z "$branch_name" ]]; then
|
||||
echo "Usage: git-pr-cleanup <repo-name> <branch-name>"
|
||||
echo ""
|
||||
echo "Active PR worktrees:"
|
||||
ls -1 "$prs_dir" 2>/dev/null || echo " (none)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local bare_repo="$repos_dir/${repo_name}.git"
|
||||
local pr_path="$prs_dir/${repo_name}-${branch_name}"
|
||||
|
||||
[[ -d "$pr_path" ]] || { echo "PR worktree not found: $pr_path"; return 1; }
|
||||
|
||||
echo "Removing worktree: $pr_path"
|
||||
git -C "$bare_repo" worktree remove "$pr_path"
|
||||
|
||||
echo "Deleting branch: $branch_name"
|
||||
if ! git -C "$bare_repo" branch -d "$branch_name" 2>/dev/null; then
|
||||
echo " Branch '$branch_name' is not fully merged."
|
||||
read -r -p " Force-delete it (unmerged commits will be lost)? [y/N] " -n 1 REPLY
|
||||
echo
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
git -C "$bare_repo" branch -D "$branch_name"
|
||||
else
|
||||
echo " Kept branch '$branch_name' (worktree already removed)."
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Done."
|
||||
}
|
||||
|
||||
# List all active PR worktrees.
|
||||
git-pr-list() {
|
||||
_devenv_load_config
|
||||
local prs_dir="${UPSTREAM_PRS_DIR:-$DEV_ROOT/upstream-prs}"
|
||||
|
||||
echo "=== Active PR Worktrees ==="
|
||||
if [[ -d "$prs_dir" && -n "$(ls -A "$prs_dir" 2>/dev/null)" ]]; then
|
||||
for pr_dir in "$prs_dir"/*; do
|
||||
[[ -d "$pr_dir" ]] || continue
|
||||
local name branch status
|
||||
name="$(basename "$pr_dir")"
|
||||
branch="$(git -C "$pr_dir" branch --show-current 2>/dev/null || echo '?')"
|
||||
status="$(git -C "$pr_dir" status -sb 2>/dev/null | head -1 || echo '?')"
|
||||
printf " %-40s %s %s\n" "$name" "$branch" "$status"
|
||||
done
|
||||
else
|
||||
echo " (none)"
|
||||
fi
|
||||
}
|
||||
|
||||
alias prb='git-pr-branch'
|
||||
alias prc='git-pr-cleanup'
|
||||
alias prl='git-pr-list'
|
||||
Loading…
Add table
Add a link
Reference in a new issue