UNPKG

16.2 kBJavaScriptView Raw
1"use strict";
2
3var cov_2p3l72uoj0 = function () {
4 var path = "/home/travis/build/commitizen/cz-cli/src/git/commit.js";
5 var hash = "c9997db9a0fd1e02a729beec4d51316bd4c3dc83";
6 var global = new Function("return this")();
7 var gcv = "__coverage__";
8 var coverageData = {
9 path: "/home/travis/build/commitizen/cz-cli/src/git/commit.js",
10 statementMap: {
11 "0": {
12 start: {
13 line: 15,
14 column: 15
15 },
16 end: {
17 line: 15,
18 column: 20
19 }
20 },
21 "1": {
22 start: {
23 line: 20,
24 column: 2
25 },
26 end: {
27 line: 81,
28 column: 3
29 }
30 },
31 "2": {
32 start: {
33 line: 21,
34 column: 15
35 },
36 end: {
37 line: 21,
38 column: 73
39 }
40 },
41 "3": {
42 start: {
43 line: 22,
44 column: 16
45 },
46 end: {
47 line: 25,
48 column: 6
49 }
50 },
51 "4": {
52 start: {
53 line: 27,
54 column: 4
55 },
56 end: {
57 line: 32,
58 column: 7
59 }
60 },
61 "5": {
62 start: {
63 line: 28,
64 column: 6
65 },
66 end: {
67 line: 28,
68 column: 25
69 }
70 },
71 "6": {
72 start: {
73 line: 28,
74 column: 18
75 },
76 end: {
77 line: 28,
78 column: 25
79 }
80 },
81 "7": {
82 start: {
83 line: 29,
84 column: 6
85 },
86 end: {
87 line: 29,
88 column: 20
89 }
90 },
91 "8": {
92 start: {
93 line: 31,
94 column: 6
95 },
96 end: {
97 line: 31,
98 column: 16
99 }
100 },
101 "9": {
102 start: {
103 line: 34,
104 column: 4
105 },
106 end: {
107 line: 51,
108 column: 7
109 }
110 },
111 "10": {
112 start: {
113 line: 35,
114 column: 6
115 },
116 end: {
117 line: 35,
118 column: 25
119 }
120 },
121 "11": {
122 start: {
123 line: 35,
124 column: 18
125 },
126 end: {
127 line: 35,
128 column: 25
129 }
130 },
131 "12": {
132 start: {
133 line: 36,
134 column: 6
135 },
136 end: {
137 line: 36,
138 column: 20
139 }
140 },
141 "13": {
142 start: {
143 line: 38,
144 column: 6
145 },
146 end: {
147 line: 50,
148 column: 7
149 }
150 },
151 "14": {
152 start: {
153 line: 39,
154 column: 8
155 },
156 end: {
157 line: 46,
158 column: 9
159 }
160 },
161 "15": {
162 start: {
163 line: 40,
164 column: 10
165 },
166 end: {
167 line: 45,
168 column: 14
169 }
170 },
171 "16": {
172 start: {
173 line: 47,
174 column: 8
175 },
176 end: {
177 line: 47,
178 column: 95
179 }
180 },
181 "17": {
182 start: {
183 line: 49,
184 column: 8
185 },
186 end: {
187 line: 49,
188 column: 19
189 }
190 },
191 "18": {
192 start: {
193 line: 53,
194 column: 27
195 },
196 end: {
197 line: 53,
198 column: 70
199 }
200 },
201 "19": {
202 start: {
203 line: 54,
204 column: 4
205 },
206 end: {
207 line: 80,
208 column: 5
209 }
210 },
211 "20": {
212 start: {
213 line: 55,
214 column: 17
215 },
216 end: {
217 line: 55,
218 column: 46
219 }
220 },
221 "21": {
222 start: {
223 line: 56,
224 column: 6
225 },
226 end: {
227 line: 63,
228 column: 7
229 }
230 },
231 "22": {
232 start: {
233 line: 57,
234 column: 8
235 },
236 end: {
237 line: 57,
238 column: 43
239 }
240 },
241 "23": {
242 start: {
243 line: 58,
244 column: 8
245 },
246 end: {
247 line: 58,
248 column: 19
249 }
250 },
251 "24": {
252 start: {
253 line: 60,
254 column: 8
255 },
256 end: {
257 line: 60,
258 column: 16
259 }
260 },
261 "25": {
262 start: {
263 line: 62,
264 column: 8
265 },
266 end: {
267 line: 62,
268 column: 22
269 }
270 },
271 "26": {
272 start: {
273 line: 67,
274 column: 6
275 },
276 end: {
277 line: 79,
278 column: 7
279 }
280 },
281 "27": {
282 start: {
283 line: 68,
284 column: 19
285 },
286 end: {
287 line: 68,
288 column: 49
289 }
290 },
291 "28": {
292 start: {
293 line: 69,
294 column: 8
295 },
296 end: {
297 line: 76,
298 column: 9
299 }
300 },
301 "29": {
302 start: {
303 line: 70,
304 column: 10
305 },
306 end: {
307 line: 70,
308 column: 45
309 }
310 },
311 "30": {
312 start: {
313 line: 71,
314 column: 10
315 },
316 end: {
317 line: 71,
318 column: 21
319 }
320 },
321 "31": {
322 start: {
323 line: 73,
324 column: 10
325 },
326 end: {
327 line: 73,
328 column: 18
329 }
330 },
331 "32": {
332 start: {
333 line: 75,
334 column: 10
335 },
336 end: {
337 line: 75,
338 column: 24
339 }
340 },
341 "33": {
342 start: {
343 line: 78,
344 column: 8
345 },
346 end: {
347 line: 78,
348 column: 16
349 }
350 }
351 },
352 fnMap: {
353 "0": {
354 name: "commit",
355 decl: {
356 start: {
357 line: 14,
358 column: 9
359 },
360 end: {
361 line: 14,
362 column: 15
363 }
364 },
365 loc: {
366 start: {
367 line: 14,
368 column: 51
369 },
370 end: {
371 line: 82,
372 column: 1
373 }
374 },
375 line: 14
376 },
377 "1": {
378 name: "(anonymous_1)",
379 decl: {
380 start: {
381 line: 27,
382 column: 22
383 },
384 end: {
385 line: 27,
386 column: 23
387 }
388 },
389 loc: {
390 start: {
391 line: 27,
392 column: 37
393 },
394 end: {
395 line: 32,
396 column: 5
397 }
398 },
399 line: 27
400 },
401 "2": {
402 name: "(anonymous_2)",
403 decl: {
404 start: {
405 line: 34,
406 column: 21
407 },
408 end: {
409 line: 34,
410 column: 22
411 }
412 },
413 loc: {
414 start: {
415 line: 34,
416 column: 45
417 },
418 end: {
419 line: 51,
420 column: 5
421 }
422 },
423 line: 34
424 }
425 },
426 branchMap: {
427 "0": {
428 loc: {
429 start: {
430 line: 20,
431 column: 2
432 },
433 end: {
434 line: 81,
435 column: 3
436 }
437 },
438 type: "if",
439 locations: [{
440 start: {
441 line: 20,
442 column: 2
443 },
444 end: {
445 line: 81,
446 column: 3
447 }
448 }, {
449 start: {
450 line: 20,
451 column: 2
452 },
453 end: {
454 line: 81,
455 column: 3
456 }
457 }],
458 line: 20
459 },
460 "1": {
461 loc: {
462 start: {
463 line: 21,
464 column: 53
465 },
466 end: {
467 line: 21,
468 column: 71
469 }
470 },
471 type: "binary-expr",
472 locations: [{
473 start: {
474 line: 21,
475 column: 53
476 },
477 end: {
478 line: 21,
479 column: 65
480 }
481 }, {
482 start: {
483 line: 21,
484 column: 69
485 },
486 end: {
487 line: 21,
488 column: 71
489 }
490 }],
491 line: 21
492 },
493 "2": {
494 loc: {
495 start: {
496 line: 24,
497 column: 13
498 },
499 end: {
500 line: 24,
501 column: 49
502 }
503 },
504 type: "cond-expr",
505 locations: [{
506 start: {
507 line: 24,
508 column: 29
509 },
510 end: {
511 line: 24,
512 column: 37
513 }
514 }, {
515 start: {
516 line: 24,
517 column: 40
518 },
519 end: {
520 line: 24,
521 column: 49
522 }
523 }],
524 line: 24
525 },
526 "3": {
527 loc: {
528 start: {
529 line: 28,
530 column: 6
531 },
532 end: {
533 line: 28,
534 column: 25
535 }
536 },
537 type: "if",
538 locations: [{
539 start: {
540 line: 28,
541 column: 6
542 },
543 end: {
544 line: 28,
545 column: 25
546 }
547 }, {
548 start: {
549 line: 28,
550 column: 6
551 },
552 end: {
553 line: 28,
554 column: 25
555 }
556 }],
557 line: 28
558 },
559 "4": {
560 loc: {
561 start: {
562 line: 35,
563 column: 6
564 },
565 end: {
566 line: 35,
567 column: 25
568 }
569 },
570 type: "if",
571 locations: [{
572 start: {
573 line: 35,
574 column: 6
575 },
576 end: {
577 line: 35,
578 column: 25
579 }
580 }, {
581 start: {
582 line: 35,
583 column: 6
584 },
585 end: {
586 line: 35,
587 column: 25
588 }
589 }],
590 line: 35
591 },
592 "5": {
593 loc: {
594 start: {
595 line: 38,
596 column: 6
597 },
598 end: {
599 line: 50,
600 column: 7
601 }
602 },
603 type: "if",
604 locations: [{
605 start: {
606 line: 38,
607 column: 6
608 },
609 end: {
610 line: 50,
611 column: 7
612 }
613 }, {
614 start: {
615 line: 38,
616 column: 6
617 },
618 end: {
619 line: 50,
620 column: 7
621 }
622 }],
623 line: 38
624 },
625 "6": {
626 loc: {
627 start: {
628 line: 39,
629 column: 8
630 },
631 end: {
632 line: 46,
633 column: 9
634 }
635 },
636 type: "if",
637 locations: [{
638 start: {
639 line: 39,
640 column: 8
641 },
642 end: {
643 line: 46,
644 column: 9
645 }
646 }, {
647 start: {
648 line: 39,
649 column: 8
650 },
651 end: {
652 line: 46,
653 column: 9
654 }
655 }],
656 line: 39
657 }
658 },
659 s: {
660 "0": 0,
661 "1": 0,
662 "2": 0,
663 "3": 0,
664 "4": 0,
665 "5": 0,
666 "6": 0,
667 "7": 0,
668 "8": 0,
669 "9": 0,
670 "10": 0,
671 "11": 0,
672 "12": 0,
673 "13": 0,
674 "14": 0,
675 "15": 0,
676 "16": 0,
677 "17": 0,
678 "18": 0,
679 "19": 0,
680 "20": 0,
681 "21": 0,
682 "22": 0,
683 "23": 0,
684 "24": 0,
685 "25": 0,
686 "26": 0,
687 "27": 0,
688 "28": 0,
689 "29": 0,
690 "30": 0,
691 "31": 0,
692 "32": 0,
693 "33": 0
694 },
695 f: {
696 "0": 0,
697 "1": 0,
698 "2": 0
699 },
700 b: {
701 "0": [0, 0],
702 "1": [0, 0],
703 "2": [0, 0],
704 "3": [0, 0],
705 "4": [0, 0],
706 "5": [0, 0],
707 "6": [0, 0]
708 },
709 _coverageSchema: "43e27e138ebf9cfc5966b082cf9a028302ed4184",
710 hash: "c9997db9a0fd1e02a729beec4d51316bd4c3dc83"
711 };
712 var coverage = global[gcv] || (global[gcv] = {});
713
714 if (coverage[path] && coverage[path].hash === hash) {
715 return coverage[path];
716 }
717
718 return coverage[path] = coverageData;
719}();
720
721Object.defineProperty(exports, "__esModule", {
722 value: true
723});
724exports.commit = commit;
725
726var _child_process = require("child_process");
727
728var _path = _interopRequireDefault(require("path"));
729
730var _fs = require("fs");
731
732var _dedent = _interopRequireDefault(require("dedent"));
733
734function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
735
736/**
737 * Asynchronously git commit at a given path with a message
738 */
739function commit(repoPath, message, options, done) {
740 cov_2p3l72uoj0.f[0]++;
741 let called = (cov_2p3l72uoj0.s[0]++, false); // commit the file by spawning a git process, unless the --hook
742 // option was provided. in that case, write the commit message into
743 // the .git/COMMIT_EDITMSG file
744
745 cov_2p3l72uoj0.s[1]++;
746
747 if (!options.hookMode) {
748 cov_2p3l72uoj0.b[0][0]++;
749 let args = (cov_2p3l72uoj0.s[2]++, ['commit', '-m', (0, _dedent.default)(message), ...((cov_2p3l72uoj0.b[1][0]++, options.args) || (cov_2p3l72uoj0.b[1][1]++, []))]);
750 let child = (cov_2p3l72uoj0.s[3]++, (0, _child_process.spawn)('git', args, {
751 cwd: repoPath,
752 stdio: options.quiet ? (cov_2p3l72uoj0.b[2][0]++, 'ignore') : (cov_2p3l72uoj0.b[2][1]++, 'inherit')
753 }));
754 cov_2p3l72uoj0.s[4]++;
755 child.on('error', function (err) {
756 cov_2p3l72uoj0.f[1]++;
757 cov_2p3l72uoj0.s[5]++;
758
759 if (called) {
760 cov_2p3l72uoj0.b[3][0]++;
761 cov_2p3l72uoj0.s[6]++;
762 return;
763 } else {
764 cov_2p3l72uoj0.b[3][1]++;
765 }
766
767 cov_2p3l72uoj0.s[7]++;
768 called = true;
769 cov_2p3l72uoj0.s[8]++;
770 done(err);
771 });
772 cov_2p3l72uoj0.s[9]++;
773 child.on('exit', function (code, signal) {
774 cov_2p3l72uoj0.f[2]++;
775 cov_2p3l72uoj0.s[10]++;
776
777 if (called) {
778 cov_2p3l72uoj0.b[4][0]++;
779 cov_2p3l72uoj0.s[11]++;
780 return;
781 } else {
782 cov_2p3l72uoj0.b[4][1]++;
783 }
784
785 cov_2p3l72uoj0.s[12]++;
786 called = true;
787 cov_2p3l72uoj0.s[13]++;
788
789 if (code) {
790 cov_2p3l72uoj0.b[5][0]++;
791 cov_2p3l72uoj0.s[14]++;
792
793 if (code === 128) {
794 cov_2p3l72uoj0.b[6][0]++;
795 cov_2p3l72uoj0.s[15]++;
796 console.warn(`
797 Git exited with code 128. Did you forget to run:
798
799 git config --global user.email "you@example.com"
800 git config --global user.name "Your Name"
801 `);
802 } else {
803 cov_2p3l72uoj0.b[6][1]++;
804 }
805
806 cov_2p3l72uoj0.s[16]++;
807 done(Object.assign(new Error(`git exited with error code ${code}`), {
808 code,
809 signal
810 }));
811 } else {
812 cov_2p3l72uoj0.b[5][1]++;
813 cov_2p3l72uoj0.s[17]++;
814 done(null);
815 }
816 });
817 } else {
818 cov_2p3l72uoj0.b[0][1]++;
819 const commitFilePath = (cov_2p3l72uoj0.s[18]++, _path.default.join(repoPath, '/.git/COMMIT_EDITMSG'));
820 cov_2p3l72uoj0.s[19]++;
821
822 try {
823 const fd = (cov_2p3l72uoj0.s[20]++, (0, _fs.openSync)(commitFilePath, 'w'));
824 cov_2p3l72uoj0.s[21]++;
825
826 try {
827 cov_2p3l72uoj0.s[22]++;
828 (0, _fs.writeFileSync)(fd, (0, _dedent.default)(message));
829 cov_2p3l72uoj0.s[23]++;
830 done(null);
831 } catch (e) {
832 cov_2p3l72uoj0.s[24]++;
833 done(e);
834 } finally {
835 cov_2p3l72uoj0.s[25]++;
836 (0, _fs.closeSync)(fd);
837 }
838 } catch (e) {
839 cov_2p3l72uoj0.s[26]++;
840
841 // windows doesn't allow opening existing hidden files
842 // in 'w' mode... but it does let you do 'r+'!
843 try {
844 const fd = (cov_2p3l72uoj0.s[27]++, (0, _fs.openSync)(commitFilePath, 'r+'));
845 cov_2p3l72uoj0.s[28]++;
846
847 try {
848 cov_2p3l72uoj0.s[29]++;
849 (0, _fs.writeFileSync)(fd, (0, _dedent.default)(message));
850 cov_2p3l72uoj0.s[30]++;
851 done(null);
852 } catch (e) {
853 cov_2p3l72uoj0.s[31]++;
854 done(e);
855 } finally {
856 cov_2p3l72uoj0.s[32]++;
857 (0, _fs.closeSync)(fd);
858 }
859 } catch (e) {
860 cov_2p3l72uoj0.s[33]++;
861 done(e);
862 }
863 }
864 }
865}
\No newline at end of file