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

fix: preserve local merge commits during rebase recovery

Adam Eivy4eb4eae7b12b
diff --git a/server/services/git.js b/server/services/git.js
index e6e8c52da6..fc7b2d42e0 100644
--- a/server/services/git.js
+++ b/server/services/git.js
@@ -1200,6 +1200,10 @@ async function rebaseAndPushDefaultBranchAdmitted(dir) {
if (!(Number(counts.stdout.trim().split(/\s+/)[0]) > 0)) {
return refused('The default branch has no local commits ahead of origin.');
}
+ const localMerges = await execGit(['rev-list', '--merges', `${remoteRef}..HEAD`], dir);
+ if (localMerges.stdout.trim()) {
+ return refused('Local history contains merge commits. Reconcile these with an agent or in the terminal to preserve merge resolutions; nothing was rebased or pushed.');
+ }
// Fetch + rebase is the explicit-origin equivalent of pull --rebase. Avoid
// pull.ff / upstream configuration and never move dirty work via autostash.
const rebased = await execGit(['rebase', '--no-autostash', remoteRef], dir, { ignoreExitCode: true });
diff --git a/server/services/git.rebasePush.test.js b/server/services/git.rebasePush.test.js
index 96c3e1e134..68eef85561 100644
--- a/server/services/git.rebasePush.test.js
+++ b/server/services/git.rebasePush.test.js
@@ -73,6 +73,22 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('rebase and push the default branch', ()
expect((await execGit(['status', '--porcelain'], repo)).stdout).toBe('');
});
+ it('refuses a local merge containing work recorded only in the merge commit', async () => {
+ const repo = await prepare();
+ await execGit(['checkout', '-b', 'feature/merged'], repo);
+ await commitFile(repo, 'feature.txt', 'feature change\n');
+ await execGit(['checkout', 'main'], repo);
+ await execGit(['merge', '--no-ff', '--no-commit', 'feature/merged'], repo);
+ await commitFile(repo, 'merge-only.txt', 'keep this merge resolution\n');
+ const [local, remote] = await Promise.all([head(repo), head(sandbox.origin)]);
+ expect(await rebaseAndPushDefaultBranch(repo)).toMatchObject({
+ success: false, pushed: false, error: expect.stringContaining('merge commits'),
+ });
+ expect(await head(repo)).toBe(local);
+ expect(await head(sandbox.origin)).toBe(remote);
+ expect(await readFile(join(repo, 'merge-only.txt'), 'utf8')).toBe('keep this merge resolution\n');
+ });
+
it('leaves another in-progress rebase untouched', async () => {
const repo = await prepare({ conflict: true });
await execGit(['fetch', 'origin'], repo);
diff --git a/server/services/git.rebasePushConcurrency.test.js b/server/services/git.rebasePushConcurrency.test.js
index 9c8b4cb5bc..8720c812d0 100644
--- a/server/services/git.rebasePushConcurrency.test.js
+++ b/server/services/git.rebasePushConcurrency.test.js
@@ -36,7 +36,7 @@ describe('rebase and push checkout ownership', () => {
if (command === 'rev-parse --abbrev-ref HEAD') return ok('main');
if (command === 'symbolic-ref --short refs/remotes/origin/HEAD') return ok('origin/main');
if (command.startsWith('rev-parse --verify')) return ok(SHA);
- if (args[0] === 'rev-list') return ok('1\t2');
+ if (args[0] === 'rev-list' && args.includes('--count')) return ok('1\t2');
return ok();
});
const result = rebaseAndPushDefaultBranch(tmpdir());