Skip to content

Commit f3d1ac8

Browse files
committed
Change to it doesn't include tag delta and hash when a tag points directly to HEAD
1 parent b3809f9 commit f3d1ac8

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ By default, the plugin runs on Maven's `initialize` phase. Any plugin running af
3939
* `build-tag-delta`: Number of commits since the closest tag until HEAD. Example: `2`
4040
* `build-commit`: Full hash of current commit (HEAD). Example: `c154712b8cea9da812c52f269578a458911f24cc`
4141
* `build-commit-abbrev`: Abbreviated hash of current commit (HEAD). Example: `c154712`
42-
* `build-version`: Full descriptive version of current build. Includes closest tag, tag delta, and abbreviated commit hash. Example: `1.2.0-SNAPSHOT-2-c154712`
42+
* `build-version`: Descriptive version of current build. If a tag points to HEAD (that is, build-tag-delta is "0") then `build-version` equals `build-tag`; otherwise, it'll include: the closest tag, tag delta, and abbreviated commit hash. Examples: `1.2.0-SNAPSHOT` (tag points to HEAD), `1.2.0-SNAPSHOT-2-c154712` (HEAD is two commits ahead of tag)
4343
* `build-tstamp`: A date and time stamp of the current commit (HEAD). The pattern is configurable. Example: `20120407001823`.
4444

4545

src/main/clojure/buildversion_plugin/git.clj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,18 @@
7979
:build-tstamp commit-tstamp-str
8080
:build-commit long-hash
8181
:build-commit-abbrev short-hash }
82-
82+
8383
{:keys [git-tag git-tag-delta] } (git-describe-first-parent dir)]
8484

8585
(if (nil? git-tag)
8686
versioning-properties
87-
88-
(let [maven-artifact-version ((re-find #"v(.*)" git-tag) 1)]
87+
88+
(let [maven-artifact-version ((re-find #"v(.*)" git-tag) 1)
89+
version (replace-first git-tag #"^v" "")]
8990
(merge versioning-properties
9091
{:build-tag maven-artifact-version
91-
:build-version (str (replace-first git-tag #"^v" "") "-"
92-
git-tag-delta "-" short-hash)
92+
:build-version (if (== git-tag-delta 0)
93+
version
94+
(str version "-"
95+
git-tag-delta "-" short-hash))
9396
:build-tag-delta (str git-tag-delta) }))))))

src/test/clojure/buildversion_plugin/test/git.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
(deftest test-infer-project-versions
8787

8888
(assert-for-commit "First tagged commit"
89-
{:build-version #"^1.0.0-SNAPSHOT-0.*"
89+
{:build-version #"^1.0.0-SNAPSHOT$"
9090
:build-tag #"^1.0.0-SNAPSHOT$"
9191
:build-tag-delta #"0"
9292
:build-tstamp #"\d+"

0 commit comments

Comments
 (0)