This repository was archived by the owner on Sep 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathgit.clj
More file actions
53 lines (48 loc) · 1.77 KB
/
git.clj
File metadata and controls
53 lines (48 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns lein-git-down.impl.git
(:refer-clojure :exclude [resolve])
(:require [clojure.java.io :as io]
[clojure.string :as string]
[clojure.tools.gitlibs :as git]
[clojure.tools.gitlibs.impl :as git-impl]
[leiningen.core.main :as lein]
[robert.hooke :as hooke])
(:import (org.eclipse.jgit.api TransportConfigCallback Git)
(java.io File)))
(defn dev-null-hook
[_ & _])
(defn procure
"Monkey patches gitlibs/procure to writes a meta-data file with information about the source."
[uri mvn-coords rev]
(hooke/with-scope
(hooke/add-hook #'git-impl/printerrln #'dev-null-hook)
(let [path (git/procure uri mvn-coords rev)
meta (io/file path ".lein-git-down")]
(when-not (.exists meta)
(spit meta {:uri uri :mvn-coords mvn-coords :rev rev}))
path)))
(defn resolve
"Monkey patches gitlibs/resolve to silence errors."
[uri version]
(hooke/with-scope
(hooke/add-hook #'git-impl/printerrln #'dev-null-hook)
(git/resolve uri version)))
(defn init
"Initializes a fresh git repository at `project-dir` and sets HEAD to the
provided rev, which allows tooling to retrieve the correct HEAD commit in
the gitlibs repo directory. Returns the .git directory."
[^File project-dir rev]
(let [git-dir (.. (Git/init)
(setDirectory project-dir)
call
getRepository
getDirectory)]
(spit (io/file git-dir "HEAD") rev)
git-dir))
(defn rm
"Removes the .git directory returning a checkout back to just the checked
out code."
[^File git-dir]
(when (and (.exists git-dir) (= ".git" (.getName git-dir)))
(->> (file-seq git-dir)
reverse
(run! #(when (.exists %) (.delete %))))))