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
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,39 @@ Once users have generated their desired commit message, they can proceed to comm

### Ignore files

You can remove files from being sent to OpenAI by creating a `.opencommitignore` file. For example:
You can remove files from being sent to OpenAI by creating ignore files. OpenCommit supports both local and global ignore files:

#### Local ignore file

Create a `.opencommitignore` file in your project root:

```ignorelang
path/to/large-asset.zip
**/*.jpg
docs/generated/
*.generated.ts
```

#### Global ignore file

Create a global `.opencommitignore` file in your home directory (`~/.opencommitignore`) to ignore files across all projects:

```ignorelang
*.log
*.tmp
.DS_Store
node_modules/
.env
.env.local
dist/
build/
coverage/
.vscode/
.idea/
```

**Priority:** Local ignore rules are applied after global rules. Both files use [gitignore syntax](https://git-scm.com/docs/gitignore#_pattern_format).

This helps prevent opencommit from uploading artifacts and large files.

By default, opencommit ignores files matching: `*-lock.*` and `*.lock`
Expand Down
28 changes: 21 additions & 7 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { execa } from 'execa';
import { readFileSync } from 'fs';
import { readFileSync, existsSync } from 'fs';
import ignore, { Ignore } from 'ignore';
import { join } from 'path';
import { homedir } from 'os';
import { outro, spinner } from '@clack/prompts';

export const assertGitRepo = async () => {
Expand All @@ -18,14 +19,27 @@ export const assertGitRepo = async () => {

export const getOpenCommitIgnore = async (): Promise<Ignore> => {
const gitDir = await getGitDir();

const ig = ignore();

try {
ig.add(
readFileSync(join(gitDir, '.opencommitignore')).toString().split('\n')
);
} catch (e) {}
const globalIgnorePath = join(homedir(), '.opencommitignore');
if (existsSync(globalIgnorePath)) {
try {
const globalIgnoreContent = readFileSync(globalIgnorePath, 'utf8');
ig.add(globalIgnoreContent.split('\n'));
} catch (e) {
// do nothing
}
}

const localIgnorePath = join(gitDir, '.opencommitignore');
if (existsSync(localIgnorePath)) {
try {
const localIgnoreContent = readFileSync(localIgnorePath, 'utf8');
ig.add(localIgnoreContent.split('\n'));
} catch (e) {
// do nothing
}
}

return ig;
};
Expand Down