Skip to content

Commit a477f4f

Browse files
committed
Add setting sorting key for fetching tags
1 parent 37389dc commit a477f4f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/GitChangeLog.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,11 @@ class GitChangeLog
147147
* noChangesMessage Message to show when there are no commit subjects to list for a tag.
148148
* addHashes True includes commit hashes to the listed subjects.
149149
* includeMergeCommits True includes merge commits in the subject lists.
150+
* tagOrderBy Specify on which field the fetched tags have to be ordered.
150151
* tagOrderDesc True to sort the tags in descending order.
151152
* commitOrder Set to 'ASC' or 'DESC' to sort the subjects in resp. ascending/descending order.
152153
* </pre>
154+
* @see https://git-scm.com/docs/git-for-each-ref
153155
*/
154156
protected $options = [
155157
'logHeader' => "# Changelog\n\n",
@@ -158,6 +160,7 @@ class GitChangeLog
158160
'noChangesMessage' => 'No changes.',
159161
'addHashes' => true,
160162
'includeMergeCommits' => false,
163+
'tagOrderBy' => 'creatordate',
161164
'tagOrderDesc' => true,
162165
'commitOrder' => 'ASC',
163166
];
@@ -192,7 +195,7 @@ public function fetchTags($force = false): array
192195
}
193196

194197
// Get all git tags.
195-
$this->gitTags = explode("\n", shell_exec("git tag --sort=-creatordate"));
198+
$this->gitTags = explode("\n", shell_exec("git tag --sort=-{$this->options['tagOrderBy']}"));
196199
array_pop($this->gitTags); // Remove empty element.
197200

198201
$toKey = $this->toTag == 'HEAD' ? 0 : array_search($this->toTag, $this->gitTags);

0 commit comments

Comments
 (0)