@@ -20,106 +20,11 @@ class GitController extends VcsController
20
20
{
21
21
protected $ _before = ['.gitignore ' ];
22
22
23
- /**
24
- * @var array VCS tags
25
- */
26
- protected $ _tags = [];
27
-
28
- public function getTags ()
29
- {
30
- return $ this ->_tags ;
31
- }
32
-
33
- public function loadTags ()
34
- {
35
- exec ("git log --date=short --tags --simplify-by-decoration --pretty='format:%cd %d' " , $ logs );
36
- foreach ($ logs as $ log ) {
37
- preg_match ('/^([0-9-]+)\s*(\(.*\))?$/ ' , $ log , $ m );
38
- $ this ->_tags [$ this ->matchTag ($ m [2 ]) ?: $ this ->initTag ] = $ m [1 ];
39
- }
40
- }
41
-
42
23
/**
43
24
* @var string current tag
44
25
*/
45
26
protected $ tag ;
46
27
47
- /**
48
- * @var array VCS history
49
- */
50
- protected $ _history = [];
51
-
52
- /**
53
- * @var array all the commits
54
- */
55
- protected $ _commits = [];
56
-
57
- public function getCommits ()
58
- {
59
- return $ this ->_commits ;
60
- }
61
-
62
- public function getHistory ()
63
- {
64
- return $ this ->_history ;
65
- }
66
-
67
- public function addHistory ($ commit )
68
- {
69
- $ this ->tag = $ this ->matchTag ($ commit ['tag ' ]) ?: $ this ->tag ;
70
- $ commit ['tag ' ] = $ this ->tag ;
71
- $ hash = (string ) $ commit ['hash ' ];
72
- $ this ->_commits [$ hash ] = $ commit ;
73
- $ this ->_history [$ this ->tag ][$ hash ] = $ commit ;
74
- }
75
-
76
- /**
77
- * Loads raw git history.
78
- * @throws InvalidConfigException
79
- */
80
- public function loadHistory ()
81
- {
82
- if (!file_exists ('.git ' )) {
83
- return ;
84
- }
85
- exec ("git log --date=short --pretty='format:%h %ad %ae %s |%d' " , $ logs );
86
- $ this ->tag = $ this ->lastTag ;
87
- if (empty ($ logs )) {
88
- return ;
89
- }
90
- foreach ($ logs as $ log ) {
91
- if (!preg_match ('/^(\w+) ([0-9-]+) (\S+) (.*?)\s+\| ?(\([^\(\)]+\))?$/ ' , $ log , $ m )) {
92
- throw new InvalidConfigException ('failed parse git log ' );
93
- }
94
- $ this ->addHistory ([
95
- 'hash ' => $ m [1 ],
96
- 'date ' => $ m [2 ],
97
- 'email ' => $ m [3 ],
98
- 'comment ' => $ m [4 ],
99
- 'tag ' => $ m [5 ],
100
- ]);
101
- }
102
- }
103
-
104
- public function matchTag ($ str )
105
- {
106
- preg_match ('/^\((.*?)\)$/ ' , $ str , $ m );
107
- $ refs = explode (', ' , $ m [1 ]);
108
- foreach ($ refs as $ ref ) {
109
- if (preg_match ('/^tag: (.*)$/ ' , $ ref , $ m )) {
110
- return $ m [1 ];
111
- }
112
- }
113
-
114
- return false ;
115
- }
116
-
117
- public function actionLoad ()
118
- {
119
- $ this ->loadTags ();
120
- $ this ->loadHistory ();
121
- }
122
-
123
28
public function actionRelease ($ version = null )
124
29
{
125
30
$ version = $ this ->takeGoal ('version ' )->getVersion ($ version );
@@ -151,12 +56,7 @@ public function getUserEmail()
151
56
152
57
public function getYear ()
153
58
{
154
- $ tags = $ this ->getTags ();
155
- if (empty ($ tags )) {
156
- $ date = `git log --reverse --pretty=%ai | head -n 1 `;
157
- } else {
158
- $ date = array_pop ($ tags );
159
- }
59
+ $ date = `git log --reverse --pretty=%ai | head -n 1 `;
160
60
$ year = $ date ? date ('Y ' , strtotime ($ date )) : '' ;
161
61
162
62
return $ year ;
0 commit comments