This repository has been archived by the owner on Jun 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.cljs
62 lines (55 loc) · 1.61 KB
/
git.cljs
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
54
55
56
57
58
59
60
61
62
(ns re-conf.resources.git
"Git resources"
(:refer-clojure :exclude [clone])
(:require-macros
[clojure.core.strint :refer (<<)])
(:require
[clojure.string :refer (includes?)]
[cljs-node-io.core :as io]
[re-conf.resources.shell :refer (sh)]
[re-conf.resources.facts :refer (os)]
[re-conf.resources.log :refer (info debug error)]
[re-conf.resources.common :refer (run)]
[cljs.core.async :refer [<! go]]))
(def fs (js/require "fs"))
(defn- binary
"Grab git binary path"
[]
(go
(let [{:keys [platform]} (<! (os))]
(case platform
"linux" "/usr/bin/git"
"freebsd" "/usr/local/bin/git"
:default {:error (<< "No matching git binary path found for ~{platform}")}))))
(defn- repo-exists?
[repo path]
(when (.existsSync fs (<< "~{path}/.git/config"))
(includes? (io/slurp (<< "~{path}/.git/config")) repo)))
(defn run-pull
"Pull implementation"
[repo dest]
(go
(if (repo-exists? repo dest)
(let [git (<! (binary))]
(<! (sh git (<< "--git-dir=~{dest}.git") "pull")))
{:ok (<< "Skipping pull ~{repo} is missing under ~{dest}")})))
(defn run-clone
"Clone implementation"
[repo dest]
(go
(if-not (repo-exists? repo dest)
(let [git (<! (binary))]
(<! (sh git "clone" repo dest)))
{:ok (<< "Skipping clone ~{repo} exists under ~{dest}")})))
(defn clone
"Clone a git repo resource"
([repo dest]
(run-clone repo dest))
([c repo dest]
(run c clone [repo dest])))
(defn pull
"Pull latest changes from a git repo resource"
([repo dest]
(run-pull repo dest))
([c repo dest]
(run c pull [repo dest])))