From 80cf398b50c21b5d15a38f46f7b69b92fe132e50 Mon Sep 17 00:00:00 2001 From: David Greenberg Date: Tue, 27 Nov 2012 20:46:59 -0500 Subject: [PATCH] Allow project's git repository to be different than project root This allows for other directories to be used for the automatic repository tagging. This is useful for repositories that contain multiple projects, such as leiningen-core and leiningen, so that both will have the correct repository tag information in their pom.xml. --- leiningen-core/project.clj | 1 + sample.project.clj | 8 +++++++- src/leiningen/pom.clj | 17 +++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/leiningen-core/project.clj b/leiningen-core/project.clj index 2486ac56b..0377d4177 100644 --- a/leiningen-core/project.clj +++ b/leiningen-core/project.clj @@ -11,6 +11,7 @@ [com.cemerick/pomegranate "0.0.13" :exclusions [org.slf4j/slf4j-api]]] :repositories [["classic" "https://clojars.org/repo/"]] + :scm {:dir ".."} ;; This is only used when releasing Leiningen. Can't put it in a ;; profile since it must be installed using lein1 ;;:aot :all diff --git a/sample.project.clj b/sample.project.clj index cdd0bdb49..952aab483 100644 --- a/sample.project.clj +++ b/sample.project.clj @@ -265,7 +265,13 @@ ;; Include tag in generated pom.xml file. All key/value pairs ;; appear exactly as configured. If absent, Leiningen will try to ;; use information from a .git directory. - :scm {:name "git" :tag "098afd745bcd" :url "http://127.0.0.1/git/my-project"} + :scm {:name "git" + :tag "098afd745bcd" + :url "http://127.0.0.1/git/my-project" + ;; Allows you to use a repository in a different directory than the + ;; project's root, for instance, if you had multiple projects in a + ;; single git repository. + :dir ".."} ;; include arbitrary xml in generated pom.xml file :pom-addition [:developers [:developer [:name "My Name"]]]) diff --git a/src/leiningen/pom.clj b/src/leiningen/pom.clj index 8c04429fd..349bc7f80 100644 --- a/src/leiningen/pom.clj +++ b/src/leiningen/pom.clj @@ -20,12 +20,13 @@ ;; git scm -(defn- resolve-git-dir [git-dir] - (let [git-dir-file (io/file git-dir)] - (cond - (.isDirectory git-dir-file) git-dir-file - (.isFile git-dir-file) (io/file (second (re-find #"gitdir: (\S+)" (slurp (str git-dir-file))))) - :else git-dir))) +(defn- resolve-git-dir [project] + (let [alternate-git-root (io/file (get-in project [:scm :dir])) + git-dir-file (io/file (or alternate-git-root (:root project)) ".git")] + (if + (.isFile git-dir-file) + (io/file (second (re-find #"gitdir: (\S+)" (slurp (str git-dir-file))))) + git-dir-file))) (defn- read-git-ref "Reads the commit SHA1 for a git ref path." @@ -110,7 +111,7 @@ Retains backwards compatibility without an :scm map." (if (= "auto" scm) - (make-git-scm (resolve-git-dir (io/file (:root project) ".git"))) + (make-git-scm (resolve-git-dir project)) (xml-tags :scm (xmlify (select-keys (:scm project) [:url :connection :tag :developerConnection]))))) @@ -337,7 +338,7 @@ (.setProperty "version" (:version project)) (.setProperty "groupId" (:group project)) (.setProperty "artifactId" (:name project))) - git-head (resolve-git-dir (io/file (:root project) ".git"))] + git-head (resolve-git-dir project)] (when (.exists git-head) (.setProperty properties "revision" (read-git-head git-head))) (.store properties baos "Leiningen"))