Skip to content
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: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ You can do this:
(def version "1.0.0")
$

## Configuration

If you have your own version tagging scheme, and/or some other way of
grabbing a version string from your source tree, you can configure
lein-git-version by adding keys to the :git-version hash-map in your
project.

The following are the defaults:

(defproject nifty "bLAH BLaH"
...
:git-version {:describe-command ["git" "describe" "--match"
"v*.*" "--abbrev=4"
"--dirty=**DIRTY**"]
:tag->version (fn [tag] (apply str (rest tag)))})

`describe-command` is a shell command that should print the current
tag, and `tag->version` is a function that translates the tag into a
version string.

## License

Copyright © 2012 Colin Steele
Expand Down
7 changes: 4 additions & 3 deletions src/lein_git_version/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

(defn middleware
[project]
(let [code (str
(let [version (get-git-version (:git-version project))
code (str
";; Do not edit. Generated by lein-git-version plugin.\n"
"(ns " (:name project) ".version)\n"
"(def version \"" (get-git-version) "\")\n")
"(def version \"" version "\")\n")
filename (str (first (:source-paths project)) "/"
(:name project) "/version.clj")]
(-> project
(update-in [:injections] concat `[(spit ~filename ~code)])
(assoc :version (get-git-version)))))
(assoc :version version))))
21 changes: 12 additions & 9 deletions src/leiningen/git_version.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
[leiningen.core.main]
[leiningen.core.project]
[robert.hooke]
[leiningen.test])
[leiningen.test]
[clojure.string :as str])
(:use
[clojure.java.shell :only [sh]]))

(def defaults
{:describe-command ["git" "describe" "--match" "v*.*"
"--abbrev=4" "--dirty=**DIRTY**"]
:tag->version '(fn [tag] (apply str (rest tag)))})

(defn get-git-version
[]
(apply str (rest (clojure.string/trim
(:out (sh
"git" "describe" "--match" "v*.*"
"--abbrev=4" "--dirty=**DIRTY**"))))))
[& [config]]
(let [{:keys [tag->version describe-command]} (merge defaults config)]
((eval tag->version) (str/trim (:out (apply sh describe-command))))))

(defn git-version
"Main project task."
^{:doc "Show git project version"}
"Show git project version"
[project & args]
(println (get-git-version)))
(println (get-git-version (:git-version project))))