|
14 | 14 |
|
15 | 15 | use Gitonomy\Git\Exception\ProcessException; |
16 | 16 | use Gitonomy\Git\Exception\RuntimeException; |
| 17 | +use Gitonomy\Git\Parser\ReferenceParser; |
17 | 18 | use Gitonomy\Git\Parser\TagParser; |
18 | 19 | use Gitonomy\Git\Reference; |
19 | 20 |
|
20 | 21 | /** |
21 | 22 | * Representation of a tag reference. |
22 | 23 | * |
23 | 24 | * @author Alexandre Salomé <alexandre.salome@gmail.com> |
| 25 | + * @author Bruce Wells <brucekwells@gmail.com> |
24 | 26 | */ |
25 | 27 | class Tag extends Reference |
26 | 28 | { |
@@ -49,6 +51,32 @@ public function isAnnotated() |
49 | 51 | return true; |
50 | 52 | } |
51 | 53 |
|
| 54 | + /** |
| 55 | + * Returns the actual commit associated with the tag, and not the hash of the tag if annotated. |
| 56 | + * |
| 57 | + * @return Commit |
| 58 | + */ |
| 59 | + public function getCommit() |
| 60 | + { |
| 61 | + if ($this->isAnnotated()) { |
| 62 | + try { |
| 63 | + $output = $this->repository->run('show-ref', ['-d', '--tag', $this->revision]); |
| 64 | + $parser = new ReferenceParser(); |
| 65 | + $parser->parse($output); |
| 66 | + |
| 67 | + foreach ($parser->references as $row) { |
| 68 | + list($commitHash, $fullname) = $row; |
| 69 | + } |
| 70 | + |
| 71 | + return $this->repository->getCommit($commitHash); |
| 72 | + } catch (ProcessException $e) { |
| 73 | + // ignore the exception |
| 74 | + } |
| 75 | + } |
| 76 | + |
| 77 | + return parent::getCommit(); |
| 78 | + } |
| 79 | + |
52 | 80 | /** |
53 | 81 | * Returns the tagger name. |
54 | 82 | * |
|
0 commit comments