diff --git a/doc/DEPLOY.md b/doc/DEPLOY.md index 97db27288..515b590d6 100644 --- a/doc/DEPLOY.md +++ b/doc/DEPLOY.md @@ -297,6 +297,13 @@ libraries using Leiningen. Applications will have different requirements that are varied enough that Leiningen doesn't attempt to support them out of the box. +### Tagging + +By default `["vcs" "tag"]` will create a GPG signed tag with your project version +number. You can add a tag prefix by passing the prefix after `"tag"`, +for example: `["vcs" "tag" "v"]`. You can disable tag signing by passing `--no-sign`, +for example: `["vcs" "tag" "v" "--no-sign"]` or `["vcs" "tag" "--no-sign"]`. + ## Deploying to Maven Central Deploying your libraries and other artifacts to [Maven diff --git a/src/leiningen/vcs.clj b/src/leiningen/vcs.clj index bacd8243b..b418272c7 100644 --- a/src/leiningen/vcs.clj +++ b/src/leiningen/vcs.clj @@ -16,7 +16,15 @@ (defn which-vcs [project & _] (or (:vcs project) (some (partial uses-vcs project) @supported-systems))) - +(defn parse-tag-args [args] + (loop [parsed-args {:sign? true} + args args] + (case (first args) + ("--sign" "-s") (recur (assoc parsed-args :sign? true) (rest args)) + "--no-sign" (recur (assoc parsed-args :sign? false) (rest args)) + nil parsed-args ;; We're finished and can exit + (recur (assoc parsed-args :prefix (first args)) (rest args))))) + ;;; Methods (defmulti push "Push to your remote repository." @@ -31,7 +39,6 @@ (defmulti assert-committed "Abort if uncommitted changes exist." which-vcs :default :none) - ;;; VCS not found @@ -48,6 +55,7 @@ (defmethod assert-committed :none [project] (unknown-vcs "assert-committed")) + ;;; Git (defmethod push :git [project & args] @@ -59,12 +67,15 @@ (binding [eval/*dir* (:root project)] (eval/sh-with-exit-code "Couldn't commit" "git" "commit" "-a" "-m" (str "Version " (:version project))))) -(defmethod tag :git [{:keys [root version]} & [prefix]] +(defmethod tag :git [{:keys [root version]} & args] (binding [eval/*dir* root] - (let [tag (if prefix + (let [{:keys [sign? prefix]} (parse-tag-args args) + tag (if prefix (str prefix version) - version)] - (eval/sh-with-exit-code "Couldn't tag" "git" "tag" "-s" tag "-m" (str "Release " version))))) + version) + cmd (->> ["git" "tag" (when sign? "--sign") tag "-m" (str "Release " version)] + (filter some?))] + (apply eval/sh-with-exit-code "Couldn't tag" cmd)))) (defmethod assert-committed :git [project] (binding [eval/*dir* (:root project)] diff --git a/test/leiningen/test/vcs.clj b/test/leiningen/test/vcs.clj new file mode 100644 index 000000000..9815f19ff --- /dev/null +++ b/test/leiningen/test/vcs.clj @@ -0,0 +1,15 @@ +(ns leiningen.test.vcs + (:require [clojure.test :refer :all] + [leiningen.vcs :as vcs])) + +(deftest parsed-args + (testing "VCS tag argument parsing" + (are [args parsed-args] (= (vcs/parse-tag-args args) parsed-args) + [] {:sign? true} + ["v"] {:prefix "v" :sign? true} + ["v" "--sign"] {:prefix "v" :sign? true} + ["--sign"] {:sign? true} + ["--no-sign"] {:sign? false} + ["--no-sign" "v"] {:prefix "v" :sign? false} + ["-s"] {:sign? true} + ["v" "r"] {:prefix "r" :sign? true})))