diff --git a/README.md b/README.md index 53c07cc..ae0288c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/lein_git_version/plugin.clj b/src/lein_git_version/plugin.clj index 35b2a58..902cdd5 100644 --- a/src/lein_git_version/plugin.clj +++ b/src/lein_git_version/plugin.clj @@ -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)))) diff --git a/src/leiningen/git_version.clj b/src/leiningen/git_version.clj index 4af74db..54b1377 100644 --- a/src/leiningen/git_version.clj +++ b/src/leiningen/git_version.clj @@ -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))))