2020-05-07 00:15:24 +00:00
|
|
|
import * as exec from './exec';
|
2020-02-11 12:52:06 +00:00
|
|
|
|
2020-05-07 00:15:24 +00:00
|
|
|
const git = async (args: string[] = []): Promise<string> => {
|
|
|
|
return await exec.exec(`git`, args, true).then(res => {
|
|
|
|
if (res.stderr != '' && !res.success) {
|
|
|
|
throw new Error(res.stderr);
|
|
|
|
}
|
|
|
|
return res.stdout.trim();
|
2020-02-11 12:52:06 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-07 00:15:24 +00:00
|
|
|
export async function getTag(): Promise<string> {
|
2020-02-11 12:52:06 +00:00
|
|
|
try {
|
2020-05-07 00:15:24 +00:00
|
|
|
return await git(['describe', '--tags', '--abbrev=0']);
|
2020-02-11 12:52:06 +00:00
|
|
|
} catch (err) {
|
2020-05-07 00:15:24 +00:00
|
|
|
return '';
|
2020-02-11 12:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 00:15:24 +00:00
|
|
|
export async function isTagDirty(currentTag: string): Promise<boolean> {
|
2020-02-14 17:25:27 +00:00
|
|
|
try {
|
2020-05-07 00:15:24 +00:00
|
|
|
await git(['describe', '--exact-match', '--tags', '--match', currentTag]);
|
2020-02-14 17:25:27 +00:00
|
|
|
} catch (err) {
|
2020-05-07 00:15:24 +00:00
|
|
|
return true;
|
2020-02-14 17:25:27 +00:00
|
|
|
}
|
2020-05-07 00:15:24 +00:00
|
|
|
return false;
|
2020-02-11 12:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function getShortCommit(): Promise<string> {
|
|
|
|
return await git(['show', "--format='%h'", 'HEAD', '--quiet']);
|
|
|
|
}
|