UNPKG

4.02 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2018 Atomist, Inc.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
19 return new (P || (P = Promise))(function (resolve, reject) {
20 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
23 step((generator = generator.apply(thisArg, _arguments || [])).next());
24 });
25};
26Object.defineProperty(exports, "__esModule", { value: true });
27const exec_1 = require("../../util/exec");
28function isFullyClean(gs) {
29 return gs.isClean && gs.ignoredChanges.length === 0;
30}
31exports.isFullyClean = isFullyClean;
32function runStatusIn(baseDir) {
33 return __awaiter(this, void 0, void 0, function* () {
34 const branch = yield determineBranch(baseDir);
35 const upstreamData = yield collectUpstream(baseDir, branch);
36 const shaData = yield collectFullSha(baseDir);
37 const cleanlinessData = yield collectCleanliness(baseDir);
38 const ignoredChangeData = yield collectIgnoredChanges(baseDir);
39 return Object.assign({ branch }, ignoredChangeData, cleanlinessData, shaData, upstreamData);
40 });
41}
42exports.runStatusIn = runStatusIn;
43function determineBranch(baseDir) {
44 return __awaiter(this, void 0, void 0, function* () {
45 const branchNameResult = yield exec_1.execIn(baseDir, "git", ["rev-parse", "--abbrev-ref", "HEAD"]);
46 return branchNameResult.stdout.trim();
47 });
48}
49function collectCleanliness(baseDir) {
50 return __awaiter(this, void 0, void 0, function* () {
51 const porcelainStatusResult = yield exec_1.execIn(baseDir, "git", ["status", "--porcelain"]);
52 const raw = porcelainStatusResult.stdout;
53 return { isClean: (raw.length) === 0 };
54 });
55}
56function collectIgnoredChanges(baseDir) {
57 return __awaiter(this, void 0, void 0, function* () {
58 const porcelainStatusResult = yield exec_1.execIn(baseDir, "git", ["status", "--porcelain", "--ignored"]);
59 const raw = porcelainStatusResult.stdout;
60 const ignored = raw.trim()
61 .split("\n")
62 .filter(s => s.startsWith("!"))
63 .map(s => s.substring(3));
64 return {
65 raw,
66 ignoredChanges: ignored,
67 };
68 });
69}
70function collectFullSha(baseDir, commit = "HEAD") {
71 return __awaiter(this, void 0, void 0, function* () {
72 const result = yield exec_1.execIn(baseDir, "git", ["rev-list", "-1", commit, "--"]);
73 return {
74 sha: result.stdout.trim(),
75 };
76 });
77}
78function collectUpstream(baseDir, branch) {
79 return __awaiter(this, void 0, void 0, function* () {
80 const branchResult = yield exec_1.execIn(baseDir, "git", ["for-each-ref", "--format", "%(upstream:short) %(upstream:trackshort)", `refs/heads/${branch}`]);
81 const branchResultParts = branchResult.stdout.trim().split(" ");
82 const upstream = branchResultParts.length > 0 ?
83 { branch: branchResultParts[0], inSync: branchResultParts[1] === "=" }
84 : undefined;
85 return { upstream };
86 });
87}
88//# sourceMappingURL=gitStatus.js.map
\No newline at end of file