File tree Expand file tree Collapse file tree 5 files changed +41
-4
lines changed
fixtures/tagged-commit/dot-git Expand file tree Collapse file tree 5 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ module.exports = function(gitPath) {
35
35
var result = {
36
36
sha : null ,
37
37
abbreviatedSha : null ,
38
- branch : null
38
+ branch : null ,
39
+ tag : null
39
40
}
40
41
41
42
try {
@@ -47,6 +48,7 @@ module.exports = function(gitPath) {
47
48
var branchName = headFile . split ( '/' ) . slice ( - 1 ) [ 0 ] . trim ( ) ;
48
49
var refPath = headFile . split ( ' ' ) [ 1 ] ;
49
50
51
+ // Find branch and SHA
50
52
if ( refPath ) {
51
53
var branchPath = path . join ( gitPath , refPath . trim ( ) ) ;
52
54
@@ -57,6 +59,18 @@ module.exports = function(gitPath) {
57
59
}
58
60
59
61
result . abbreviatedSha = result . sha . slice ( 0 , 10 ) ;
62
+
63
+ // Find tag
64
+ var packedRefsFilePath = path . join ( gitPath , 'packed-refs' ) ;
65
+ if ( fs . existsSync ( packedRefsFilePath ) ) {
66
+ var packedRefsFile = fs . readFileSync ( packedRefsFilePath , { encoding : 'utf8' } ) ;
67
+ var tagLine = packedRefsFile . split ( '\n' ) . filter ( function ( l ) {
68
+ return l . indexOf ( "refs/tags" ) > - 1 && l . indexOf ( result . sha ) > - 1 ;
69
+ } ) [ 0 ] ;
70
+ if ( tagLine ) {
71
+ result . tag = tagLine . split ( 'tags/' ) [ 1 ]
72
+ }
73
+ }
60
74
}
61
75
} catch ( e ) {
62
76
// eat it
@@ -66,4 +80,4 @@ module.exports = function(gitPath) {
66
80
} ;
67
81
68
82
module . exports . _findRepo = findRepo ;
69
- module . exports . _changeGitDir = changeGitDir ;
83
+ module . exports . _changeGitDir = changeGitDir ;
Original file line number Diff line number Diff line change
1
+ ref: refs/heads/master
Original file line number Diff line number Diff line change
1
+ 5359aabd3872d9ffd160712e9615c5592dfe6745 refs/remotes/origin/master
2
+ c76753aa8651471fe082a3ecd0790ec54f5ec673 refs/tags/v1.0.0
3
+ 5359aabd3872d9ffd160712e9615c5592dfe6745 refs/tags/my-tag
4
+ 6f2abfab299ad8e302f3a3023f88483f4be3b402 refs/tags/v1.0.1
Original file line number Diff line number Diff line change
1
+ 5359aabd3872d9ffd160712e9615c5592dfe6745
Original file line number Diff line number Diff line change @@ -57,7 +57,8 @@ describe('git-repo-info', function() {
57
57
var expected = {
58
58
branch : 'master' ,
59
59
sha : '5359aabd3872d9ffd160712e9615c5592dfe6745' ,
60
- abbreviatedSha : '5359aabd38'
60
+ abbreviatedSha : '5359aabd38' ,
61
+ tag : null
61
62
}
62
63
63
64
assert . deepEqual ( result , expected ) ;
@@ -70,7 +71,23 @@ describe('git-repo-info', function() {
70
71
var expected = {
71
72
branch : null ,
72
73
sha : '9dac893d5a83c02344d91e79dad8904889aeacb1' ,
73
- abbreviatedSha : '9dac893d5a'
74
+ abbreviatedSha : '9dac893d5a' ,
75
+ tag : null
76
+ }
77
+
78
+ assert . deepEqual ( result , expected ) ;
79
+ } ) ;
80
+
81
+
82
+ it ( 'returns an object with repo info, including the tag' , function ( ) {
83
+ var repoRoot = path . join ( testFixturesPath , 'tagged-commit' ) ;
84
+ var result = repoInfo ( path . join ( repoRoot , gitDir ) )
85
+
86
+ var expected = {
87
+ branch : 'master' ,
88
+ sha : '5359aabd3872d9ffd160712e9615c5592dfe6745' ,
89
+ abbreviatedSha : '5359aabd38' ,
90
+ tag : 'my-tag'
74
91
}
75
92
76
93
assert . deepEqual ( result , expected ) ;
You can’t perform that action at this time.
0 commit comments