File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ var runGitCommand = require('./helpers/run-git-command')
33
44var COMMITHASH_COMMAND = 'rev-parse HEAD'
55var VERSION_COMMAND = 'describe --always'
6+ var BRANCH_COMMAND = 'rev-parse --abbrev-ref HEAD'
67
78function 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 / \[ g i t - r e v i s i o n - v e r s i o n \] / gi,
3741 'VERSION'
3842 )
43+
44+ buildFile (
45+ compiler ,
46+ this . gitWorkTree ,
47+ this . branchCommand ,
48+ / \[ g i t - r e v i s i o n - b r a n c h \] / gi,
49+ 'BRANCH'
50+ )
3951}
4052
4153GitRevisionPlugin . 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+
5574module . exports = GitRevisionPlugin
You can’t perform that action at this time.
0 commit comments