exec-staged 0.2.2 → 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/dist/lib/stage.js CHANGED
@@ -70,15 +70,15 @@ export class Stage {
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
  }
@@ -237,16 +237,19 @@ export class Stage {
237
237
  '-m',
238
238
  STAGED_CHANGES_COMMIT_MESSAGE,
239
239
  ]);
240
- // apply patch containing unstaged changes
241
- this.git([
242
- 'apply',
243
- '--allow-empty',
244
- '--recount',
245
- '--unidiff-zero',
246
- '--whitespace=nowarn',
247
- '--3way',
248
- this.patchPath,
249
- ]);
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
+ }
250
253
  // unstaged deletions are not included in the patch and must be handled
251
254
  // separately because the patch cannot be applied if such files are
252
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.2",
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
@@ -90,16 +90,16 @@ export class Stage {
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
  }
@@ -311,16 +311,19 @@ export class Stage {
311
311
  STAGED_CHANGES_COMMIT_MESSAGE,
312
312
  ]);
313
313
 
314
- // apply patch containing unstaged changes
315
- this.git([
316
- 'apply',
317
- '--allow-empty',
318
- '--recount',
319
- '--unidiff-zero',
320
- '--whitespace=nowarn',
321
- '--3way',
322
- this.patchPath,
323
- ]);
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
+ }
324
327
 
325
328
  // unstaged deletions are not included in the patch and must be handled
326
329
  // separately because the patch cannot be applied if such files are