Skip to content

Commit e1d70fa

Browse files
committed
feat: add --git-ignore option
When set, excludes git ignored files from patch creation.
1 parent 50f73bd commit e1d70fa

File tree

7 files changed

+685
-3
lines changed

7 files changed

+685
-3
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ team.
130130
- `--patch-dir`
131131

132132
Specify the name for the directory in which to put the patch files.
133+
134+
- `--git-ignore`
135+
136+
By default, patch-package creates patches disregarding your git-ignore
137+
settings. Set this option to exclude git-ignored files from patches.
133138

134139
#### Nested packages
135140

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# make sure errors stop the script
2+
set -e
3+
4+
echo "add patch-package"
5+
yarn add $1
6+
7+
echo "intitialize a git repo"
8+
git init
9+
10+
addedFileName=addedFileName.md
11+
addedFile=node_modules/lodash/$addedFileName
12+
addedIgnoredFileName=addedIgnoredFileName.md
13+
addedIgnoredFile=node_modules/lodash/$addedIgnoredFileName
14+
removedFileName=fp/__.js
15+
removedFile=node_modules/lodash/$removedFileName
16+
removedIgnoredFileName=fp.js
17+
removedIgnoredFile=node_modules/lodash/$removedIgnoredFileName
18+
19+
echo "add not ignored file"
20+
echo "this should be patched" > $addedFile
21+
22+
echo "add ignored file"
23+
echo "this should be ginored" > $addedIgnoredFile
24+
25+
echo "remove a not ignored file"
26+
rm $removedFile
27+
28+
echo "remove an ignored file"
29+
rm $removedIgnoredFile
30+
31+
echo "config .gitignore"
32+
echo $addedIgnoredFileName > .gitignore
33+
echo $removedIgnoredFileName >> .gitignore
34+
35+
echo "generate patch file"
36+
npx patch-package lodash --git-ignore
37+
38+
echo "remove node_modules"
39+
rm -rf node_modules
40+
41+
echo "resintall and patch node_modules"
42+
yarn
43+
npx patch-package
44+
45+
echo "check that not ignored file was added"
46+
ls $addedFile
47+
48+
echo "check that ignored file was not added"
49+
if ls $addedIgnoredFile
50+
then
51+
exit 1
52+
fi
53+
54+
echo "check that not ignored file was removed"
55+
if ls $removedFile
56+
then
57+
exit 1
58+
fi
59+
60+
echo "check that ignored file was not removed"
61+
ls $removedIgnoredFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { runIntegrationTest } from "../runIntegrationTest"
2+
3+
runIntegrationTest({
4+
projectName: "exclude-git-ignored-files",
5+
shouldProduceSnapshots: false,
6+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "exclude-git-ignored-files",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"dependencies": {
12+
"lodash": "4.17.4"
13+
}
14+
}

0 commit comments

Comments
 (0)