continue-custom/src/util/git.ts
2025-07-20 18:30:09 -07:00

47 lines
No EOL
1 KiB
TypeScript

import { execSync } from "child_process";
/**
* Get the git remote URL for the current repository
* @param remote The remote name (defaults to 'origin')
* @returns The remote URL or null if not found
*/
export function getGitRemoteUrl(remote: string = "origin"): string | null {
try {
const result = execSync(`git remote get-url ${remote}`, {
encoding: "utf-8",
cwd: process.cwd(),
stdio: "pipe",
});
return result.trim();
} catch {
return null;
}
}
/**
* Check if current directory is a git repository
*/
export function isGitRepo(): boolean {
try {
execSync("git rev-parse --is-inside-work-tree", {
stdio: "ignore",
cwd: process.cwd(),
});
return true;
} catch {
return false;
}
}
/**
* Get the current repository URL, falling back to local path if not a git repo
* @returns Git remote URL or local path
*/
export function getRepoUrl(): string {
if (!isGitRepo()) {
return process.cwd();
}
const remoteUrl = getGitRemoteUrl();
return remoteUrl || process.cwd();
}