|
24 | 24 | (URL. (str "http://" url))))) |
25 | 25 |
|
26 | 26 | (defn read-file |
27 | | - "Read the contents of file if it exists." |
| 27 | + "Returns the first Clojure form in a file if it exists." |
28 | 28 | [file] |
29 | 29 | (if (.exists file) |
30 | 30 | (try (read-string (slurp file)) |
31 | 31 | (catch Exception e |
32 | | - (binding [*out* *err*] |
| 32 | + (binding [*out* *err*] ;; TODO: use main/warn for this in 3.0 |
33 | 33 | (println "Error reading" |
34 | 34 | (.getName file) |
35 | 35 | "from" |
|
55 | 55 | [".clj" (str clojure.lang.RT/LOADER_SUFFIX ".class")])) |
56 | 56 |
|
57 | 57 | (defn error [& args] |
58 | | - (binding [*out* *err*] |
| 58 | + (binding [*out* *err*] ;; TODO: use main/warn for this in 3.0 |
59 | 59 | (apply println "Error:" args))) |
60 | 60 |
|
61 | 61 | (defn require-resolve |
|
116 | 116 |
|
117 | 117 | ;; # Git |
118 | 118 |
|
| 119 | +;; This is very similar to the read-file function above. The only differences |
| 120 | +;; are the error messages and the transformations done on the content. |
| 121 | +(defn- git-file-contents |
| 122 | + "Returns the (trimmed) contents by the given git path, or nil if it is |
| 123 | + inacessible or nonexisting. If it exists and is not readable, a warning is |
| 124 | + printed." |
| 125 | + [git-dir ref-path] |
| 126 | + (let [ref (io/file git-dir ref-path)] |
| 127 | + (println (.toString ref)) |
| 128 | + (if (.canRead ref) |
| 129 | + (.trim (slurp ref)) |
| 130 | + (do |
| 131 | + (when (.exists ref) |
| 132 | + (binding [*out* *err*] ;; TODO: use main/warn for this in 3.0 |
| 133 | + (println "Warning: Contents of git file" |
| 134 | + (str ".git/" ref-path) "is not readable.") |
| 135 | + (println "(Check that you have the right permissions to read" |
| 136 | + "the .git repo)"))) |
| 137 | + nil)))) |
| 138 | + |
119 | 139 | (defn ^:internal resolve-git-dir [project] |
120 | 140 | (let [alternate-git-root (io/file (get-in project [:scm :dir])) |
121 | 141 | git-dir-file (io/file (or alternate-git-root (:root project)) ".git")] |
122 | | - (if (.isFile git-dir-file) |
| 142 | + (if (and (.isFile git-dir-file) (.canRead git-dir-file)) |
123 | 143 | (io/file (second (re-find #"gitdir: (\S+)" (slurp (str git-dir-file))))) |
124 | 144 | git-dir-file))) |
125 | 145 |
|
126 | 146 | (defn- read-git-ref |
127 | 147 | "Reads the commit SHA1 for a git ref path, or nil if no commit exist." |
128 | 148 | [git-dir ref-path] |
129 | | - (let [ref (io/file git-dir ref-path)] |
130 | | - (if (.exists ref) |
131 | | - (.trim (slurp ref)) |
132 | | - nil))) |
| 149 | + (git-file-contents git-dir ref-path)) |
133 | 150 |
|
134 | 151 | (defn- read-git-head-file |
135 | 152 | "Reads the current value of HEAD by attempting to read .git/HEAD, returning |
136 | 153 | the SHA1 or nil if none exists." |
137 | 154 | [git-dir] |
138 | | - (let [head (.trim (slurp (str (io/file git-dir "HEAD"))))] |
139 | | - (if-let [ref-path (second (re-find #"ref: (\S+)" head))] |
140 | | - (read-git-ref git-dir ref-path)))) |
| 155 | + (some->> (git-file-contents git-dir "HEAD") |
| 156 | + (re-find #"ref: (\S+)") |
| 157 | + (second) |
| 158 | + (read-git-ref git-dir))) |
141 | 159 |
|
142 | | -;; TODO: de-dupe with pom namespace |
| 160 | +;; TODO: de-dupe with pom namespace (3.0?) |
143 | 161 |
|
144 | 162 | (defn ^:internal read-git-head |
145 | 163 | "Reads the value of HEAD and returns a commit SHA1, or nil if no commit |
|
0 commit comments