1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getGitRemotes = exports.configRemote = exports.Git = void 0;
|
4 | const errors_1 = require("@oclif/core/lib/errors");
|
5 | const vars_1 = require("./vars");
|
6 | class Git {
|
7 | get remotes() {
|
8 | return this.exec('remote -v')
|
9 | .split('\n')
|
10 | .filter(l => l.endsWith('(fetch)'))
|
11 | .map(l => {
|
12 | const [name, url] = l.split('\t');
|
13 | return { name, url: url.split(' ')[0] };
|
14 | });
|
15 | }
|
16 | exec(cmd) {
|
17 | const { execSync: exec } = require('child_process');
|
18 | try {
|
19 | return exec(`git ${cmd}`, {
|
20 | encoding: 'utf8',
|
21 | stdio: [null, 'pipe', null],
|
22 | });
|
23 | }
|
24 | catch (error) {
|
25 | if (error.code === 'ENOENT') {
|
26 | throw new errors_1.CLIError('Git must be installed to use the Heroku CLI. See instructions here: http://git-scm.com');
|
27 | }
|
28 | throw error;
|
29 | }
|
30 | }
|
31 | }
|
32 | exports.Git = Git;
|
33 | function configRemote() {
|
34 | const git = new Git();
|
35 | try {
|
36 | return git.exec('config heroku.remote').trim();
|
37 | }
|
38 | catch (_a) { }
|
39 | }
|
40 | exports.configRemote = configRemote;
|
41 | function getGitRemotes(onlyRemote) {
|
42 | const git = new Git();
|
43 | const appRemotes = [];
|
44 | let remotes;
|
45 | try {
|
46 | remotes = git.remotes;
|
47 | }
|
48 | catch (_a) {
|
49 | return [];
|
50 | }
|
51 | for (const remote of remotes) {
|
52 | if (onlyRemote && remote.name !== onlyRemote)
|
53 | continue;
|
54 | for (const prefix of vars_1.vars.gitPrefixes) {
|
55 | const suffix = '.git';
|
56 | const match = remote.url.match(`${prefix}(.*)${suffix}`);
|
57 | if (!match)
|
58 | continue;
|
59 | appRemotes.push({
|
60 | app: match[1],
|
61 | remote: remote.name,
|
62 | });
|
63 | }
|
64 | }
|
65 | return appRemotes;
|
66 | }
|
67 | exports.getGitRemotes = getGitRemotes;
|