Skip to content

feat: FudeCreatePRで向き先のbranchを選べるようにする - #191

Draft
kyu08 wants to merge 12 commits into
mainfrom
feat/specify-base-branch-at-pr-creation
Draft

kyu08 wants to merge 12 commits into
mainfrom
feat/specify-base-branch-at-pr-creation

Conversation

@kyu08

@kyu08 kyu08 commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

概要

:FudeCreatePRでPRの向き先(base branch)を選べるようにする。default branchを先頭に置いたpickerを開くので、そのまま<CR>を押せばdefault branchが選ばれ、別のbranchにしたいときは絞り込んで選べる。

変更内容

  • template選択の前にbase branchのpickerを表示する
    • 候補はoriginのremote-tracking branchに限る。GitHub上に存在するbranchでなければbaseにできないため、ローカルbranchは含めない
    • 並び順は「default branch → 関連branch → その他(コミット日時の新しい順)」にする
    • default branchは(default)付きで先頭に置く。Telescopeは先頭のentryを初期選択するため、何も操作せずに<CR>を押せばdefaultが選ばれる
    • 関連branchはdefault branchの直後に置く。stack運用では向き先が1つ下の層になることが多く、毎回絞り込まずに選べるようにするため
      • gh stackの親branch((stack parent))は.git/gh-stackを直接読んで求める。gh stack viewはPRの状態をネットワーク越しに更新するため使わない
      • git log上の基点branch((ancestor))は、tipがHEADの祖先でありdefault branchの祖先ではないoriginのbranchとし、HEADとのコミット数が少ない順に並べる。default branchにmerge済みのbranchは除外する
      • remoteに存在しないbranchは向き先にできないため、関連branchでもremoteに無ければ出さない
    • 現在のbranchは候補から外す。自分自身を向き先にするとghがエラーを返すため
    • remoteが無くても、diff.get_default_branch()がローカルのmain/masterから解決したdefault branchは候補に入れる。候補が1つも無いときだけpickerを出さず、従来どおりghにbaseを任せる。pickerをキャンセルするとコマンド全体を中断する
  • default branch以外を選んだときは、stacked PRにするかをYes/Noで確認する
    • Yesと答えたら、PRを作成した後にgh stack link <向き先のPR URL> <新しいPR URL>で向き先PRのstackに積む。ローカルのgh-stackで管理していないbranchでもstackにできるよう、自動判定はせずユーザーに確認する形にした
    • (stack parent)を選んだときはYesを先頭に、それ以外はNoを先頭に置く
    • 向き先は必ずPR URLで渡す。branch名で渡すと、gh stack linkがそのbranchをpushし、PRが無ければ作成してしまうため
    • 向き先にopen PRが無い場合や、linkに失敗した場合(gh-stack拡張が未導入、repoでstackが無効、向き先PRの上に別のPRがすでに積まれている、など)は、WARNを出して通常のPRのまま残す
  • 選んだbranchをgh pr create --baseに渡す(gh.create_draft_prにbase引数を追加した)
  • default titleは選んだbaseを基準に作る。「base..HEADの最初のcommit subject」を使うため、baseが変わればtitleの基準も変わる
  • floatのfooterに向き先を表示する(<CR> create draft → main | q cancel)。pickerで選んだ内容をsubmit前に確認できるようにするため
  • Telescope/vim.ui.selectの切り替えをselect_templateと共通のmodule-local関数pick_entryにまとめた。2つのpickerで同じ実装を重複させないため

テスト計画

  • 既存テスト全パス(make all)
  • 新規テスト追加: tests/fude/pr_spec.lua, tests/fude/gh_spec.lua, tests/fude/diff_spec.lua
  • 手動確認: remoteのあるrepoで:FudeCreatePRを実行し、<CR>でdefault branchが選ばれること、絞り込みで選んだbranchがfooterと作成されたPRのbaseに反映されることを確認する(Telescopeを使う経路はテスト環境で動かせないため)

備考

  • 候補は最後にgit fetchした時点のremote-tracking refsから作るため、fetchしていない新しいbranchは表示されない

Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 24, 2026 09:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

When remote candidates exist, local main/master fallback may add an invalid GitHub base branch.

Review effort: Lite
Findings: None

What changed in this PR

Adds base-branch selection to :FudeCreatePR, propagating the selection to PR creation, title generation, and the UI.

Changes:

  • Added remote branch picker with default-branch handling.
  • Added --base support to draft PR creation.
  • Updated picker logic, tests, documentation, and architecture notes.
File Description
tests/​fude/​pr_spec.lua PR creation flow and picker tests
tests/​fude/​gh_spec.lua --base argument tests
tests/​fude/​diff_spec.lua Remote branch parsing tests
README.md Feature documentation updates
lua/​fude/​pr.lua Base selection, picker flow, title, and footer integration
lua/​fude/​gh.lua Added --base argument support
lua/​fude/​diff.lua Remote branch retrieval and parsing
doc/​fude.txt :FudeCreatePR help updates
CLAUDE.md Architecture documentation updates

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 24, 2026 09:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Address the synchronous branch-distance calculation and ensure remote selections are used for title generation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)

Comment thread lua/fude/diff.lua Outdated
Copilot AI review requested due to automatic review settings September 24, 2026 11:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Address Git performance, error propagation, remote-ref consistency, and Telescope coverage concerns.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity

Open (3)

Comment thread lua/fude/gh.lua Outdated
Comment thread lua/fude/pr.lua Outdated
Copilot AI review requested due to automatic review settings September 25, 2026 09:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Unresolved moderate issues affect branch discovery performance and error reporting.

Review effort: Lite
Findings: 3 Medium severity

Open (3)

Copilot AI review requested due to automatic review settings September 25, 2026 09:48
@kyu08
kyu08 force-pushed the feat/specify-base-branch-at-pr-creation branch from eb99a59 to 44b86d9 Compare September 25, 2026 09:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

ancestor検出、default branch候補、title基準に未解決の問題があります。

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)
Resolved since last review (3)

Comment thread lua/fude/diff.lua
Comment thread lua/fude/pr.lua
Comment on lines +772 to +774
if default_branch and default_branch ~= "" and not seen[default_branch] then
table.insert(entries, { display = default_branch .. " (default)", value = default_branch, is_default = true })
seen[default_branch] = true
Copilot AI review requested due to automatic review settings September 25, 2026 10:40
@kyu08
kyu08 force-pushed the feat/specify-base-branch-at-pr-creation branch from 44b86d9 to 370d338 Compare September 25, 2026 10:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🔵 Needs a closer look

Three unresolved moderate issues affect ancestor ordering, default-branch validation, and title ref selection.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity

Open (2)

kyu08 added a commit that referenced this pull request Sep 25, 2026
Copilot AI review requested due to automatic review settings September 25, 2026 11:10
@kyu08
kyu08 force-pushed the feat/specify-base-branch-at-pr-creation branch from 370d338 to 6a8c7ec Compare September 25, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Three moderate issues remain regarding ancestor ordering, default-branch validation, and remote-based title generation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
Resolved since last review (1)

Comment thread lua/fude/diff.lua
Comment on lines +316 to +320
"--topo-order",
"--format=%D",
"--decorate-refs=refs/remotes/origin/",
"--decorate-refs-exclude=refs/remotes/origin/HEAD",
default_ref .. "..HEAD",
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.

2 participants