Welcome! Please see the About page for a little more info on how this works.

+2 votes
in tools.build by
closed by

I want api to get git hash to find the exact version.
Thank you.

(defn git-hash
  "Shells out to git and returns hash of commits on this branch:
    git rev-parse HEAD

  Options:
    :dir - dir to invoke this command from, by default current directory
    :short? - shorten hash to 7 length characters"
  [{:keys [dir short?] :or {dir "."} :as params}]
  (assert-specs "git-hash" params
                :dir ::specs/path
                :short? ::specs/boolean)
  (-> {:command-args (cond-> ["git" "rev-parse"]
                       short? (conj "--short")
                       :default (conj "HEAD"))
       :dir (.getPath (resolve-path dir))
       :out :capture}
      process
      :out
      str/trim))
closed with the note: Use git-process as of v0.6.5: (api/git-process {:git-args "rev-parse --short HEAD"})

2 Answers

0 votes
by

Just curious - what are you using it for?

by
I used to include the commit-sha in the final bundle, to I can include this info in "--version" info and on datomic audit-tx
by
Sorry I forgot to write why I need this.

I am thinking of using git hash to tag artifacts.
by
+1 for naming uber-file.

would it be good to place it `tools.gitlib`?
0 votes
by
...