-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
core.clj
53 lines (43 loc) · 1.72 KB
/
core.clj
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 polylith.clj.core.git.core
(:require [clojure.string :as str]
[polylith.clj.core.git.tag :as tag]
[polylith.clj.core.shell.interface :as shell]))
(defn is-git-repo? [ws-dir]
(try
(= "true" (first (str/split-lines (shell/sh "git" "rev-parse" "--is-inside-work-tree" :dir ws-dir))))
(catch Exception _
false)))
(defn init [ws-dir]
(try
(shell/sh "git" "init" :dir ws-dir)
(shell/sh "git" "add" "." :dir ws-dir)
(shell/sh "git" "commit" "-m" "Workspace created." :dir ws-dir)
(catch Exception e
(println (str "Cannot create a git repository for the workspace.\n"
"Please try to create it manually instead: " (.getMessage e))))))
(defn add [ws-dir filename]
(shell/sh "git" "add" filename :dir ws-dir))
(defn diff-command-parts [sha1 sha2]
(if sha1
(if sha2
["git" "diff" sha1 sha2 "--name-only"]
["git" "diff" sha1 "--name-only"])
["git" "diff" "--name-only"]))
(defn diff-command [sha1 sha2]
(str/join " " (diff-command-parts sha1 sha2)))
(defn diff [ws-dir sha1 sha2]
(let [files (apply shell/sh (concat (diff-command-parts sha1 sha2)
[:dir ws-dir]))]
(str/split-lines files)))
(defn first-committed-sha [ws-dir]
(last (str/split-lines (shell/sh "git" "log" "--format=%H" :dir ws-dir))))
(defn drop-or-keep [elements drop?]
(when elements (if drop? (rest elements) elements)))
(defn release [ws-dir pattern previous?]
(or (-> (tag/matching-tags ws-dir pattern)
(drop-or-keep previous?)
first)
{:sha (first-committed-sha ws-dir)}))
(defn latest-stable [ws-dir pattern]
(or (first (tag/matching-tags ws-dir pattern))
{:sha (first-committed-sha ws-dir)}))