Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip git revision in pom if empty git repo. Fixes #887. #888

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/leiningen/pom.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down Expand Up @@ -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 _)))

Expand Down Expand Up @@ -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)))

Expand Down