1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | var __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 | };
|
26 | Object.defineProperty(exports, "__esModule", { value: true });
|
27 | const exec_1 = require("../../util/exec");
|
28 | function isFullyClean(gs) {
|
29 | return gs.isClean && gs.ignoredChanges.length === 0;
|
30 | }
|
31 | exports.isFullyClean = isFullyClean;
|
32 | function 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 | }
|
42 | exports.runStatusIn = runStatusIn;
|
43 | function 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 | }
|
49 | function 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 | }
|
56 | function 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 | }
|
70 | function 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 | }
|
78 | function 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 |
|
\ | No newline at end of file |