Skip to content

chore(scripts): safe-worktree.sh — 防 stale baseline 白工守門#450

Merged
s123104 merged 1 commit into
mainfrom
chore/safe-worktree-preflight
Jun 26, 2026
Merged

chore(scripts): safe-worktree.sh — 防 stale baseline 白工守門#450
s123104 merged 1 commit into
mainfrom
chore/safe-worktree-preflight

Conversation

@s123104

@s123104 s123104 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

背景

Codex + Cursor 三方 review(Q2)一致最高信心建議:把「branch 起點機械化驗證」固化成守門,根治多次 stale-baseline 白工(例:被 #445 取代的 cluster PR、被吞併的 #444)。

內容

scripts/safe-worktree.sh <new-branch> <worktree-path> [base-branch]:

  • git fetch --all --prune 後,一律以 origin/<base> 最新 tip 為基準建立 worktree → 過期本地同名分支在物理上無法成為起點。
  • 本地/遠端 SHA 不一致時印出 ahead/behind 警告。

驗證

  • bash -n 語法檢查通過;功能測試從 origin/main tip 建立並驗證 HEAD SHA 一致、清理成功。

後續(可選):在 AGENTS.md/CLAUDE.md 補一行「開 worktree 一律用 scripts/safe-worktree.sh」。

🤖 Generated with Claude Code

- 一律以 origin/<base> 最新 tip 建立 worktree,過期本地分支無法成為起點
- fetch --all --prune + 本地/遠端 SHA 一致性檢查,落後時警告
- 根治多次從過期分支開 worktree 導致 PR 白工的事故(Codex/Cursor review Q2)

測試:bash -n 語法檢查通過;功能測試從 origin/main tip 建立並驗證 SHA 一致
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cec3af0541

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/safe-worktree.sh
REMOTE_REF="origin/${BASE}"

echo "🔄 git fetch --all --prune ..."
git fetch --all --prune

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Fetch only the target origin branch

When a developer has any extra remote that is unavailable or requires credentials, git fetch --all --prune fails before the script reaches the origin/<base> validation because set -e is enabled. I checked git fetch -h, which defines --all as “fetch from all remotes”; this script only needs origin/${BASE}, so one bad side remote blocks safe worktree creation even though the intended base is fetchable.

Useful? React with 👍 / 👎.

@s123104 s123104 merged commit 6a5529f into main Jun 26, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant