Skip to content

[#398] github-issue-398-branchexists#401

Draft
nrslib wants to merge 1 commit intomainfrom
takt/398/github-issue-398-branchexists
Draft

[#398] github-issue-398-branchexists#401
nrslib wants to merge 1 commit intomainfrom
takt/398/github-issue-398-branchexists

Conversation

@nrslib
Copy link
Owner

@nrslib nrslib commented Feb 26, 2026

Summary

概要

別PCで作業の続きをしたいケースで、リモートにしかブランチが存在しない場合、現在の実装では branchExists がローカルブランチしかチェックしないため、既存ブランチが無視されて main から新規ブランチが作成されてしまう。

現状の動作

createSharedClone 内の branchExistsgit rev-parse --verify <branch> でローカルブランチのみ確認している。

  • ローカルにブランチあり → ✅ そのブランチでクローン
  • リモートにのみあり → ❌ main から新規ブランチ作成(リモートの内容が引き継がれない)
  • どこにもなし → 新規ブランチ作成

期待する動作

3段階でブランチを解決する:

  1. ローカルにブランチあり → そのブランチでクローン
  2. リモート(origin)にあり → そのブランチでクローン(git clone --branch がリモート名も解決可能)
  3. どこにもなし → ベースブランチからクローン → 新規ブランチ作成

実装方針

branchExists を拡張し、origin/<branch> もチェックする:

private static branchExists(projectDir: string, branch: string): boolean {
  // ローカルブランチ
  try {
    execFileSync('git', ['rev-parse', '--verify', branch], { cwd: projectDir, stdio: 'pipe' });
    return true;
  } catch {}
  // リモート追跡ブランチ
  try {
    execFileSync('git', ['rev-parse', '--verify', \`origin/${branch}\`], { cwd: projectDir, stdio: 'pipe' });
    return true;
  } catch {}
  return false;
}

cloneAndIsolategit clone --branch を使っており、リモートブランチ名でも解決してくれるため変更不要。

ユースケース

  • PC-A で takt がブランチを push 済み
  • PC-B で同じブランチ名を指定して takt addtakt run
  • リモートから既存ブランチが取得され、続きから作業できる

Execution Report

Piece default completed successfully.

Closes #398

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.

branchExists をリモートブランチにも対応させる(別PCでの作業継続)

1 participant