Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Skip git revision in pom.xml if empty git repo.

Tests if the git ref path exists before slurping the SHA from it. If it does not
exist, return nil instead of throwing an error. Also remove empty references to
the SHA where they may occur.
  • Loading branch information...
commit 23da9257a2f04a2a2b7a7e6e1673947a59330fdc 1 parent 723671b
@hyPiRion hyPiRion authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 src/leiningen/pom.clj
View
16 src/leiningen/pom.clj
@@ -29,12 +29,16 @@
git-dir-file)))
(defn- read-git-ref
- "Reads the commit SHA1 for a git ref path."
+ "Reads the commit SHA1 for a git ref path, or nil if no commit exist."
[git-dir ref-path]
- (.trim (slurp (str (io/file git-dir ref-path)))))
+ (let [ref (io/file git-dir ref-path)]
+ (if (.exists ref)
+ (.trim (slurp ref))
+ nil)))
(defn- read-git-head
- "Reads the value of HEAD and returns a commit SHA1."
+ "Reads the value of HEAD and returns a commit SHA1, or nil if no commit
+ exist."
[git-dir]
(let [head (.trim (slurp (str (io/file git-dir "HEAD"))))]
(if-let [ref-path (second (re-find #"ref: (\S+)" head))]
@@ -78,7 +82,8 @@
[:connection (str "scm:git:" (:public-clone urls))])
(and (:dev-clone urls)
[:developerConnection (str "scm:git:" (:dev-clone urls))])
- [:tag head]
+ (and head
+ [:tag head])
[:url (:browse urls)]])
(catch java.io.FileNotFoundException _)))
@@ -340,7 +345,8 @@
(.setProperty "artifactId" (:name project)))
git-head (resolve-git-dir project)]
(when (.exists git-head)
- (.setProperty properties "revision" (read-git-head git-head)))
+ (if-let [revision (read-git-head git-head)]
+ (.setProperty properties "revision" revision)))
(.store properties baos "Leiningen"))
(str baos)))
Please sign in to comment.
Something went wrong with that request. Please try again.