Skip to content

Commit 3f7025d

Browse files
authored
feat: add support for .opencommitignore file (#22)
* feat: add support for .opencommitignore
1 parent d793bf1 commit 3f7025d

File tree

5 files changed

+40
-8
lines changed

5 files changed

+40
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ application.log
1010
logfile.log
1111
uncaughtExceptions.log
1212
.vscode
13-
src/*.json
13+
src/*.json
14+
.idea

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ is translated to :
9898
git commit -m "${generatedMessage}" --no-verify
9999
```
100100

101+
### Ignore files
102+
You can ignore files from submission to OpenAI by creating a `.opencommitignore` file. For example:
103+
104+
```ignorelang
105+
path/to/large-asset.zip
106+
**/*.jpg
107+
```
108+
109+
This is useful for preventing opencommit from uploading artifacts and large files.
110+
111+
By default, opencommit ignores files matching: `*-lock.*` and `*.lock`
112+
101113
## Git hook
102114

103115
You can set OpenCommit as Git [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) hook. Hook integrates with you IDE Source Control and allows you edit the message before commit.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opencommit",
3-
"version": "1.1.11",
3+
"version": "1.1.16",
44
"description": "GPT CLI to auto-generate impressive commits in 1 second. Killing lame commits with AI 🤯🔫",
55
"keywords": [
66
"git",
@@ -64,6 +64,7 @@
6464
"chalk": "^5.2.0",
6565
"cleye": "^1.3.2",
6666
"execa": "^7.0.0",
67+
"ignore": "^5.2.4",
6768
"ini": "^3.0.1",
6869
"inquirer": "^9.1.4",
6970
"openai": "^3.2.1"

src/utils/git.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { execa } from 'execa';
22
import { outro, spinner } from '@clack/prompts';
3+
import { readFileSync } from 'fs';
4+
import ignore, { Ignore } from 'ignore';
35

46
export const assertGitRepo = async () => {
57
try {
@@ -13,16 +15,32 @@ export const assertGitRepo = async () => {
1315
// (file) => `:(exclude)${file}`
1416
// );
1517

18+
export const getOpenCommitIgnore = (): Ignore => {
19+
const ig = ignore();
20+
21+
try {
22+
ig.add(readFileSync('.opencommitignore').toString().split('\n'));
23+
} catch(e) {}
24+
25+
return ig;
26+
}
27+
1628
export const getStagedFiles = async (): Promise<string[]> => {
1729
const { stdout: files } = await execa('git', [
1830
'diff',
1931
'--name-only',
20-
'--cached'
32+
'--cached',
2133
]);
2234

23-
if (!files) return [];
35+
const filesList = files.split('\n');
36+
37+
38+
const ig = getOpenCommitIgnore();
39+
const allowedFiles = filesList.filter(file => !ig.ignores(file));
40+
41+
if (!allowedFiles) return [];
2442

25-
return files.split('\n').sort();
43+
return allowedFiles.sort();
2644
};
2745

2846
export const getChangedFiles = async (): Promise<string[]> => {

0 commit comments

Comments
 (0)