Skip to content

Commit 0bc3443

Browse files
committed
Merge branch 'master' into add-tags
2 parents 223f0c2 + 2d14969 commit 0bc3443

File tree

9 files changed

+140
-142
lines changed

9 files changed

+140
-142
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
===========
33

4+
* 2.1.129 on Mar 10, 2021
5+
* Change git options during checkout to work with more git versions
6+
* Check exit code on checkout and throw if failed
7+
* Overhaul config and debug settings
8+
* Change min Clojure dep to 1.9
49
* 2.0.119 on Mar 10, 2021
510
* Fix issues with checkouts of multiple commits per repo
611
* resolve now only fetches if it can't resolve a ref

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ The cache location can also be set with the environment variable GITLIBS.
8383

8484
This project follows the version scheme MAJOR.MINOR.COMMITS where MAJOR and MINOR provide some relative indication of the size of the change, but do not follow semantic versioning. In general, all changes endeavor to be non-breaking (by moving to new names rather than by breaking existing names). COMMITS is an ever-increasing counter of commits since the beginning of this repository.
8585

86-
Latest release: 2.0.119
86+
Latest release: 2.1.129
8787

8888
* [All released versions](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.clojure%22%20AND%20a%3A%22tools.gitlibs%22)
89-
* Coordinates: `org.clojure/tools.gitlibs {:mvn/version "2.0.119"}`
89+
* Coordinates: `org.clojure/tools.gitlibs {:mvn/version "2.1.129"}`
9090

9191
# Developer Information
9292

VERSION_TEMPLATE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.GENERATED_VERSION
1+
2.1.GENERATED_VERSION

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{:paths ["src/main/clojure"]
2-
:deps {org.clojure/clojure {:mvn/version "1.8.0"}}}
2+
:deps {org.clojure/clojure {:mvn/version "1.9.0"}}}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22
<modelVersion>4.0.0</modelVersion>
33
<artifactId>tools.gitlibs</artifactId>
4-
<version>2.0.120-SNAPSHOT</version>
4+
<version>2.1.130-SNAPSHOT</version>
55
<name>tools.gitlibs</name>
66

77
<parent>
@@ -19,7 +19,7 @@
1919

2020
<properties>
2121
<clojure.warnOnReflection>true</clojure.warnOnReflection>
22-
<clojure.version>1.8.0</clojure.version>
22+
<clojure.version>1.9.0</clojure.version>
2323
</properties>
2424

2525
<dependencies>

src/main/clojure/clojure/tools/gitlibs.clj

Lines changed: 38 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
(:refer-clojure :exclude [resolve])
1515
(:require
1616
[clojure.java.io :as jio]
17+
[clojure.tools.gitlibs.config :as config]
1718
[clojure.tools.gitlibs.impl :as impl]))
1819

1920
(set! *warn-on-reflection* true)
@@ -22,79 +23,55 @@
2223
"Return the root gitlibs cache directory. By default ~/.gitlibs or
2324
override by setting the environment variable GITLIBS."
2425
[]
25-
(impl/cache-dir))
26+
(:gitlibs/dir @config/CONFIG))
2627

2728
;; Possible new API, internal for now
2829
(defn- resolve-all
2930
"Takes a git url and a coll of revs, and returns the full commit shas.
3031
Each rev may be a partial sha, full sha, or tag name. Returns nil for
31-
unresolveable revs.
32-
33-
Optional opts map may include:
34-
:interactive (default false) - set true to allow stdin prompts (example: unknown host)
35-
:print-commands (default false) - set true to write git executions to stderr"
36-
([url revs]
37-
(resolve-all url revs nil))
38-
([url revs opts]
39-
(let [git-dir (impl/ensure-git-dir url opts)]
40-
(reduce
41-
(fn [rs r]
42-
(if-let [res (impl/git-rev-parse git-dir r opts)]
43-
(conj rs res)
44-
(do ;; could not resolve - fetch and try again
45-
(impl/git-fetch (jio/file git-dir) opts)
46-
(conj rs (impl/git-rev-parse git-dir r opts)))))
47-
[] revs))))
32+
unresolveable revs."
33+
[url revs]
34+
(let [git-dir (impl/ensure-git-dir url)]
35+
(reduce
36+
(fn [rs r]
37+
(if-let [res (impl/git-rev-parse git-dir r)]
38+
(conj rs res)
39+
(do ;; could not resolve - fetch and try again
40+
(impl/git-fetch (jio/file git-dir))
41+
(conj rs (impl/git-rev-parse git-dir r)))))
42+
[] revs)))
4843

4944
(defn resolve
5045
"Takes a git url and a rev, and returns the full commit sha or nil if can't
51-
resolve. rev may be a partial sha, full sha, or tag name.
52-
53-
Optional opts map may include:
54-
:interactive (default false) - set true to allow stdin prompts (example: unknown host)
55-
:print-commands (default false) - set true to write git executions to stderr"
56-
([url rev]
57-
(resolve url rev nil))
58-
([url rev opts]
59-
(first (resolve-all url [rev] opts))))
46+
resolve. rev may be a partial sha, full sha, or tag name."
47+
[url rev]
48+
(first (resolve-all url [rev])))
6049

