-
Notifications
You must be signed in to change notification settings - Fork 1
/
gh-submodule-add.js
284 lines (246 loc) · 17.6 KB
/
gh-submodule-add.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
const ins = require("util").inspect;
const deb = (...args) => {
if (debug) console.log(ins(...args, {depth: null}));
};
const path = require('path');
const fs = require("fs");
const shell = require('shelljs');
const {
showError,
//sh,
//shContinue, shStderr, gh,
//ghCont,
//ghCode,
names2urls,
//getUserLogin,
//getRepoListFromFile,
//getRepoListFromAPISearch,
//getNumberOfCommits,
//branches,
numBranches,
//RepoIsEmpty,
getRepoList,
fzfGetOrg,
//addImplicitOrgIfNeeded,
addSubmodules,
setDefaultOrg
} = require('@crguezl/gh-utilities');
const { Command } = require('commander');
const program = new Command();
program.version(require('./package.json').version);
program
.name('gh submodule-add')
.usage("[options] [organization] -- [git submodule options]")
.allowUnknownOption()
.option('-s, --search <query>', "search <query> using GitHub Search API")
.option('-r, --regexp <regexp>', 'filter <query> results using <regexp>')
.option('-c, --csr <comma separated list of repos>', 'the list of repos is specified as a comma separated list')
.option('-f, --file <file>', 'file with the list of repos, one per line')
.option('-k, --fork <value>', 'Include fork repos. Legal values: "true", "only", "false". Default is "true"')
.option('-n --dryrun','just show what repos will be added as submodules')
.option('-C --clone','clone only. Skip submodule adds and aborbgitdirs steps')
.option('-o --org <org>', 'organization or user')
.option(' --default', 'Implies "-o <org>". Set "org" as default organization for future uses')
.option('-D --depth <depth>','Create a shallow clone with a history truncated to <depth> number of commits')
.option('-d, --debug', 'output extra debugging')
.option('-p --parallel <int>', 'number of concurrent processes during the cloning stage', 2);
program.addHelpText('after', `
- If the organization is not explicitly specified,
the selection will be done interactively among the list of your organizations
- You can set the default organization through the "--default" option for future uses of this program
- If no repos are specified the selection of repos will be done interactively among the repos in the org
- Option '-s' assumes all the repos belong to the same org
- When called with option '-s .', the dot '.' refers to all the repos. fzf will be open to select the repos
- The current folder must be the root of a git repo unless options '-n' or '-C' are used
- When in fzf, use CTRL-A to select all, tab to select/deselect
`
);
program.parse(process.argv);
//if (process.argv.length === 2) program.help()
const debug = program.debug;
const options = program.opts();
// console.log(options.search || options.file || options.csr);
// console.log(program.args)
if (!(options.search || options.file || options.csr)) options.search = '.';
if (!shell.which('git')) {
showError('Sorry, this extension requires git installed!');
}
if (!shell.which('gh')) {
showError('Sorry, this extension requires GitHub Cli (gh) installed!');
}
if (!(options.dryrun ||options.clone)) {
let isGitFolder = shell.exec("git rev-parse --is-inside-work-tree", {silent: true});
if (!isGitFolder || !fs.existsSync(".git")) {
showError('Unless one of the options "-n" or "-C" are used, the current folder must be the root of a git repo when running this command!');
}
}
debugger;
if (!options.org && (program.args.length == 1) ) options.org = program.args.shift();
let org = options.org || fzfGetOrg();
if (options.default) setDefaultOrg(org);
let repos = getRepoList(options, org);
if (repos.length === 0) {
console.log(`No matching repos found in owner "${org}"!`);
process.exit(0);
}
if (options.regexp) {
let regexp = new RegExp(options.regexp,'i');
repos = repos.filter(rn => {
return regexp.test(rn)
});
}
if (options.dryrun) {
//console.error("Only repos with more than one commit will be added as submodules:")
//console.log(repos);
let nb = numBranches(repos)
repos.forEach((r,i) => {
if (nb[i] === 0)
console.error(`${r} is empty!`);
else console.log(r);
});
process.exit(0);
}
let urls = names2urls(repos);
addSubmodules({
urls,
repos,
parallel: options.parallel,
depth: options.depth,
cloneOnly: options.clone,
submoduleArgs: program.args,
cloneArgs: []
});
/*
######### UNIFIED graphQL NO parallelism in the downloads of repos
# unified graphql request for empty repos download complete of 1 repo
➜ asyncserialize git:(master) ✗ time gh submodule-add -s 'asyncserialize' --org ULL-MII-SYTWS-2122
Skipping to add repo https://github.com/ULL-MII-SYTWS-2122/asyncserialize-lorenaolaru because is empty!
Skipping to add repo https://github.com/ULL-MII-SYTWS-2122/asyncserialize-mstoisor because is empty!
Skipping to add repo https://github.com/ULL-MII-SYTWS-2122/asyncserialize-crguezl because is empty!
Skipping to add repo https://github.com/ULL-MII-SYTWS-2122/asyncserialize-ddialar because is empty!
git submodule add https://github.com/ULL-MII-SYTWS-2122/asyncserialize-alu0101102726
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/sytws2122/practicas-alumnos/asyncserialize/asyncserialize-alu0101102726'...
Skipping to add repo https://github.com/ULL-MII-SYTWS-2122/asyncserialize-PaulaExposito because is empty!
gh submodule-add -s 'asyncserialize' --org ULL-MII-SYTWS-2122 0,99s user 0,43s system 36% cpu 3,946 total
# unified graphql request for empty repos -n option. No downloads
➜ asyncserialize git:(master) ✗ time gh submodule-add -s asyncserialize -o ULL-MII-SYTWS-2122 -n
Only repos with more than one commit will be added as submodules:
ULL-MII-SYTWS-2122/asyncserialize-mstoisor is empty!
ULL-MII-SYTWS-2122/asyncserialize-lorenaolaru is empty!
ULL-MII-SYTWS-2122/asyncserialize-crguezl is empty!
ULL-MII-SYTWS-2122/asyncserialize-ddialar is empty!
ULL-MII-SYTWS-2122/asyncserialize-alu0101102726
ULL-MII-SYTWS-2122/asyncserialize-PaulaExposito is empty!
gh submodule-add -s asyncserialize -o ULL-MII-SYTWS-2122 -n 0,39s user 0,15s system 26% cpu 2,040 total
# unified graphql request for empty repos -n option. 16 repos. No downloads
➜ aprender-markdown git:(master) ✗ time gh submodule-add -s aprender-markdown --org ULL-MFP-AET-2122 -n
Only repos with more than one commit will be added as submodules:
ULL-MFP-AET-2122/aprender-markdown-anabel-coello-perez-alu0100885200
ULL-MFP-AET-2122/aprender-markdown-alejandro-gonzalez-sarasola-alu0100260076
ULL-MFP-AET-2122/aprender-markdown-wim-van-hoye-alu0101520377
ULL-MFP-AET-2122/aprender-markdown-adela-gonzalez-maury-alu0101116204
ULL-MFP-AET-2122/aprender-markdown-ivan-gonzalez-aguiar-alu0100551266
ULL-MFP-AET-2122/aprender-markdown-carlos-guerra-olivera-alu0100703535
ULL-MFP-AET-2122/aprender-markdown-adrian-prieto-curbelo_alu0100948387
ULL-MFP-AET-2122/aprender-markdown-manuel_curbelo_alu0100045130
ULL-MFP-AET-2122/aprender-markdown-chloe-boistel-perez-alu0100788020
ULL-MFP-AET-2122/aprender-markdown-noelia-rodriguez-hernandez-alu0100595420
ULL-MFP-AET-2122/aprender-markdown-alejandro-marrero-diaz-alu100825008
ULL-MFP-AET-2122/aprender-markdown-yeray_exposito_garcia_alu0100951844
ULL-MFP-AET-2122/aprender-markdown-angel-ramallobenitez-alu0100312898
ULL-MFP-AET-2122/aprender-markdown-nestor-gonzalez-lopez-alu0100108859
ULL-MFP-AET-2122/aprender-markdown-jaime-garcia-bullejos-alu0100906806
ULL-MFP-AET-2122/gitpod-template
gh submodule-add -s aprender-markdown --org ULL-MFP-AET-2122 -n 0,40s user 0,16s system 26% cpu 2,122 total
# Unified graphql request for empty repos -n option. 16 downloads
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-anabel-coello-perez-alu0100885200
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-anabel-coello-perez-alu0100885200'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-alejandro-gonzalez-sarasola-alu0100260076
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-alejandro-gonzalez-sarasola-alu0100260076'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-adela-gonzalez-maury-alu0101116204
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-adela-gonzalez-maury-alu0101116204'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-wim-van-hoye-alu0101520377
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-wim-van-hoye-alu0101520377'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-ivan-gonzalez-aguiar-alu0100551266
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-ivan-gonzalez-aguiar-alu0100551266'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-adrian-prieto-curbelo_alu0100948387
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-adrian-prieto-curbelo_alu0100948387'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-manuel_curbelo_alu0100045130
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-manuel_curbelo_alu0100045130'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-carlos-guerra-olivera-alu0100703535
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-carlos-guerra-olivera-alu0100703535'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-chloe-boistel-perez-alu0100788020
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-chloe-boistel-perez-alu0100788020'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-noelia-rodriguez-hernandez-alu0100595420
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-noelia-rodriguez-hernandez-alu0100595420'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-alejandro-marrero-diaz-alu100825008
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-alejandro-marrero-diaz-alu100825008'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-angel-ramallobenitez-alu0100312898
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-angel-ramallobenitez-alu0100312898'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-nestor-gonzalez-lopez-alu0100108859
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-nestor-gonzalez-lopez-alu0100108859'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-yeray_exposito_garcia_alu0100951844
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-yeray_exposito_garcia_alu0100951844'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-jaime-garcia-bullejos-alu0100906806
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-jaime-garcia-bullejos-alu0100906806'...
git submodule add https://github.com/ULL-MFP-AET-2122/gitpod-template
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/gitpod-template'...
gh submodule-add -s aprender-markdown --org ULL-MFP-AET-2122 4,05s user 2,63s system 27% cpu 24,702 total
### Sequential
# 16 repos no downloads
➜ aprender-markdown git:(master) ✗ time gh submodule-add -s 'aprender-markdown' --org ULL-MFP-AET-2122 -n
Only repos with more than one commit will be added as submodules:
ULL-MFP-AET-2122/aprender-markdown-anabel-coello-perez-alu0100885200
ULL-MFP-AET-2122/aprender-markdown-adela-gonzalez-maury-alu0101116204
ULL-MFP-AET-2122/aprender-markdown-alejandro-gonzalez-sarasola-alu0100260076
ULL-MFP-AET-2122/aprender-markdown-wim-van-hoye-alu0101520377
ULL-MFP-AET-2122/aprender-markdown-adrian-prieto-curbelo_alu0100948387
ULL-MFP-AET-2122/aprender-markdown-manuel_curbelo_alu0100045130
ULL-MFP-AET-2122/aprender-markdown-carlos-guerra-olivera-alu0100703535
ULL-MFP-AET-2122/aprender-markdown-noelia-rodriguez-hernandez-alu0100595420
ULL-MFP-AET-2122/aprender-markdown-ivan-gonzalez-aguiar-alu0100551266
ULL-MFP-AET-2122/aprender-markdown-chloe-boistel-perez-alu0100788020
ULL-MFP-AET-2122/aprender-markdown-alejandro-marrero-diaz-alu100825008
ULL-MFP-AET-2122/aprender-markdown-angel-ramallobenitez-alu0100312898
ULL-MFP-AET-2122/aprender-markdown-nestor-gonzalez-lopez-alu0100108859
ULL-MFP-AET-2122/aprender-markdown-yeray_exposito_garcia_alu0100951844
ULL-MFP-AET-2122/aprender-markdown-jaime-garcia-bullejos-alu0100906806
ULL-MFP-AET-2122/gitpod-template
gh submodule-add -s 'aprender-markdown' --org ULL-MFP-AET-2122 -n 2,33s user 0,83s system 26% cpu 11,815 total
➜ aprender-markdown git:(master) ✗ time gh submodule-add -s 'aprender-markdown' --org ULL-MFP-AET-2122
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-anabel-coello-perez-alu0100885200
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-anabel-coello-perez-alu0100885200'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-alejandro-gonzalez-sarasola-alu0100260076
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-alejandro-gonzalez-sarasola-alu0100260076'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-wim-van-hoye-alu0101520377
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-wim-van-hoye-alu0101520377'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-adela-gonzalez-maury-alu0101116204
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-adela-gonzalez-maury-alu0101116204'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-ivan-gonzalez-aguiar-alu0100551266
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-ivan-gonzalez-aguiar-alu0100551266'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-carlos-guerra-olivera-alu0100703535
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-carlos-guerra-olivera-alu0100703535'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-adrian-prieto-curbelo_alu0100948387
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-adrian-prieto-curbelo_alu0100948387'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-manuel_curbelo_alu0100045130
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-manuel_curbelo_alu0100045130'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-chloe-boistel-perez-alu0100788020
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-chloe-boistel-perez-alu0100788020'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-noelia-rodriguez-hernandez-alu0100595420
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-noelia-rodriguez-hernandez-alu0100595420'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-alejandro-marrero-diaz-alu100825008
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-alejandro-marrero-diaz-alu100825008'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-yeray_exposito_garcia_alu0100951844
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-yeray_exposito_garcia_alu0100951844'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-angel-ramallobenitez-alu0100312898
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-angel-ramallobenitez-alu0100312898'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-nestor-gonzalez-lopez-alu0100108859
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-nestor-gonzalez-lopez-alu0100108859'...
git submodule add https://github.com/ULL-MFP-AET-2122/aprender-markdown-jaime-garcia-bullejos-alu0100906806
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/aprender-markdown-jaime-garcia-bullejos-alu0100906806'...
git submodule add https://github.com/ULL-MFP-AET-2122/gitpod-template
Clonando en '/Users/casianorodriguezleon/campus-virtual/2122/aet2122/practicas-alumnos/aprender-markdown/gitpod-template'...
gh submodule-add -s 'aprender-markdown' --org ULL-MFP-AET-2122 5,96s user 3,25s system 27% cpu 33,934 total
## Parallel clone and graphql unified
16 repos gh submodule-add -s aprender-markdown --org ULL-MFP-AET-2122 4,30s user 2,87s system 57% cpu 12,540 total
*/