mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-01 19:25:10 +02:00
feat: add remote slug helper and auto-gitignore for .gstack/
- getRemoteSlug() in config.ts: parses git remote origin → owner-repo format - browse/bin/remote-slug: shell helper for SKILL.md use (BSD sed compatible) - ensureStateDir() now appends .gstack/ to project .gitignore if not present - setup creates ~/.gstack/projects/ global state directory - 7 new tests: 4 gitignore behavior + 3 remote slug parsing
This commit is contained in:
@@ -89,6 +89,42 @@ export function ensureStateDir(config: BrowseConfig): void {
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
// Ensure .gstack/ is in the project's .gitignore
|
||||
const gitignorePath = path.join(config.projectDir, '.gitignore');
|
||||
try {
|
||||
const content = fs.readFileSync(gitignorePath, 'utf-8');
|
||||
if (!content.match(/^\.gstack\/?$/m)) {
|
||||
const separator = content.endsWith('\n') ? '' : '\n';
|
||||
fs.appendFileSync(gitignorePath, `${separator}.gstack/\n`);
|
||||
}
|
||||
} catch {
|
||||
// No .gitignore or unreadable — skip
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive a slug from the git remote origin URL (owner-repo format).
|
||||
* Falls back to the directory basename if no remote is configured.
|
||||
*/
|
||||
export function getRemoteSlug(): string {
|
||||
try {
|
||||
const proc = Bun.spawnSync(['git', 'remote', 'get-url', 'origin'], {
|
||||
stdout: 'pipe',
|
||||
stderr: 'pipe',
|
||||
timeout: 2_000,
|
||||
});
|
||||
if (proc.exitCode !== 0) throw new Error('no remote');
|
||||
const url = proc.stdout.toString().trim();
|
||||
// SSH: git@github.com:owner/repo.git → owner-repo
|
||||
// HTTPS: https://github.com/owner/repo.git → owner-repo
|
||||
const match = url.match(/[:/]([^/]+)\/([^/]+?)(?:\.git)?$/);
|
||||
if (match) return `${match[1]}-${match[2]}`;
|
||||
throw new Error('unparseable');
|
||||
} catch {
|
||||
const root = getGitRoot();
|
||||
return path.basename(root || process.cwd());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user