Skip to content

Commit c54d5ad

Browse files
authored
Merge pull request #6 from RomiC/master
Lightweight tags support
2 parents cf1806d + b5ae0f6 commit c54d5ad

11 files changed

Lines changed: 95 additions & 10 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ And a `COMMITHASH` such as:
3939
7c16d8b1abeced419c14eb9908baeb4229ac0542
4040
```
4141

42+
If you need lightweight tags support, you may turn on `lighweithTags` option in this way:
43+
44+
```javascript
45+
var GitRevisionPlugin = require('git-revision-webpack-plugin')
46+
47+
module.exports = {
48+
plugins: [
49+
new GitRevisionPlugin({lightweightTags: true})
50+
]
51+
}
52+
```
53+
4254
### Path Substitutions
4355

4456
It is also possible to use two [path substituitions](http://webpack.github.io/docs/configuration.html#output-filename) on build to get either the revision or version as part of output paths.

fixtures/git-repository/config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
logallrefupdates = true
66
ignorecase = true
77
precomposeunicode = true
8+
[receive]
9+
denyCurrentBranch = ignore

fixtures/git-repository/logs/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
0000000000000000000000000000000000000000 10e1ff4c17ad1f12241b5c4d9a708a76e98289d8 Paulo Ragonha <paulo@ragonha.me> 1463076183 +0200 commit (initial): dummy project
2+
10e1ff4c17ad1f12241b5c4d9a708a76e98289d8 9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2 Roman Charugin <cr@redmadrobot.com> 1469887902 +0300 push
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
0000000000000000000000000000000000000000 10e1ff4c17ad1f12241b5c4d9a708a76e98289d8 Paulo Ragonha <paulo@ragonha.me> 1463076183 +0200 commit (initial): dummy project
2+
10e1ff4c17ad1f12241b5c4d9a708a76e98289d8 9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2 Roman Charugin <cr@redmadrobot.com> 1469887902 +0300 push
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
10e1ff4c17ad1f12241b5c4d9a708a76e98289d8
1+
9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2

lib/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ var versionCommand = 'describe --always'
66

77
function GitRevisionPlugin (options) {
88
this.gitWorkTree = options && options.gitWorkTree
9+
this.lightweightTags = options && options.lightweightTags || false
910
}
1011

1112
GitRevisionPlugin.prototype.apply = function (compiler) {
1213
buildFile(compiler, this.gitWorkTree, commithashCommand, /\[git-revision-hash\]/gi, 'COMMITHASH')
13-
buildFile(compiler, this.gitWorkTree, versionCommand, /\[git-revision-version\]/gi, 'VERSION')
14+
buildFile(compiler, this.gitWorkTree, versionCommand + (this.lightweightTags ? ' --tags' : ''), /\[git-revision-version\]/gi, 'VERSION')
1415
}
1516

1617
GitRevisionPlugin.prototype.commithash = function (callback) {
1718
return runGitCommand(this.gitWorkTree, commithashCommand)
1819
}
1920

2021
GitRevisionPlugin.prototype.version = function (callback) {
21-
return runGitCommand(this.gitWorkTree, versionCommand)
22+
return runGitCommand(this.gitWorkTree, versionCommand + (this.lightweightTags ? ' --tags' : ''))
2223
}
2324

2425
module.exports = GitRevisionPlugin

0 commit comments

Comments
 (0)