Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): fall back to remote-tracking ref for merge detection when no local default branch exists

Adam Eivya14ff5cb707f
diff --git a/server/services/getBranches.test.js b/server/services/getBranches.test.js
index a792b79037..9901371709 100644
--- a/server/services/getBranches.test.js
+++ b/server/services/getBranches.test.js
@@ -92,4 +92,44 @@ describe('getBranches', () => {
expect(dev.merged).toBe(false);
});
+
+ it('falls back to the remote-tracking ref when there is no local branch matching the default (single-branch clone / feature-only worktree)', async () => {
+ execGit.mockImplementation((args) => {
+ if (args[0] === 'branch' && args.includes('-vv')) {
+ return Promise.resolve({
+ stdout: ['*|feature-a||', ' |feature-b||'].join('\n'),
+ stderr: '',
+ exitCode: 0
+ });
+ }
+ if (args[0] === 'symbolic-ref') {
+ // origin/HEAD resolves to main, but there is no local `main` branch
+ return Promise.resolve({ stdout: 'origin/main', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'rev-parse' && args.includes('--verify')) {
+ return Promise.resolve({ stdout: 'abc123', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'branch' && args.includes('--list')) {
+ return Promise.resolve({ stdout: ' feature-a\n feature-b\n', stderr: '', exitCode: 0 });
+ }
+ if (args[0] === 'branch' && args.includes('--merged')) {
+ if (args[2] === 'main') {
+ // No local `main` ref exists — git errors out
+ return Promise.resolve({ stdout: '', stderr: 'fatal: malformed object name main', exitCode: 128 });
+ }
+ if (args[2] === 'origin/main') {
+ return Promise.resolve({ stdout: 'feature-b\n', stderr: '', exitCode: 0 });
+ }
+ }
+ return Promise.resolve({ stdout: '', stderr: '', exitCode: 0 });
+ });
+
+ const branches = await getBranches('/fake/dir');
+ const featureA = branches.find(b => b.name === 'feature-a');
+ const featureB = branches.find(b => b.name === 'feature-b');
+
+ expect(featureA.current).toBe(true);
+ expect(featureA.merged).toBe(false);
+ expect(featureB.merged).toBe(true);
+ });
});
diff --git a/server/services/git.js b/server/services/git.js
index d3df6d43f7..7a1f8e6e4c 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -608,11 +608,22 @@ export async function getBranches(dir) {
const protectedSet = new Set(PROTECTED_BRANCHES);
protectedSet.add(defaultBranch);
- const mergedResult = await execGit(
+ // Prefer the local default-branch ref, but fall back to the remote-tracking
+ // ref when there's no local branch by that name (single-branch clones,
+ // feature-only worktrees) — otherwise `git branch --merged <defaultBranch>`
+ // fails and every branch silently reports unmerged.
+ let mergedResult = await execGit(
['branch', '--merged', defaultBranch, '--format=%(refname:short)'],
dir,
{ ignoreExitCode: true }
);
+ if (mergedResult.exitCode !== 0) {
+ mergedResult = await execGit(
+ ['branch', '--merged', `origin/${defaultBranch}`, '--format=%(refname:short)'],
+ dir,
+ { ignoreExitCode: true }
+ );
+ }
const mergedSet = new Set(mergedResult.stdout.trim().split('\n').filter(Boolean));
return result.stdout.trim().split('\n').filter(Boolean)