Skip to content

Commit 5060e6b

Browse files
authored
Merge pull request #1748 from Yeachan-Heo/omx-issue-1747-omc-gitignore
Prevent .omc state artifacts from being committed by default
2 parents 927da52 + f23f328 commit 5060e6b

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

scripts/setup-claude-md.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,38 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1313
SCRIPT_PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
1414
CANONICAL_CLAUDE_MD="${SCRIPT_PLUGIN_ROOT}/docs/CLAUDE.md"
1515

16+
ensure_local_omc_git_exclude() {
17+
local exclude_path
18+
19+
if ! exclude_path=$(git rev-parse --git-path info/exclude 2>/dev/null); then
20+
echo "Skipped OMC git exclude setup (not a git repository)"
21+
return 0
22+
fi
23+
24+
mkdir -p "$(dirname "$exclude_path")"
25+
26+
local block_start="# BEGIN OMC local artifacts"
27+
28+
if [ -f "$exclude_path" ] && grep -Fq "$block_start" "$exclude_path"; then
29+
echo "OMC git exclude already configured"
30+
return 0
31+
fi
32+
33+
if [ -f "$exclude_path" ] && [ -s "$exclude_path" ]; then
34+
printf '\n' >> "$exclude_path"
35+
fi
36+
37+
cat >> "$exclude_path" <<'EOF'
38+
# BEGIN OMC local artifacts
39+
.omc/*
40+
!.omc/skills/
41+
!.omc/skills/**
42+
# END OMC local artifacts
43+
EOF
44+
45+
echo "Configured git exclude for local .omc artifacts (preserving .omc/skills/)"
46+
}
47+
1648
# Determine target path
1749
if [ "$MODE" = "local" ]; then
1850
mkdir -p .claude
@@ -145,6 +177,10 @@ if ! grep -q '<!-- OMC:START -->' "$TARGET_PATH" || ! grep -q '<!-- OMC:END -->'
145177
exit 1
146178
fi
147179

180+
if [ "$MODE" = "local" ]; then
181+
ensure_local_omc_git_exclude
182+
fi
183+
148184
# Extract new version and report
149185
NEW_VERSION=$(grep -m1 'OMC:VERSION:' "$TARGET_PATH" 2>/dev/null | sed -E 's/.*OMC:VERSION:([^ ]+).*/\1/' || true)
150186
if [ -z "$NEW_VERSION" ]; then

skills/omc-setup/phases/01-install-claude-md.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ partially reconstruct CLAUDE.md.
3232
After running the script, verify the target file contains both markers. If marker validation
3333
fails, stop and report the failure instead of writing CLAUDE.md manually.
3434

35+
For `local` installs inside a git repository, the script also seeds `.git/info/exclude` with an OMC block that ignores local `.omc/*` artifacts by default while preserving `.omc/skills/` for version-controlled project skills.
36+
3537
**FALLBACK** if curl fails:
3638
Tell user to manually download from:
3739
https://raw.githubusercontent.com/Yeachan-Heo/oh-my-claudecode/main/docs/CLAUDE.md
@@ -46,6 +48,7 @@ If `CONFIG_TARGET` is `local`:
4648
```
4749
OMC Project Configuration Complete
4850
- CLAUDE.md: Updated with latest configuration from GitHub at ./.claude/CLAUDE.md
51+
- Git excludes: Added local `.omc/*` ignore rules to `.git/info/exclude` (keeps `.omc/skills/` trackable)
4952
- Backup: Previous CLAUDE.md backed up (if existed)
5053
- Scope: PROJECT - applies only to this project
5154
- Hooks: Provided by plugin (no manual installation needed)

src/__tests__/setup-claude-md-script.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,88 @@ This is a summarized CLAUDE.md without markers.
100100
expect(`${result.stdout}\n${result.stderr}`).toContain('missing required OMC markers');
101101
expect(existsSync(join(fixture.projectRoot, '.claude', 'CLAUDE.md'))).toBe(false);
102102
});
103+
104+
it('adds a local git exclude block for .omc artifacts while preserving .omc/skills', () => {
105+
const fixture = createPluginFixture(`<!-- OMC:START -->
106+
<!-- OMC:VERSION:9.9.9 -->
107+
108+
# Canonical CLAUDE
109+
Use the real docs file.
110+
<!-- OMC:END -->
111+
`);
112+
113+
const gitInit = spawnSync('git', ['init'], {
114+
cwd: fixture.projectRoot,
115+
env: {
116+
...process.env,
117+
HOME: fixture.homeRoot,
118+
},
119+
encoding: 'utf-8',
120+
});
121+
expect(gitInit.status).toBe(0);
122+
123+
const result = spawnSync('bash', [fixture.scriptPath, 'local'], {
124+
cwd: fixture.projectRoot,
125+
env: {
126+
...process.env,
127+
HOME: fixture.homeRoot,
128+
},
129+
encoding: 'utf-8',
130+
});
131+
132+
expect(result.status).toBe(0);
133+
134+
const excludePath = join(fixture.projectRoot, '.git', 'info', 'exclude');
135+
expect(existsSync(excludePath)).toBe(true);
136+
137+
const excludeContents = readFileSync(excludePath, 'utf-8');
138+
expect(excludeContents).toContain('# BEGIN OMC local artifacts');
139+
expect(excludeContents).toContain('.omc/*');
140+
expect(excludeContents).toContain('!.omc/skills/');
141+
expect(excludeContents).toContain('!.omc/skills/**');
142+
expect(excludeContents).toContain('# END OMC local artifacts');
143+
});
144+
145+
it('does not duplicate the local git exclude block on repeated local setup runs', () => {
146+
const fixture = createPluginFixture(`<!-- OMC:START -->
147+
<!-- OMC:VERSION:9.9.9 -->
148+
149+
# Canonical CLAUDE
150+
Use the real docs file.
151+
<!-- OMC:END -->
152+
`);
153+
154+
const gitInit = spawnSync('git', ['init'], {
155+
cwd: fixture.projectRoot,
156+
env: {
157+
...process.env,
158+
HOME: fixture.homeRoot,
159+
},
160+
encoding: 'utf-8',
161+
});
162+
expect(gitInit.status).toBe(0);
163+
164+
const firstRun = spawnSync('bash', [fixture.scriptPath, 'local'], {
165+
cwd: fixture.projectRoot,
166+
env: {
167+
...process.env,
168+
HOME: fixture.homeRoot,
169+
},
170+
encoding: 'utf-8',
171+
});
172+
expect(firstRun.status).toBe(0);
173+
174+
const secondRun = spawnSync('bash', [fixture.scriptPath, 'local'], {
175+
cwd: fixture.projectRoot,
176+
env: {
177+
...process.env,
178+
HOME: fixture.homeRoot,
179+
},
180+
encoding: 'utf-8',
181+
});
182+
expect(secondRun.status).toBe(0);
183+
184+
const excludeContents = readFileSync(join(fixture.projectRoot, '.git', 'info', 'exclude'), 'utf-8');
185+
expect(excludeContents.match(/# BEGIN OMC local artifacts/g)).toHaveLength(1);
186+
});
103187
});

0 commit comments

Comments
 (0)