Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions scripts/pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,39 @@ cd "$(dirname "$0")/.."

BRANCH="${1:-}"
MSG="${2:-}"
shift 2 || true

if [[ -z "${BRANCH}" || -z "${MSG}" ]]; then
echo "usage: scripts/pr.sh <branch-name> <commit-message>" >&2
echo "usage: scripts/pr.sh <branch-name> <commit-message> [paths...]" >&2
exit 2
fi

# Guard: refuse to run if there are nested git repos (prevents submodule/gitlink accidents)
if find . -mindepth 2 -maxdepth 6 -name .git -type d | grep -q .; then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Detect .git files when guarding nested repos

The new safety guard only searches for .git directories (find ... -name .git -type d), but Git submodules and linked worktrees use a .git file, so this check silently misses the common nested-repo case it is meant to block. In repositories that include submodules, the script will continue and can still stage gitlink updates via git add -u, which undermines the hardening goal and can lead to accidental submodule pointer commits.

Useful? React with 👍 / 👎.

echo "[error] nested .git directories detected under repo root; refuse to 'git add' blindly" >&2
find . -mindepth 2 -maxdepth 6 -name .git -type d >&2
exit 3
fi

./scripts/hygiene.sh

git checkout -b "${BRANCH}"
git add -A
# Create branch if missing; otherwise just checkout
if git show-ref --verify --quiet "refs/heads/${BRANCH}"; then
git checkout "${BRANCH}"
else
git checkout -b "${BRANCH}"
fi

# Safer staging:
# - if paths provided, stage only those
# - else stage tracked changes only (no new untracked surprises)
if [[ "$#" -gt 0 ]]; then
git add -- "$@"
else
git add -u
fi

git commit -m "${MSG}"
git push -u origin "${BRANCH}"

gh pr create --repo SocioProphet/agentplane --base main --head "${BRANCH}" --title "${MSG}" --body "${MSG}"
gh pr create --base main --head "${BRANCH}" --title "${MSG}" --body "${MSG}"