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 CHANGED
@@ -24,6 +24,10 @@ Install from npm, using your preferred package manager:
24
24
  npm install --save-dev exec-staged
25
25
  ```
26
26
 
27
+ ## Requirements
28
+
29
+ - Git >= 2.22.0
30
+
27
31
  ## Usage
28
32
 
29
33
  ### Run from the CLI
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.lte(version, '2.13.0')) {
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 gitRootDirectory;
73
+ let prefix;
74
74
  try {
75
- gitRootDirectory = this.git(['rev-parse', '--show-toplevel']).trim();
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 (gitRootDirectory !== this.cwd) {
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
- '--default-prefix',
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
- this.git([
241
- 'apply',
242
- '--allow-empty',
243
- '--recount',
244
- '--unidiff-zero',
245
- '--whitespace=nowarn',
246
- '--3way',
247
- this.patchPath,
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exec-staged",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Run commands against the current git index",
5
5
  "keywords": [
6
6
  "git",
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.lte(version, '2.13.0')) {
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 gitRootDirectory: string;
93
+ let prefix: string;
94
94
 
95
95
  try {
96
- gitRootDirectory = this.git(['rev-parse', '--show-toplevel']).trim();
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 (gitRootDirectory !== this.cwd) {
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
- '--default-prefix',
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
- this.git([
315
- 'apply',
316
- '--allow-empty',
317
- '--recount',
318
- '--unidiff-zero',
319
- '--whitespace=nowarn',
320
- '--3way',
321
- this.patchPath,
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