Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
fe11dd4
feat(desktop): add option to use existing branch when creating worktree
chasemcdo Jan 22, 2026
bf8076a
refactor(desktop): simplify worktree creation code
chasemcdo Jan 22, 2026
fce5d35
move button
chasemcdo Jan 23, 2026
9989e95
resuse existing search select
chasemcdo Jan 23, 2026
d974df1
refactor(desktop): use object params for git utility functions
chasemcdo Jan 23, 2026
36d1099
fix(desktop): fix popover scroll and interaction inside dialog
Kitenite Jan 23, 2026
ed28815
feat(desktop): add PR URL support in workspace creation
Kitenite Jan 23, 2026
7dcc382
fix(desktop): reopen existing workspace when opening PR URL
Kitenite Jan 23, 2026
86802ec
refactor(desktop): reorder Existing tab - PR, Branches, then Worktrees
Kitenite Jan 23, 2026
dcf58b3
refactor(desktop): extract ExistingWorktreesList into smaller components
Kitenite Jan 23, 2026
02363e7
style(desktop): increase workspace modal width to 440px
Kitenite Jan 23, 2026
06e20fa
feat(desktop): show local/remote status for branches
Kitenite Jan 23, 2026
981a157
fix(desktop): initialize workspace after PR checkout
Kitenite Jan 23, 2026
0987b3d
refactor(desktop): extract PR workspace helpers for better factoring
Kitenite Jan 23, 2026
b0dbca7
fix(desktop): handle existing local branch when opening fork PR
Kitenite Jan 23, 2026
dd58e24
refactor(desktop): remove redundant comments from workspace code
Kitenite Jan 23, 2026
4f9efd4
Address high concerns
Kitenite Jan 23, 2026
a214391
chore: update bun.lock after rebase from main
Kitenite Jan 23, 2026
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
121 changes: 92 additions & 29 deletions apps/desktop/src/lib/trpc/routers/projects/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ export const createProjectsRouter = (getWindow: () => BrowserWindow | null) => {
async ({
input,
}): Promise<{
branches: Array<{ name: string; lastCommitDate: number }>;
branches: Array<{
name: string;
lastCommitDate: number;
isLocal: boolean;
isRemote: boolean;
}>;
defaultBranch: string;
}> => {
const project = localDb
Expand All @@ -298,64 +303,122 @@ export const createProjectsRouter = (getWindow: () => BrowserWindow | null) => {

const branchSummary = await git.branch(["-a"]);

const localBranches: string[] = [];
const remoteBranches: string[] = [];
const localBranchSet = new Set<string>();
const remoteBranchSet = new Set<string>();

for (const name of Object.keys(branchSummary.branches)) {
if (name.startsWith("remotes/origin/")) {
if (name === "remotes/origin/HEAD") continue;
const remoteName = name.replace("remotes/origin/", "");
remoteBranches.push(remoteName);
remoteBranchSet.add(remoteName);
} else {
localBranches.push(name);
localBranchSet.add(name);
}
}

// Get branch dates for sorting
let branches: Array<{ name: string; lastCommitDate: number }> = [];
// Get branch dates for sorting - fetch from both local and remote
const branchMap = new Map<
string,
{ lastCommitDate: number; isLocal: boolean; isRemote: boolean }
>();

// Determine which ref pattern to use based on whether origin exists
const refPattern = hasOrigin ? "refs/remotes/origin/" : "refs/heads/";
// First, get remote branch dates (if origin exists)
if (hasOrigin) {
try {
const remoteBranchInfo = await git.raw([
"for-each-ref",
"--sort=-committerdate",
"--format=%(refname:short) %(committerdate:unix)",
"refs/remotes/origin/",
]);

for (const line of remoteBranchInfo.trim().split("\n")) {
if (!line) continue;
const lastSpaceIdx = line.lastIndexOf(" ");
let branch = line.substring(0, lastSpaceIdx);
const timestamp = Number.parseInt(
line.substring(lastSpaceIdx + 1),
10,
);

// Normalize remote branch names
if (branch.startsWith("origin/")) {
branch = branch.replace("origin/", "");
}

if (branch === "HEAD") continue;

branchMap.set(branch, {
lastCommitDate: timestamp * 1000,
isLocal: localBranchSet.has(branch),
isRemote: true,
});
}
} catch {
// Fallback for remote branches
for (const name of remoteBranchSet) {
branchMap.set(name, {
lastCommitDate: 0,
isLocal: localBranchSet.has(name),
isRemote: true,
});
}
}
Comment on lines +327 to +366

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.

⚠️ Potential issue | 🟡 Minor

Don’t swallow git ref lookup failures silently.

Both git.raw fallbacks drop the error context, which makes diagnosing repo issues hard. Please log with a contextual prefix and keep the fallback behavior. As per coding guidelines.

🛠️ Suggested fix
-						} catch {
+						} catch (err) {
+							console.warn(
+								"[projects/getBranches] Failed to read remote branch dates; falling back to zero timestamps",
+								err,
+							);
 							// Fallback for remote branches
 							for (const name of remoteBranchSet) {
 								branchMap.set(name, {
 									lastCommitDate: 0,
 									isLocal: localBranchSet.has(name),
 									isRemote: true,
 								});
 							}
 						}
-					} catch {
+					} catch (err) {
+						console.warn(
+							"[projects/getBranches] Failed to read local branch dates; falling back to zero timestamps",
+							err,
+						);
 						// Fallback for local branches
 						for (const name of localBranchSet) {
 							if (!branchMap.has(name)) {
 								branchMap.set(name, {
 									lastCommitDate: 0,
 									isLocal: true,
 									isRemote: remoteBranchSet.has(name),
 								});
 							}
 						}
 					}

Also applies to: 402-412

🤖 Prompt for AI Agents
In `@apps/desktop/src/lib/trpc/routers/projects/projects.ts` around lines 327 -
366, The catch block that wraps the git.raw call building remoteBranchInfo
currently swallows errors; update the catch to capture the exception (e) and log
a contextual message including the error details before continuing with the
existing fallback population of branchMap (referencing git.raw,
remoteBranchInfo, branchMap, remoteBranchSet, localBranchSet); apply the same
change to the other identical try/catch handling (the block around lines
402-412) so failures are logged with a clear prefix and full error context while
preserving the fallback behavior.

}

// Then, add local-only branches
try {
const branchInfo = await git.raw([
const localBranchInfo = await git.raw([
"for-each-ref",
"--sort=-committerdate",
"--format=%(refname:short) %(committerdate:unix)",
refPattern,
"refs/heads/",
]);

const seen = new Set<string>();
for (const line of branchInfo.trim().split("\n")) {
for (const line of localBranchInfo.trim().split("\n")) {
if (!line) continue;
const lastSpaceIdx = line.lastIndexOf(" ");
let branch = line.substring(0, lastSpaceIdx);
const branch = line.substring(0, lastSpaceIdx);
const timestamp = Number.parseInt(
line.substring(lastSpaceIdx + 1),
10,
);

// Normalize remote branch names
if (branch.startsWith("origin/")) {
branch = branch.replace("origin/", "");
}

// Skip duplicates and HEAD
if (seen.has(branch)) continue;
if (branch === "HEAD") continue;
seen.add(branch);

branches.push({
name: branch,
lastCommitDate: timestamp * 1000,
});
// Only add if not already in map (remote takes precedence for date)
if (!branchMap.has(branch)) {
branchMap.set(branch, {
lastCommitDate: timestamp * 1000,
isLocal: true,
isRemote: remoteBranchSet.has(branch),
});
} else {
// Update isLocal flag for branches that exist both locally and remotely
const existing = branchMap.get(branch)!;
existing.isLocal = true;
}
Comment on lines +371 to +400

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.

⚠️ Potential issue | 🟡 Minor

Merge local timestamps into existing branch entries.

When a branch already exists in branchMap, you only flip isLocal, so local commit dates are dropped (or left at 0 from the remote fallback). This can misorder branches when local is ahead or when the remote fetch fails. Consider merging timestamps with Math.max.

🛠️ Suggested fix
-						if (!branchMap.has(branch)) {
-							branchMap.set(branch, {
-								lastCommitDate: timestamp * 1000,
-								isLocal: true,
-								isRemote: remoteBranchSet.has(branch),
-							});
-						} else {
-							// Update isLocal flag for branches that exist both locally and remotely
-							const existing = branchMap.get(branch)!;
-							existing.isLocal = true;
-						}
+						if (!branchMap.has(branch)) {
+							branchMap.set(branch, {
+								lastCommitDate: timestamp * 1000,
+								isLocal: true,
+								isRemote: remoteBranchSet.has(branch),
+							});
+						} else {
+							// Update isLocal flag and keep the freshest timestamp
+							const existing = branchMap.get(branch)!;
+							existing.isLocal = true;
+							existing.lastCommitDate = Math.max(
+								existing.lastCommitDate,
+								timestamp * 1000,
+							);
+						}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const localBranchInfo = await git.raw([
"for-each-ref",
"--sort=-committerdate",
"--format=%(refname:short) %(committerdate:unix)",
refPattern,
"refs/heads/",
]);
const seen = new Set<string>();
for (const line of branchInfo.trim().split("\n")) {
for (const line of localBranchInfo.trim().split("\n")) {
if (!line) continue;
const lastSpaceIdx = line.lastIndexOf(" ");
let branch = line.substring(0, lastSpaceIdx);
const branch = line.substring(0, lastSpaceIdx);
const timestamp = Number.parseInt(
line.substring(lastSpaceIdx + 1),
10,
);
// Normalize remote branch names
if (branch.startsWith("origin/")) {
branch = branch.replace("origin/", "");
}
// Skip duplicates and HEAD
if (seen.has(branch)) continue;
if (branch === "HEAD") continue;
seen.add(branch);
branches.push({
name: branch,
lastCommitDate: timestamp * 1000,
});
// Only add if not already in map (remote takes precedence for date)
if (!branchMap.has(branch)) {
branchMap.set(branch, {
lastCommitDate: timestamp * 1000,
isLocal: true,
isRemote: remoteBranchSet.has(branch),
});
} else {
// Update isLocal flag for branches that exist both locally and remotely
const existing = branchMap.get(branch)!;
existing.isLocal = true;
}
const localBranchInfo = await git.raw([
"for-each-ref",
"--sort=-committerdate",
"--format=%(refname:short) %(committerdate:unix)",
"refs/heads/",
]);
for (const line of localBranchInfo.trim().split("\n")) {
if (!line) continue;
const lastSpaceIdx = line.lastIndexOf(" ");
const branch = line.substring(0, lastSpaceIdx);
const timestamp = Number.parseInt(
line.substring(lastSpaceIdx + 1),
10,
);
if (branch === "HEAD") continue;
// Only add if not already in map (remote takes precedence for date)
if (!branchMap.has(branch)) {
branchMap.set(branch, {
lastCommitDate: timestamp * 1000,
isLocal: true,
isRemote: remoteBranchSet.has(branch),
});
} else {
// Update isLocal flag and keep the freshest timestamp
const existing = branchMap.get(branch)!;
existing.isLocal = true;
existing.lastCommitDate = Math.max(
existing.lastCommitDate,
timestamp * 1000,
);
}
🤖 Prompt for AI Agents
In `@apps/desktop/src/lib/trpc/routers/projects/projects.ts` around lines 371 -
400, The code that parses localBranchInfo and updates branchMap currently only
sets existing.isLocal = true when a branch already exists, which discards the
local lastCommitDate; update the logic in the block handling existing entries
(the branchMap.get(branch) branch) to merge lastCommitDate using
Math.max(existing.lastCommitDate ?? 0, timestamp * 1000) and set isLocal = true
and isRemote = remoteBranchSet.has(branch) as needed so local timestamps take
precedence when more recent (refer to localBranchInfo parsing, branchMap,
lastCommitDate, isLocal, and remoteBranchSet).

}
} catch {
// Fallback: just list branches without dates
const branchList = hasOrigin ? remoteBranches : localBranches;
branches = branchList.map((name) => ({ name, lastCommitDate: 0 }));
// Fallback for local branches
for (const name of localBranchSet) {
if (!branchMap.has(name)) {
branchMap.set(name, {
lastCommitDate: 0,
isLocal: true,
isRemote: remoteBranchSet.has(name),
});
}
}
}

const branches = Array.from(branchMap.entries()).map(
([name, data]) => ({
name,
...data,
}),
);

// Sync with remote in case the default branch changed (e.g. master -> main)
const remoteDefaultBranch = await refreshDefaultBranch(
project.mainRepoPath,
Expand Down
Loading