Skip to content

Commit 572d486

Browse files
Copilothotlong
andcommitted
Improve .gitignore entry detection to check complete lines
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent aff642c commit 572d486

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/cli/src/commands/init.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ export function registerInitCommand(cli) {
7575
gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
7676
}
7777

78-
// Check if the entry already exists
79-
if (!gitignoreContent.includes(gitignoreEntry)) {
78+
// Check if the entry already exists (as a complete line)
79+
const lines = gitignoreContent.split('\n').map(line => line.trim());
80+
if (!lines.includes(gitignoreEntry)) {
8081
// Add the entry with a comment
8182
const separator = gitignoreContent.trim() ? '\n\n' : '';
82-
const newContent = gitignoreContent.trim() + separator + '# ObjectDocs\n' + gitignoreEntry + '\n';
83+
const newContent = `${gitignoreContent.trim()}${separator}# ObjectDocs\n${gitignoreEntry}\n`;
8384
fs.writeFileSync(gitignorePath, newContent);
8485
console.log('📝 Added content/.objectdocs to .gitignore\n');
8586
}

0 commit comments

Comments
 (0)