-
Notifications
You must be signed in to change notification settings - Fork 10
/
diff.clj
47 lines (40 loc) · 1.59 KB
/
diff.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
(ns leiningen.polylith.cmd.diff
(:require [leiningen.polylith.file :as file]
[leiningen.polylith.time :as time]
[leiningen.polylith.git :as git]))
(defn ci? []
(or (System/getenv "CI")
(System/getProperty "CI")))
(defn changed-file-paths-with-git [ws-path args]
(let [last-successful-sha1 (git/parse-git-args ws-path args)
current-sha1 (git/current-sha1 ws-path)
paths (git/diff ws-path last-successful-sha1 current-sha1)]
(file/filter-invalid-paths paths)))
(defn changed-file-paths-with-time
([include-time? ws-path args]
(let [time (time/parse-time-args ws-path args)
all-paths (file/valid-paths ws-path)]
(file/changed-relative-paths include-time? ws-path all-paths time)))
([ws-path args]
(changed-file-paths-with-time false ws-path args)))
(defn changed-file-paths
([include-time? ws-path args]
(if (ci?)
(changed-file-paths-with-git ws-path args)
(changed-file-paths-with-time include-time? ws-path args)))
([ws-path args]
(changed-file-paths false ws-path args)))
(defn path-with-time->string [show-time? path]
(if show-time?
(str (first path) " " (time/->time (first path)) " " (second path))
path))
(defn print-paths [paths show-time?]
(doseq [path paths]
(if (ci?)
(println " " path)
(println " " (path-with-time->string show-time? path)))))
(defn execute [ws-path args]
(let [show-time? (contains? (set args) "+")
without-plus (filter #(not= "+" %) args)
paths (changed-file-paths show-time? ws-path without-plus)]
(print-paths paths show-time?)))