Skip to content

Commit da088cd

Browse files
authored
Merge pull request #510 from miyaoka/fix/worktree-creating-per-rootdir
fix(sidebar): isolate worktree creating state per rootDir
2 parents de4cdc5 + df89898 commit da088cd

2 files changed

Lines changed: 42 additions & 35 deletions

File tree

apps/renderer/src/features/sidebar/SidebarPane.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ useSidebarData();
5656
5757
const { confirmRef, confirmMessage, showConfirm, closeConfirm, executeConfirm } = useDialogs();
5858
59-
const { isCreating, handleWorktreeSelect, addWorktree, handleWorktreeRemove } = useWorktreeActions({
60-
showConfirm,
61-
});
59+
const { isCreatingFor, handleWorktreeSelect, addWorktree, handleWorktreeRemove } =
60+
useWorktreeActions({
61+
showConfirm,
62+
});
6263
6364
// --- 経過時間表示用の現在時刻 ---
6465
@@ -232,7 +233,7 @@ const activeRootWorktree = computed(() => {
232233
:index="i"
233234
:edit-mode="editMode"
234235
:active-dir="worktreeStore.dir"
235-
:is-creating="isCreating"
236+
:is-creating="isCreatingFor(rootDir)"
236237
:now="now"
237238
:get-resumeable-session-count="terminalStore.getResumeableSessionCount"
238239
:get-terminal-count="getTerminalCount"

apps/renderer/src/features/sidebar/features/worktree/useWorktreeActions.ts

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function useWorktreeActions({ showConfirm }: UseWorktreeActionsOptions) {
2424
const terminalStore = useTerminalStore();
2525
const repoStore = useRepoStore();
2626

27-
const isCreating = ref(false);
27+
const creatingRootDirs = ref(new Set<string>());
2828

2929
function handleWorktreeSelect(wt: WorktreeEntry) {
3030
terminalStore.viewMode = "wt";
@@ -47,37 +47,43 @@ export function useWorktreeActions({ showConfirm }: UseWorktreeActionsOptions) {
4747

4848
/** タイムスタンプで即座に新規 worktree を作成する(Task なし) */
4949
async function addWorktree(rootDir: string) {
50-
if (isCreating.value) return;
51-
isCreating.value = true;
52-
// default branch を起点にする。Swift 側で `origin/HEAD` を優先し、未設定
53-
// (remote 無し / push 前 repo)の場合は main repo root 自身の current branch に
54-
// fallback した ref を受け取り、`startPoint` に渡す。
55-
const branchResult = await tryCatch(rpcGitDefaultBranch({ dir: rootDir }));
56-
if (!branchResult.ok || branchResult.value.branch === "") {
57-
notify.error(
58-
"Failed to resolve default branch",
59-
branchResult.ok ? undefined : branchResult.error,
50+
if (creatingRootDirs.value.has(rootDir)) return;
51+
creatingRootDirs.value.add(rootDir);
52+
try {
53+
// default branch を起点にする。Swift 側で `origin/HEAD` を優先し、未設定
54+
// (remote 無し / push 前 repo)の場合は main repo root 自身の current branch に
55+
// fallback した ref を受け取り、`startPoint` に渡す。
56+
const branchResult = await tryCatch(rpcGitDefaultBranch({ dir: rootDir }));
57+
if (!branchResult.ok || branchResult.value.branch === "") {
58+
notify.error(
59+
"Failed to resolve default branch",
60+
branchResult.ok ? undefined : branchResult.error,
61+
);
62+
return;
63+
}
64+
const timestamp = generateTimestamp();
65+
const result = await tryCatch(
66+
rpcCreateWorktree({
67+
dir: rootDir,
68+
worktreeDir: timestamp,
69+
branch: timestamp,
70+
startPoint: branchResult.value.branch,
71+
}),
6072
);
61-
isCreating.value = false;
62-
return;
73+
if (result.ok && result.value.worktree !== undefined) {
74+
repoStore.appendWorktree(rootDir, result.value.worktree);
75+
terminalStore.viewMode = "wt";
76+
worktreeStore.setOpen(result.value.dir);
77+
} else {
78+
notify.error("Failed to add worktree", result.ok ? undefined : result.error);
79+
}
80+
} finally {
81+
creatingRootDirs.value.delete(rootDir);
6382
}
64-
const timestamp = generateTimestamp();
65-
const result = await tryCatch(
66-
rpcCreateWorktree({
67-
dir: rootDir,
68-
worktreeDir: timestamp,
69-
branch: timestamp,
70-
startPoint: branchResult.value.branch,
71-
}),
72-
);
73-
if (result.ok && result.value.worktree !== undefined) {
74-
repoStore.appendWorktree(rootDir, result.value.worktree);
75-
terminalStore.viewMode = "wt";
76-
worktreeStore.setOpen(result.value.dir);
77-
} else {
78-
notify.error("Failed to add worktree", result.ok ? undefined : result.error);
79-
}
80-
isCreating.value = false;
83+
}
84+
85+
function isCreatingFor(rootDir: string): boolean {
86+
return creatingRootDirs.value.has(rootDir);
8187
}
8288

8389
/** worktree 解除: 通常削除 → 失敗時に確認の上 --force */
@@ -105,7 +111,7 @@ export function useWorktreeActions({ showConfirm }: UseWorktreeActionsOptions) {
105111
}
106112

107113
return {
108-
isCreating,
114+
isCreatingFor,
109115
handleWorktreeSelect,
110116
addWorktree,
111117
handleWorktreeRemove,

0 commit comments

Comments
 (0)