Skip to content

Commit 14e3a53

Browse files
committed
Add branch name
1 parent 74faeda commit 14e3a53

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

lib/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var runGitCommand = require('./helpers/run-git-command')
33

44
var COMMITHASH_COMMAND = 'rev-parse HEAD'
55
var VERSION_COMMAND = 'describe --always'
6+
var BRANCH_COMMAND = 'rev-parse --abbrev-ref HEAD'
67

78
function GitRevisionPlugin (options) {
89
options = options || {}
@@ -15,6 +16,9 @@ function GitRevisionPlugin (options) {
1516
this.versionCommand = options.versionCommand ||
1617
VERSION_COMMAND + (options.lightweightTags ? ' --tags' : '')
1718

19+
this.branchCommand = options.branchCommand ||
20+
BRANCH_COMMAND
21+
1822
if (options.versionCommand && options.lightweightTags) {
1923
throw new Error('lightweightTags can\'t be used together versionCommand')
2024
}
@@ -36,6 +40,14 @@ GitRevisionPlugin.prototype.apply = function (compiler) {
3640
/\[git-revision-version\]/gi,
3741
'VERSION'
3842
)
43+
44+
buildFile(
45+
compiler,
46+
this.gitWorkTree,
47+
this.branchCommand,
48+
/\[git-revision-branch\]/gi,
49+
'BRANCH'
50+
)
3951
}
4052

4153
GitRevisionPlugin.prototype.commithash = function () {
@@ -52,4 +64,11 @@ GitRevisionPlugin.prototype.version = function () {
5264
)
5365
}
5466

67+
GitRevisionPlugin.prototype.branch = function () {
68+
return runGitCommand(
69+
this.gitWorkTree,
70+
this.branchCommand
71+
)
72+
}
73+
5574
module.exports = GitRevisionPlugin

0 commit comments

Comments
 (0)