6150
(defn procure
6251
"Procure a working tree at rev for the git url representing the library lib,
6352
returns the directory path. lib is a qualified symbol where the qualifier is a
64-
controlled or conveyed identity, or nil if rev is unknown.
65-
66-
Optional opts map may include:
67-
:interactive (default false) - set true to allow stdin prompts (example: unknown host)
68-
:print-commands (default false) - set true to write git commands to stderr"
69-
([url lib rev]
70-
(procure url lib rev nil))
71-
([url lib rev opts]
72-
(let [lib-dir (impl/lib-dir lib)
73-
git-dir-path (impl/ensure-git-dir url opts)
74-
sha (or (impl/match-exact lib-dir rev) (impl/match-prefix lib-dir rev) (resolve url rev))]
75-
(when sha
76-
(let [sha-dir (jio/file lib-dir sha)]
77-
(when-not (.exists sha-dir)
78-
(impl/printerrln "Checking out:" url "at" rev)
79-
(impl/git-checkout git-dir-path lib-dir sha opts))
80-
(.getCanonicalPath sha-dir))))))
53+
controlled or conveyed identity, or nil if rev is unknown."
54+
[url lib rev]
55+
(let [lib-dir (impl/lib-dir lib)
56+
git-dir-path (impl/ensure-git-dir url)
57+
sha (or (impl/match-exact lib-dir rev) (impl/match-prefix lib-dir rev) (resolve url rev))]
58+
(when sha
59+
(let [sha-dir (jio/file lib-dir sha)]
60+
(when-not (.exists sha-dir)
61+
(impl/printerrln "Checking out:" url "at" rev)
62+
(impl/git-checkout git-dir-path lib-dir sha))
63+
(.getCanonicalPath sha-dir)))))
8164

8265
(defn descendant
8366
"Returns rev in git url which is a descendant of all other revs,
84-
or nil if no such relationship can be established.
85-
86-
Optional opts map may include:
87-
:interactive (default false) - set true to allow stdin prompts (example: unknown host)
88-
:print-commands (default false) - set true to write git commands to stderr"
89-
([url rev]
90-
(descendant url rev nil))
91-
([url revs opts]
92-
(when (seq revs)
93-
(let [shas (resolve-all url revs opts)]
94-
(if (seq (filter nil? shas))
95-
nil ;; can't resolve all shas in this repo
96-
(let [git-dir (impl/ensure-git-dir url opts)]
97-
(->> shas (sort (partial impl/commit-comparator git-dir opts)) first)))))))
67+
or nil if no such relationship can be established."
68+
[url revs]
69+
(when (seq revs)
70+
(let [shas (resolve-all url revs)]
71+
(if (seq (filter nil? shas))
72+
nil ;; can't resolve all shas in this repo
73+
(let [git-dir (impl/ensure-git-dir url)]
74+
(->> shas (sort (partial impl/commit-comparator git-dir)) first))))))
9875

9976
(defn tags
10077
"Returns coll of tags in git url"
@@ -104,8 +81,9 @@
10481
(impl/tags (impl/ensure-git-dir url opts) opts)))
10582

10683
(comment
107-
(resolve "[email protected]:clojure/tools.gitlibs.git" "11fc774" {:print-commands true :interactive true})
108-
(descendant "https://github.com/clojure/tools.gitlibs.git" ["5e2797a487c" "11fc774" "d82adc29" "815e312310"] {:print-commands true})
84+
(System/setProperty "clojure.gitlibs.debug" "true")
85+
(resolve "[email protected]:clojure/tools.gitlibs.git" "11fc774")
86+
(descendant "https://github.com/clojure/tools.gitlibs.git" ["5e2797a487c" "11fc774" "d82adc29" "815e312310"])
10987

11088
(println
11189
@(future (procure "https://github.com/clojure/tools.gitlibs.git" 'org.clojure/tools.gitlibs "11fc77496f013871c8af3514bbba03de0af28061"))
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; Copyright (c) Rich Hickey. All rights reserved.
2+
; The use and distribution terms for this software are covered by the
3+
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+
; which can be found in the file epl-v10.html at the root of this distribution.
5+
; By using this software in any fashion, you are agreeing to be bound by
6+
; the terms of this license.
7+
; You must not remove this notice, or any other, from this software.
8+
9+
(ns clojure.tools.gitlibs.config
10+
"Implementation, use at your own risk"
11+
(:require
12+
[clojure.java.io :as jio]
13+
[clojure.string :as str]))
14+
15+
(set! *warn-on-reflection* true)
16+
17+
(defn- read-config-value
18+
"Read a config value from each of these in order, taking the first value found:
19+
* Java system property
20+
* env variable
21+
* default value"
22+
[property env default]
23+
(or
24+
(System/getProperty property)
25+
(System/getenv env)
26+
default))
27+
28+
(defn- init-config
29+
[]
30+
{:gitlibs/dir
31+
(.getCanonicalPath
32+
(let [lib-dir (or (System/getProperty "clojure.gitlibs.dir") (System/getenv "GITLIBS"))]
33+
(if (str/blank? lib-dir)
34+
(jio/file (System/getProperty "user.home") ".gitlibs")
35+
(jio/file lib-dir))))
36+
37+
:gitlibs/command
38+
(or (System/getProperty "clojure.gitlibs.command") (System/getenv "GITLIBS_COMMAND") "git")
39+
40+
:gitlibs/debug
41+
(Boolean/parseBoolean (or (System/getProperty "clojure.gitlibs.debug") (System/getenv "GITLIBS_DEBUG") "false"))
42+
43+
:gitlibs/terminal
44+
(Boolean/parseBoolean (or (System/getProperty "clojure.gitlibs.terminal") (System/getenv "GITLIBS_TERMINAL") "false"))})
45+
46+
(def CONFIG
47+
"Config map - deref to access"
48+
(delay (init-config)))

0 commit comments

Comments
 (0)