@@ -15,11 +15,10 @@ var cache = path.resolve(pkg, 'cache')
15
15
16
16
var json = { name : 'cat' , version : '0.1.2' }
17
17
18
- test ( 'npm version from-git with a valid tag creates new commit' , function ( t ) {
18
+ test ( 'npm version from-git with a valid tag creates a new commit' , function ( t ) {
19
19
var version = '1.2.3'
20
- var tag = 'v' + version
21
20
setup ( )
22
- createTag ( t , tag , runVersion )
21
+ createTag ( t , version , runVersion )
23
22
24
23
function runVersion ( er ) {
25
24
t . ifError ( er , 'git tag ran without error' )
@@ -40,16 +39,15 @@ test('npm version from-git with a valid tag creates new commit', function (t) {
40
39
function checkCommit ( er , log , stderr ) {
41
40
t . ifError ( er , 'git log ran without issue' )
42
41
t . notOk ( stderr , 'no error output' )
43
- t . ok ( log . indexOf ( version ) !== - 1 , 'commited from subdirectory ' )
42
+ t . ok ( log . indexOf ( version ) !== - 1 , 'commit was created ' )
44
43
t . end ( )
45
44
}
46
45
} )
47
46
48
47
test ( 'npm version from-git with a valid tag updates the package.json version' , function ( t ) {
49
48
var version = '1.2.3'
50
- var tag = 'v' + version
51
49
setup ( )
52
- createTag ( t , tag , runVersion )
50
+ createTag ( t , version , runVersion )
53
51
54
52
function runVersion ( er ) {
55
53
t . ifError ( er , 'git tag ran without error' )
@@ -68,6 +66,70 @@ test('npm version from-git with a valid tag updates the package.json version', f
68
66
}
69
67
} )
70
68
69
+ test ( 'npm version from-git strips tag-version-prefix' , function ( t ) {
70
+ var version = '1.2.3'
71
+ var prefix = 'custom-'
72
+ var tag = prefix + version
73
+ setup ( )
74
+ createTag ( t , tag , runVersion )
75
+
76
+ function runVersion ( er ) {
77
+ t . ifError ( er , 'git tag ran without error' )
78
+ npm . config . set ( 'sign-git-tag' , false )
79
+ npm . config . set ( 'tag-version-prefix' , prefix )
80
+ npm . commands . version ( [ 'from-git' ] , checkVersion )
81
+ }
82
+
83
+ function checkVersion ( er ) {
84
+ var git = require ( '../../lib/utils/git.js' )
85
+ t . ifError ( er , 'version command ran without error' )
86
+ git . whichAndExec (
87
+ [ 'log' , '--pretty=medium' ] ,
88
+ { cwd : pkg , env : process . env } ,
89
+ checkCommit
90
+ )
91
+ }
92
+
93
+ function checkCommit ( er , log , stderr ) {
94
+ t . ifError ( er , 'git log ran without issue' )
95
+ t . notOk ( stderr , 'no error output' )
96
+ t . ok ( log . indexOf ( tag ) === - 1 , 'commit should not include prefix' )
97
+ t . ok ( log . indexOf ( version ) !== - 1 , 'commit should include version' )
98
+ t . end ( )
99
+ }
100
+ } )
101
+
102
+ test ( 'npm version from-git only strips tag-version-prefix if it is a prefix' , function ( t ) {
103
+ var prefix = 'test'
104
+ var version = '1.2.3-' + prefix
105
+ setup ( )
106
+ createTag ( t , version , runVersion )
107
+
108
+ function runVersion ( er ) {
109
+ t . ifError ( er , 'git tag ran without error' )
110
+ npm . config . set ( 'sign-git-tag' , false )
111
+ npm . config . set ( 'tag-version-prefix' , prefix )
112
+ npm . commands . version ( [ 'from-git' ] , checkVersion )
113
+ }
114
+
115
+ function checkVersion ( er ) {
116
+ var git = require ( '../../lib/utils/git.js' )
117
+ t . ifError ( er , 'version command ran without error' )
118
+ git . whichAndExec (
119
+ [ 'log' ] ,
120
+ { cwd : pkg , env : process . env } ,
121
+ checkCommit
122
+ )
123
+ }
124
+
125
+ function checkCommit ( er , log , stderr ) {
126
+ t . ifError ( er , 'git log ran without issue' )
127
+ t . notOk ( stderr , 'no error output' )
128
+ t . ok ( log . indexOf ( version ) !== - 1 , 'commit should include the full version' )
129
+ t . end ( )
130
+ }
131
+ } )
132
+
71
133
test ( 'npm version from-git with an existing version' , function ( t ) {
72
134
var tag = 'v' + json . version
73
135
setup ( )
0 commit comments