putout 29.13.5 → 29.14.0

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/ChangeLog CHANGED
@@ -1,3 +1,8 @@
1
+ 2023.06.15, v29.14.0
2
+
3
+ feature:
4
+ - 5d0accb16 putout: use @putout/git-status-porcelain for --staged
5
+
1
6
  2023.06.14, v29.13.5
2
7
 
3
8
  feature:
package/lib/cli/staged.js CHANGED
@@ -1,25 +1,14 @@
1
1
  'use strict';
2
2
 
3
3
  const {join} = require('path');
4
- const fs = require('fs');
4
+ const {spawnSync} = require('child_process');
5
5
 
6
- const git = require('isomorphic-git');
6
+ const porcelain = require('@putout/git-status-porcelain');
7
7
  const once = require('once');
8
8
  const fullstore = require('fullstore');
9
-
10
9
  const {isSupported} = require('./supported-files');
11
10
 
12
- const STAGED_INDEX = 3;
13
- const STAGED = 2;
14
- const STAGED_WITH_CHANGES = 3;
15
-
16
- const MODIFIED_INDEX = 2;
17
- const MODIFIED = 2;
18
-
19
11
  const namesStore = fullstore([]);
20
- const isStagedStr = (statuses) => (name) => /^\*?(added|modified)$/.test(statuses[name]);
21
-
22
- const {fromEntries} = Object;
23
12
 
24
13
  const findGit = once(async ({findUp}) => {
25
14
  const type = 'directory';
@@ -36,9 +25,6 @@ const findGit = once(async ({findUp}) => {
36
25
  return dir;
37
26
  });
38
27
 
39
- const isStaged = (a) => a[STAGED_INDEX] === STAGED || a[STAGED_INDEX] === STAGED_WITH_CHANGES;
40
- const isModified = (a) => a[MODIFIED_INDEX] === MODIFIED;
41
- const head = ([a]) => a;
42
28
  const joinDir = (a) => (b) => join(a, b);
43
29
 
44
30
  module.exports.get = async function get({findUp}) {
@@ -46,56 +32,39 @@ module.exports.get = async function get({findUp}) {
46
32
  findUp,
47
33
  });
48
34
 
49
- const status = await git.statusMatrix({
50
- fs,
51
- dir,
52
- filter: isSupported,
53
- });
54
-
55
- const names = status
56
- .filter(isStaged)
57
- .filter(isModified)
58
- .map(head);
35
+ const names = porcelain({
36
+ modified: true,
37
+ added: true,
38
+ }).filter(isSupported);
59
39
 
60
40
  namesStore(names);
61
41
 
62
42
  return names.map(joinDir(dir));
63
43
  };
64
44
 
65
- async function getStatus(dir, filepath) {
66
- const status = await git.status({
67
- fs,
68
- dir,
69
- filepath,
70
- });
71
-
72
- return [filepath, status];
73
- }
74
-
75
45
  module.exports.set = async function set({findUp}) {
76
46
  const dir = await findGit({
77
47
  findUp,
78
48
  });
79
49
 
80
50
  const names = namesStore();
81
- const statusPromises = [];
82
51
 
83
- for (const filepath of names) {
84
- statusPromises.push(await getStatus(dir, filepath));
85
- }
52
+ const staged = porcelain({
53
+ unstaged: true,
54
+ });
86
55
 
87
- const statuses = fromEntries(await Promise.all(statusPromises));
88
- const staged = names.filter(isStagedStr(statuses));
89
- const promises = [];
56
+ const namesToAdd = [];
90
57
 
91
- for (const filepath of names)
92
- promises.push(git.add({
93
- fs,
94
- dir,
95
- filepath,
96
- }));
58
+ for (const filepath of names) {
59
+ if (!staged.includes(filepath))
60
+ namesToAdd.push(filepath);
61
+ }
97
62
 
98
- await Promise.all(promises);
63
+ add(namesToAdd.map(joinDir(dir)));
99
64
 
100
65
  return staged;
101
66
  };
67
+
68
+ function add(names) {
69
+ spawnSync('git', ['add', ...names]);
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "putout",
3
- "version": "29.13.5",
3
+ "version": "29.14.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊 Pluggable and configurable code transformer with built-in ESLint, Babel and support of js, jsx, typescript, flow, markdown, yaml and json",
@@ -66,6 +66,7 @@
66
66
  "@putout/formatter-progress": "^4.0.0",
67
67
  "@putout/formatter-progress-bar": "^3.0.0",
68
68
  "@putout/formatter-stream": "^4.0.0",
69
+ "@putout/git-status-porcelain": "^3.0.0",
69
70
  "@putout/operate": "^8.0.0",
70
71
  "@putout/operator-add-args": "^4.0.0",
71
72
  "@putout/operator-declare": "^5.0.0",
@@ -180,7 +181,6 @@
180
181
  "fullstore": "^3.0.0",
181
182
  "ignore": "^5.0.4",
182
183
  "is-relative": "^1.0.0",
183
- "isomorphic-git": "1.23.0",
184
184
  "nano-memoize": "^3.0.11",
185
185
  "once": "^1.4.0",
186
186
  "picomatch": "^2.2.2",