Skip to content
Open
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/sync-gitignore-symlinks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bomb.sh/tools": patch
---

`sync` CLI command writes `.gitignore` entries that match the skill symlinks it creates, so linked skills no longer show up as untracked.
55 changes: 53 additions & 2 deletions src/commands/sync.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { lstat, readlink, realpath, symlink as fsSymlink } from 'node:fs/promises';
import { lstat, readdir, readlink, realpath, symlink as fsSymlink } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { x, type Output } from 'tinyexec';
import { describe, it, expect, vi } from 'vitest';
import { createFixture, createMocks } from '../test-utils/index.ts';
import {
Expand Down Expand Up @@ -221,14 +222,64 @@ describe('sync', () => {
expect(await fixture.text('project/skills/mine.md')).toBe('user-owned');

const gitignore = await fixture.text('project/.gitignore');
expect(gitignore).toContain('.agents/skills/lifecycle/');
expect(gitignore).toMatch(/^\.agents\/skills\/lifecycle$/m);
expect(gitignore).not.toMatch(/^skills\//m);

expect(await fixture.text('project/AGENTS.md')).toContain(
'[.agents/skills/lifecycle/SKILL.md](.agents/skills/lifecycle/SKILL.md)',
);
});

it('writes .gitignore entries that git applies to the skill links', async () => {
const fixture = await createFixture({
project: { 'package.json': '{ "name": "my-app" }' },
});
const project = await realpath(fileURLToPath(new URL('project/', fixture.root)));
createMocks({ env: { INIT_CWD: project } });
vi.spyOn(console, 'info').mockImplementation(() => {});
// Keep the user's global and system git config (and its excludes file) out of the result.
const git = (args: string[]): PromiseLike<Output> =>
x('git', args, {
nodeOptions: {
cwd: project,
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1' },
},
throwOnError: true,
});
await git(['init', '--quiet']);

await sync({ args: [] });

expect(await readdir(new URL('project/.agents/skills/', fixture.root))).toContain('lifecycle');
const status = await git(['status', '--porcelain', '--untracked-files=all', '--', '.agents']);
expect(status.stdout).toBe('');
});

it('rewrites .gitignore entries from older syncs and keeps content outside the block', async () => {
const fixture = await createFixture({
project: {
'package.json': '{ "name": "my-app" }',
'.gitignore':
'node_modules\n\n# bsh:skills\n.agents/skills/lifecycle/\n.agents/skills/removed/\n# /bsh:skills\n\ndist\n',
},
});
const project = await realpath(fileURLToPath(new URL('project/', fixture.root)));
createMocks({ env: { INIT_CWD: project } });
vi.spyOn(console, 'info').mockImplementation(() => {});

await sync({ args: [] });

const linked = (await readdir(new URL('project/.agents/skills/', fixture.root))).toSorted();
const gitignore = await fixture.text('project/.gitignore');
const match = /^node_modules\n\n# bsh:skills\n([\s\S]*)\n# \/bsh:skills\n\ndist\n$/.exec(
gitignore!,
);
expect(match).not.toBeNull();
expect(match![1]!.split('\n').toSorted()).toEqual(
linked.map((name) => `.agents/skills/${name}`),
);
});

it('removes the legacy skills directory once it is empty', async () => {
const fixture = await createFixture({
project: {
Expand Down
3 changes: 2 additions & 1 deletion src/commands/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ async function updateGitignore(options: { root: URL; skills: SkillInfo[] }): Pro
const gitignorePath = new URL('.gitignore', root);
let content = (await hfs.text(gitignorePath)) ?? '';

const lines = skills.map((s) => `${SKILLS_DIR}${s.name}/`);
// No trailing slash: git treats a symlink as a file, and `dir/` only matches directories.
const lines = skills.map((s) => `${SKILLS_DIR}${s.name}`);
const section = [GITIGNORE_START, ...lines, GITIGNORE_END].join('\n');

const startIdx = content.indexOf(GITIGNORE_START);
Expand Down
Loading