Created
March 29, 2012 22:56
-
-
Save kurtharriger/2244645 to your computer and use it in GitHub Desktop.
git extended version for leiningen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (use '[clojure.java.shell :only [sh]]) | |
| (def version "0.1.1") | |
| (defn clean? [] | |
| (empty? (:out (sh "git" "diff-index" "HEAD")))) | |
| (defn tagged? [version] | |
| (let [tag (.trim (:out (sh "git" "describe" "--tags" "--exact-match") ""))] | |
| (= tag version))) | |
| (defn get-branch [] | |
| "Returns branch name if not master" | |
| (let [ref (:out (sh "git" "symbolic-ref" "HEAD") "") | |
| [[_ branch]] (re-seq #"refs/heads/(.*)" ref) | |
| ;; if detatched head on ci server check environment variable | |
| branch (if branch branch (System/getenv "BRANCH")) ] | |
| (if-not (= branch "master") branch))) | |
| (defn get-hash [] | |
| (.substring (:out (sh "git" "rev-parse" "HEAD")) 0 6)) | |
| ;; if version is tagged and working copy is clean use unmodified version | |
| ;; otherwise append branch (when not master) | |
| ;; and hash if clean, or -"SNAPSHOT" when dirty | |
| (def version+ | |
| (let [clean (clean?)] | |
| (if (and clean (tagged? version)) version | |
| (str version | |
| (if-let [branch (get-branch)] (str "-" branch)) | |
| "-" (if clean (get-hash) "SNAPSHOT"))))) | |
| (defproject cherry-pitter version+ | |
| ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment