-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (50 loc) · 1.84 KB
/
index.js
File metadata and controls
61 lines (50 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import execa from 'execa';
import isGit from 'is-git-repository';
import { platform } from 'os';
import makepath from 'path';
import pathIsAbsolute from 'path-is-absolute';
const cwd = process.cwd();
const taggedGitCommits = ({ path, lookBehind, local, remote } = {}) => {
let taggedCommits = [];
let getCommits;
let thisPath = path || cwd;
thisPath = pathIsAbsolute(thisPath) ? thisPath : makepath.join(cwd, thisPath);
const thisLookBehind = lookBehind || 1;
const thisLocal = local === undefined ? true : local;
const thisRemote = remote || 'origin';
if (!isGit(thisPath)) {
return [];
}
try {
let getTaggedCommitsExec;
let getCommitsExec;
if (thisLocal) {
if (platform() === 'win32') {
getCommitsExec = `pushd ${thisPath} & git show-ref`;
getTaggedCommitsExec = `pushd ${thisPath} & git show-ref --tags`;
} else {
getCommitsExec = `(cd ${thisPath} ; git show-ref)`;
getTaggedCommitsExec = `(cd ${thisPath} ; git show-ref --tags)`;
}
getCommits = execa.shellSync(getCommitsExec).stdout;
} else {
if (platform() === 'win32') {
getCommitsExec = `pushd ${thisPath} & git ls-remote ${thisRemote}`;
getTaggedCommitsExec = `pushd ${thisPath} & git ls-remote --tags ${thisRemote}`;
} else {
getCommitsExec = `(cd ${thisPath} ; git ls-remote)`;
getTaggedCommitsExec = `(cd ${thisPath} ; git ls-remote --tags ${thisRemote})`;
}
getCommits = execa.shellSync(getCommitsExec).stdout;
}
if (getCommits.includes('refs/tags')) {
const getTaggedCommits = execa.shellSync(getTaggedCommitsExec).stdout;
taggedCommits = getTaggedCommits.split('\n');
taggedCommits = taggedCommits.slice(-Math.abs(thisLookBehind));
}
return taggedCommits;
} catch (e) {
return [];
}
};
export default taggedGitCommits;