Skip to content

provide default function for :status-to-version #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Add:

```clojure
;; Add in the git-version plugin
:plugins [[me.arrdem/lein-git-version "2.0.3"]
:plugins [[me.arrdem/lein-git-version "2.0.8"]
...]
```

Expand Down Expand Up @@ -69,14 +69,14 @@ For instance,

```clojure
(defproject bar :project/git-ref
:plugins [[me.arrdem/lein-git-version "2.0.3"]]
:plugins [[me.arrdem/lein-git-version "2.0.8"]]
...)
```
or

```clojure
(defproject baz :project/git-ref-short
:plugins [[me.arrdem/lein-git-version "2.0.3"]]
:plugins [[me.arrdem/lein-git-version "2.0.8"]]
...)
```
lein-git-version can also be used to compute a versions string, as an
Expand All @@ -89,7 +89,7 @@ itself to compute its own version.

```clojure
(defproject me.arrdem/lein-git-version "_"
:plugins [[me.arrdem/lein-git-version "2.0.3"]]
:plugins [[me.arrdem/lein-git-version "2.0.8"]]

:git-version
{:status-to-version
Expand All @@ -106,6 +106,16 @@ itself to compute its own version.
...)
```

If you want reuse this function used by lein-git-version itself, simply set `:status-to-version` to `lein-git-version.plugin/default-status-to-version`.

```clojure
(defproject me.arrdem/lein-git-version "_"
:plugins [[me.arrdem/lein-git-version "2.0.8"]]

:git-version {:status-to-version lein-git-version.plugin/default-status-to-version}
...)
```

Will use the last tag as the version if level with a tag, otherwise
will produce a `SNAPSHOT` one SemVer patch ahead of the previous tag
qualified with the name of the current branch.
Expand All @@ -123,7 +133,7 @@ For instance,

```clojure
(defproject com.my-app/cares-what-version-it-is :project/ref-short
:plugins [[me.arrdem/lein-git-version "2.0.3"]]
:plugins [[me.arrdem/lein-git-version "2.0.8"]]
...
:git-version {:version-file "resources/com/my_app/version.edn"
:version-file-keys [:ref :version :timestamp]}))
Expand Down
13 changes: 1 addition & 12 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,4 @@

:plugins [[me.arrdem/lein-git-version "LATEST"]]
:git-version
,,{:status-to-version
,,(fn [{:keys [tag version branch ahead ahead? dirty?] :as git}]
(assert (re-find #"\d+\.\d+\.\d+" tag)
"Tag is assumed to be a raw SemVer version")
(if (and tag (not ahead?) (not dirty?))
tag
(let [[_ prefix patch] (re-find #"(\d+\.\d+)\.(\d+)" tag)
patch (Long/parseLong patch)
patch+ (inc patch)]
(format "%s.%d-%s-SNAPSHOT" prefix patch+ branch))))
}
)
,,{:status-to-version lein-git-version.plugin/default-status-to-version})
14 changes: 13 additions & 1 deletion src/lein_git_version/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@
"The default configuration values."
{:git "git"
:describe-pattern git/git-describe-pattern
:tag-to-version nil
:status-to-version nil
:version-file nil
:version-file-keys [:ref :ref-short :tag :ahead :ahead? :dirty? :message :timestamp :version]})

(defn default-status-to-version
"A function you may want use for :status-to-version"
[{:keys [tag version branch ahead ahead? dirty?] :as git}]
(assert (re-find #"\d+\.\d+\.\d+" tag)
"Tag is assumed to be a raw SemVer version")
(if (and tag (not ahead?) (not dirty?))
tag
(let [[_ prefix patch] (re-find #"(\d+\.\d+)\.(\d+)" tag)
patch (Long/parseLong patch)
patch+ (inc patch)]
(format "%s.%d-%s-SNAPSHOT" prefix patch+ branch))))

(defn write-version-file
"Write a project \"version\" file."
[{:keys [root] :as project} file keys]
Expand Down