exec-staged 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/lib/stage.js +19 -15
- package/package.json +1 -1
- package/src/lib/stage.ts +19 -15
package/README.md
CHANGED
package/dist/lib/stage.js
CHANGED
|
@@ -66,19 +66,19 @@ export class Stage {
|
|
|
66
66
|
this.logger.log('⚠️ Git installation not found!');
|
|
67
67
|
throw new Error('git installation not found');
|
|
68
68
|
}
|
|
69
|
-
if (!version || semver.
|
|
69
|
+
if (!version || semver.lt(version, '2.22.0')) {
|
|
70
70
|
this.logger.log('⚠️ Unsupported git version!');
|
|
71
71
|
throw new Error('unsupported git version');
|
|
72
72
|
}
|
|
73
|
-
let
|
|
73
|
+
let prefix;
|
|
74
74
|
try {
|
|
75
|
-
|
|
75
|
+
prefix = this.git(['rev-parse', '--show-prefix']).trim();
|
|
76
76
|
}
|
|
77
77
|
catch (error) {
|
|
78
78
|
this.logger.log('⚠️ Not a git repository!');
|
|
79
79
|
throw new Error('cwd is not a git repository');
|
|
80
80
|
}
|
|
81
|
-
if (
|
|
81
|
+
if (prefix !== '') {
|
|
82
82
|
this.logger.log('⚠️ Not in git root directory!');
|
|
83
83
|
throw new Error('cwd is not a git repository root directory');
|
|
84
84
|
}
|
|
@@ -135,7 +135,8 @@ export class Stage {
|
|
|
135
135
|
this.git([
|
|
136
136
|
'diff',
|
|
137
137
|
'--binary',
|
|
138
|
-
'--
|
|
138
|
+
'--src-prefix=a/',
|
|
139
|
+
'--dst-prefix=b/',
|
|
139
140
|
// skip deleted files because patch doesn't apply if they're modified
|
|
140
141
|
'--diff-filter=d',
|
|
141
142
|
'--no-color',
|
|
@@ -236,16 +237,19 @@ export class Stage {
|
|
|
236
237
|
'-m',
|
|
237
238
|
STAGED_CHANGES_COMMIT_MESSAGE,
|
|
238
239
|
]);
|
|
239
|
-
// apply patch containing unstaged changes
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
240
|
+
// apply patch containing unstaged changes.
|
|
241
|
+
// `--allow-empty` could be used here, but it was not added to `git apply`
|
|
242
|
+
// until 2.35.0 (January 2022), so we skip the call when the patch is empty.
|
|
243
|
+
if (fs.statSync(this.patchPath).size > 0) {
|
|
244
|
+
this.git([
|
|
245
|
+
'apply',
|
|
246
|
+
'--recount',
|
|
247
|
+
'--unidiff-zero',
|
|
248
|
+
'--whitespace=nowarn',
|
|
249
|
+
'--3way',
|
|
250
|
+
this.patchPath,
|
|
251
|
+
]);
|
|
252
|
+
}
|
|
249
253
|
// unstaged deletions are not included in the patch and must be handled
|
|
250
254
|
// separately because the patch cannot be applied if such files are
|
|
251
255
|
// modified by tasks; use force: true to handle cases where the file
|
package/package.json
CHANGED
package/src/lib/stage.ts
CHANGED
|
@@ -85,21 +85,21 @@ export class Stage {
|
|
|
85
85
|
throw new Error('git installation not found');
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
if (!version || semver.
|
|
88
|
+
if (!version || semver.lt(version, '2.22.0')) {
|
|
89
89
|
this.logger.log('⚠️ Unsupported git version!');
|
|
90
90
|
throw new Error('unsupported git version');
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
let
|
|
93
|
+
let prefix: string;
|
|
94
94
|
|
|
95
95
|
try {
|
|
96
|
-
|
|
96
|
+
prefix = this.git(['rev-parse', '--show-prefix']).trim();
|
|
97
97
|
} catch (error) {
|
|
98
98
|
this.logger.log('⚠️ Not a git repository!');
|
|
99
99
|
throw new Error('cwd is not a git repository');
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
if (
|
|
102
|
+
if (prefix !== '') {
|
|
103
103
|
this.logger.log('⚠️ Not in git root directory!');
|
|
104
104
|
throw new Error('cwd is not a git repository root directory');
|
|
105
105
|
}
|
|
@@ -185,7 +185,8 @@ export class Stage {
|
|
|
185
185
|
this.git([
|
|
186
186
|
'diff',
|
|
187
187
|
'--binary',
|
|
188
|
-
'--
|
|
188
|
+
'--src-prefix=a/',
|
|
189
|
+
'--dst-prefix=b/',
|
|
189
190
|
// skip deleted files because patch doesn't apply if they're modified
|
|
190
191
|
'--diff-filter=d',
|
|
191
192
|
'--no-color',
|
|
@@ -310,16 +311,19 @@ export class Stage {
|
|
|
310
311
|
STAGED_CHANGES_COMMIT_MESSAGE,
|
|
311
312
|
]);
|
|
312
313
|
|
|
313
|
-
// apply patch containing unstaged changes
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
314
|
+
// apply patch containing unstaged changes.
|
|
315
|
+
// `--allow-empty` could be used here, but it was not added to `git apply`
|
|
316
|
+
// until 2.35.0 (January 2022), so we skip the call when the patch is empty.
|
|
317
|
+
if (fs.statSync(this.patchPath).size > 0) {
|
|
318
|
+
this.git([
|
|
319
|
+
'apply',
|
|
320
|
+
'--recount',
|
|
321
|
+
'--unidiff-zero',
|
|
322
|
+
'--whitespace=nowarn',
|
|
323
|
+
'--3way',
|
|
324
|
+
this.patchPath,
|
|
325
|
+
]);
|
|
326
|
+
}
|
|
323
327
|
|
|
324
328
|
// unstaged deletions are not included in the patch and must be handled
|
|
325
329
|
// separately because the patch cannot be applied if such files are
|