1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.push = exports.setTag = exports.isHeadTag = exports.tagExists = void 0;
|
4 | const command_join_1 = require("command-join");
|
5 | const utils_1 = require("./utils");
|
6 | async function tagExists(tagName) {
|
7 | try {
|
8 | const { stdout } = await utils_1.execFileAsync('git', ['tag', '-l', tagName]);
|
9 | return stdout.split(/[\r\n]+/).includes(tagName);
|
10 | }
|
11 | catch (error) {
|
12 | throw new Error(`tagExists() Error: ${error}`);
|
13 | }
|
14 | }
|
15 | exports.tagExists = tagExists;
|
16 | async function isHeadTag(tagName) {
|
17 | try {
|
18 | const { stdout } = await utils_1.execFileAsync('git', [
|
19 | 'tag',
|
20 | '-l',
|
21 | tagName,
|
22 | '--points-at',
|
23 | 'HEAD',
|
24 | ]);
|
25 | return stdout.split(/[\r\n]+/).includes(tagName);
|
26 | }
|
27 | catch (error) {
|
28 | throw new Error(`isHeadTag() Error: ${error}`);
|
29 | }
|
30 | }
|
31 | exports.isHeadTag = isHeadTag;
|
32 | function genTagCmdArgs(tagName, message, sign = false) {
|
33 | const command = 'git';
|
34 | const args = sign || typeof message === 'string'
|
35 | ? |
36 |
|
37 |
|
38 | ['tag', tagName, sign ? '-sm' : '-m', message || '']
|
39 | : ['tag', tagName];
|
40 | return {
|
41 | command,
|
42 | args,
|
43 | get commandText() {
|
44 | return `${command} ${command_join_1.commandJoin(args)}`;
|
45 | },
|
46 | };
|
47 | }
|
48 | async function setTag(tagName, { message, sign, debug = false, dryRun = false, } = {}) {
|
49 | const cmd = genTagCmdArgs(tagName, message, sign);
|
50 | if (typeof debug === 'function') {
|
51 | utils_1.printVerbose(debug(cmd.commandText));
|
52 | }
|
53 | else if (debug) {
|
54 | utils_1.printVerbose(`> ${cmd.commandText}`);
|
55 | }
|
56 | if (!dryRun) {
|
57 | try {
|
58 | await utils_1.execFileAsync(cmd.command, cmd.args);
|
59 | }
|
60 | catch (error) {
|
61 | throw new Error(`setTag() Error: ${error}`);
|
62 | }
|
63 | }
|
64 | }
|
65 | exports.setTag = setTag;
|
66 | async function push(src, { repository = 'origin', debug = false, dryRun = false, } = {}) {
|
67 | try {
|
68 | const args = ['push', repository, src];
|
69 | if (debug) {
|
70 | utils_1.printVerbose(`> git ${command_join_1.commandJoin(args)}`);
|
71 | }
|
72 | if (!dryRun) {
|
73 | await utils_1.execFileAsync('git', args);
|
74 | }
|
75 | }
|
76 | catch (error) {
|
77 | throw new Error(`push() Error: ${error}`);
|
78 | }
|
79 | }
|
80 | exports.push = push;
|
81 |
|
\ | No newline at end of file |