From 94053198571ca2af19b366aede548c76b99441a3 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Fri, 25 Jan 2013 11:44:59 +0100 Subject: [PATCH 1/3] Allow configuration via project.clj --- README.md | 19 +++++++++++++++++++ src/lein_git_version/plugin.clj | 7 ++++--- src/leiningen/git_version.clj | 21 ++++++++++++--------- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 53c07cc..9af9c75 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,25 @@ 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 add 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` translates the tag into the 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)))) From f69474257574ba18f6fcc5a90698b2f2f13b56d5 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Fri, 25 Jan 2013 11:58:07 +0100 Subject: [PATCH 2/3] Documentation fixes. --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9af9c75..ec25ace 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ You can do this: ## 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 add configure +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. @@ -61,7 +61,8 @@ The following are the defaults: :tag->version (fn [tag] (apply str (rest tag)))}) `describe-command` is a shell command that should print the current -tag, and `:tag->version` translates the tag into the version string. +tag, and `tag->version` is a function that translates the tag into a +version string. ## License From 06ac6fa4d9a281655c8a6ee5227e7ac08e529c71 Mon Sep 17 00:00:00 2001 From: Joost Diepenmaat Date: Fri, 25 Jan 2013 12:03:16 +0100 Subject: [PATCH 3/3] Another little typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec25ace..ae0288c 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ The following are the defaults: (defproject nifty "bLAH BLaH" ... :git-version {:describe-command ["git" "describe" "--match" - "v*.*""--abbrev=4" + "v*.*" "--abbrev=4" "--dirty=**DIRTY**"] :tag->version (fn [tag] (apply str (rest tag)))})