Support remote branch listing and tracked checkout from branch picker #126
Mergedjuliusmarmingemerged 7 commits into
main fromcodething/deb940eemerged by juliusmarminge View on GitHub- apps/server/src/git/Layers/GitCore.ts line 96OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -76,3 +76,21 @@7676 return filePath.length > 0 ? filePath : null;7777 }787879+function parseBranchLine(line: string): { name: string; current: boolean } | null {80+ const trimmed = line.trim();81+ if (trimmed.length === 0) return null;82+83+ const name = trimmed.replace(/^[*+]\s+/, "");84+ // Exclude symbolic refs like: "origin/HEAD -> origin/main".85+ if (name.includes(" -> ")) return null;86+87+ return {88+ name,89+ current: trimmed.startsWith("* "),90+ };91+}92+93+function parseRemoteTrackingCandidate(94+ branchName: string,95+): { remoteRef: string; localBranch: string } | null {96+ const separatorIndex = branchName.indexOf("/");
- apps/server/src/git/Layers/GitCore.ts line 838OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -722,0 +818,21 @@818+ },819+ ).pipe(Effect.map((result) => result.code === 0)),820+ executeGit(821+ "GitCore.checkoutBranch.localTrackingExists",822+ input.cwd,823+ ["show-ref", "--verify", "--quiet", `refs/heads/${trackingCandidate.localBranch}`],824+ {825+ timeoutMs: 5_000,826+ allowNonZeroExit: true,827+ },828+ ).pipe(Effect.map((result) => result.code === 0)),829+ ],830+ { concurrency: "unbounded" },831+ );832+833+ const checkoutArgs =834+ localInputExists835+ ? ["checkout", input.branch]836+ : remoteExists && !localTrackingExists837+ ? ["checkout", "--track", trackingCandidate.remoteRef]838+ : ["checkout", localTrackingExists ? trackingCandidate.localBranch : input.branch];
- apps/server/src/git/Layers/GitCore.ts line 149Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -78,0 +84,21 @@84+ // Exclude symbolic refs like: "origin/HEAD -> origin/main".85+ if (name.includes(" -> ")) return null;86+87+ return {88+ name,89+ current: trimmed.startsWith("* "),90+ };91+}92+93+function parseRemoteTrackingCandidate(94+ branchName: string,95+): { remoteRef: string; localBranch: string } | null {96+ const separatorIndex = branchName.indexOf("/");97+ if (separatorIndex <= 0 || separatorIndex === branchName.length - 1) return null;98+ const localBranch = branchName.slice(separatorIndex + 1).trim();99+ if (localBranch.length === 0) return null;100+ return {101+ remoteRef: branchName.trim(),102+ localBranch,103+ };104+}
- @@ -820,3 +803,20 @@820803 <TooltipPopup side="top">{prStatus.tooltip}</TooltipPopup>821804 </Tooltip>822805 )}806+ {threadStatus && (807+ <span808+ className={`inline-flex items-center gap-1 text-[10px] ${threadStatus.colorClass}`}809+ >810+ <span811+ className={`h-1.5 w-1.5 rounded-full ${threadStatus.dotClass} ${812+ threadStatus.pulse ? "animate-pulse" : ""813+ }`}814+ />815+ <span className="hidden md:inline">{threadStatus.label}</span>816+ </span>817+ )}818+ <span className="min-w-0 flex-1 truncate text-xs">819+ {thread.title}820+ </span>821+ </div>822+ <div className="ml-auto flex shrink-0 items-center gap-1.5">
- apps/server/src/git/Layers/GitCore.ts lines 83 to 85OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -76,3 +76,10 @@7676 return filePath.length > 0 ? filePath : null;7777 }787879+function parseBranchLine(line: string): { name: string; current: boolean } | null {80+ const trimmed = line.trim();81+ if (trimmed.length === 0) return null;82+83+ const name = trimmed.replace(/^[*+]\s+/, "");84+ // Exclude symbolic refs like: "origin/HEAD -> origin/main".85+ if (name.includes(" -> ")) return null;apps/server/src/git/Layers/GitCore.ts line 947Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -722,0 +872,21 @@872+873+ const localTrackingBranch =874+ remoteExists875+ ? yield* executeGit(876+ "GitCore.checkoutBranch.localTrackingBranch",877+ input.cwd,878+ ["for-each-ref", "--format=%(refname:short)\t%(upstream:short)", "refs/heads"],879+ {880+ timeoutMs: 5_000,881+ allowNonZeroExit: true,882+ },883+ ).pipe(884+ Effect.map((result) =>885+ result.code === 0886+ ? parseTrackingBranchByUpstreamRef(result.stdout, input.branch)887+ : null,888+ ),889+ )890+ : null;891+892+ const checkoutArgs =
- apps/web/src/components/BranchToolbar.logic.ts line 17Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -8,3 +8,20 @@88 queryBranches: ReadonlyArray<GitBranch> | undefined;99 }101011+export function deriveLocalBranchNameFromRemoteRef(12+ branchName: string,13+ remoteName?: string,14+): string {15+ if (remoteName) {16+ const remotePrefix = `${remoteName}/`;17+ if (branchName.startsWith(remotePrefix) && branchName.length > remotePrefix.length) {18+ return branchName.slice(remotePrefix.length);19+ }20+ }21+22+ const firstSeparatorIndex = branchName.indexOf("/");23+ if (firstSeparatorIndex <= 0 || firstSeparatorIndex === branchName.length - 1) {24+ return branchName;25+ }26+ return branchName.slice(firstSeparatorIndex + 1);27+}
juliusmarminge merged this1af43db
juliusmarminge closed this
- @@ -8,3 +8,10 @@88 queryBranches: ReadonlyArray<GitBranch> | undefined;99 }101011+export function deriveLocalBranchNameFromRemoteRef(branchName: string): string {12+ const firstSeparatorIndex = branchName.indexOf("/");13+ if (firstSeparatorIndex <= 0 || firstSeparatorIndex === branchName.length - 1) {14+ return branchName;15+ }16+ return branchName.slice(firstSeparatorIndex + 1);17+}
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.