Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/fix-server-crash-and-cred-path.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@enbox/gitd": patch
---

Fix daemon crash when cloning nonexistent repos (process.exit in server context) and resolve credential helper by absolute path so push auth works without PATH setup.
12 changes: 4 additions & 8 deletions src/cli/repo-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export async function getRepoContext(
});

if (records.length === 0) {
console.error(`Repository "${repoName}" not found. Run \`gitd init ${repoName}\` first.`);
process.exit(1);
throw new Error(`Repository "${repoName}" not found. Run \`gitd init ${repoName}\` first.`);
}

return extractContext(records[0], repoName);
Expand All @@ -54,13 +53,11 @@ export async function getRepoContext(
const { records } = await ctx.repo.records.query('repo');

if (records.length === 0) {
console.error('No repository found. Run `gitd init <name>` first.');
process.exit(1);
throw new Error('No repository found. Run `gitd init <name>` first.');
}

if (records.length > 1) {
console.error('Multiple repositories exist. Specify one with --repo <name>, GITD_REPO env, or `git config enbox.repo <name>`.');
process.exit(1);
throw new Error('Multiple repositories exist. Specify one with --repo <name>, GITD_REPO env, or `git config enbox.repo <name>`.');
}

const data = await records[0].data.json();
Expand All @@ -85,8 +82,7 @@ export async function getRepoContextId(
function extractContext(record: any, name: string): RepoContext {
const contextId = record.contextId;
if (!contextId) {
console.error('Repository record has no contextId — this should not happen.');
process.exit(1);
throw new Error('Repository record has no contextId — this should not happen.');
}

const visibility = (record.tags?.visibility as 'public' | 'private') ?? 'public';
Expand Down
14 changes: 13 additions & 1 deletion src/git-remote/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@
* @module
*/

import { fileURLToPath } from 'node:url';
import { resolve } from 'node:path';
import { spawn } from 'node:child_process';

import { parseDidUrl } from './parse-url.js';
import { resolveGitEndpoint } from './resolve.js';

/** Resolve the absolute path to the credential helper binary (sibling file). */
function resolveCredentialHelper(): string {
const thisFile = fileURLToPath(import.meta.url);
return resolve(thisFile, '..', 'credential-main.js');
}

// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -67,8 +75,12 @@ async function main(): Promise<void> {
? 'remote-https'
: 'remote-http';

// The credential helper is a sibling .js file with a bun shebang.
// Use git's `!<command>` syntax to invoke it via bun, which avoids
// needing the file to be +x or on PATH.
const credHelper = resolveCredentialHelper();
const child = spawn('git', [
'-c', 'credential.helper=git-remote-did-credential',
'-c', `credential.helper=!bun '${credHelper}'`,
'-c', 'credential.useHttpPath=true',
helper, remoteName, endpoint.url,
], {
Expand Down
Loading