Fallback to the original behaviour on any error invoking git plumbing
This commit is contained in:
parent
5dfa542f8f
commit
4fc9e61fdd
1 changed files with 13 additions and 4 deletions
|
@ -37,15 +37,24 @@
|
|||
(.trim (slurp ref))
|
||||
nil)))
|
||||
|
||||
(defn- read-git-head-file
|
||||
"Reads the current value of HEAD by attempting to read .git/HEAD, returning
|
||||
the SHA1 or nil if none exists"
|
||||
[git-dir]
|
||||
(let [head (.trim (slurp (str (io/file git-dir "HEAD"))))]
|
||||
(if-let [ref-path (second (re-find #"ref: (\S+)" head))]
|
||||
(read-git-ref git-dir ref-path))))
|
||||
|
||||
(defn- read-git-head
|
||||
"Reads the value of HEAD and returns a commit SHA1, or nil if no commit
|
||||
exist."
|
||||
[git-dir]
|
||||
(try
|
||||
(:out (sh/sh "git" "rev-parse" "HEAD" :dir git-dir))
|
||||
(catch IOException e (let [head (.trim (slurp (str (io/file git-dir "HEAD"))))]
|
||||
(if-let [ref-path (second (re-find #"ref: (\S+)" head))]
|
||||
(read-git-ref git-dir ref-path))))))
|
||||
(let [git-ref (sh/sh "git" "rev-parse" "HEAD" :dir git-dir)]
|
||||
(if (= (:exit git-ref) 0)
|
||||
(:out git-ref)
|
||||
(read-git-head-file git-dir)))
|
||||
(catch IOException e (read-git-head-file git-dir))))
|
||||
|
||||
(defn- read-git-origin
|
||||
"Reads the URL for the remote origin repository."
|
||||
|
|
Loading…
Reference in a new issue