@@ -12,6 +12,12 @@ depsjl = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
12
12
isfile (depsjl) ? include (depsjl) : error (" Git.jl not properly installed. " *
13
13
" Please run\n Pkg.build(\" Git\" )" )
14
14
15
+ """
16
+ Git.dir([d])
17
+
18
+ Return the path to the default `.git` for the given repository directory, or the
19
+ path to use in place of the default `.git`.
20
+ """
15
21
function dir (d)
16
22
g = joinpath (d," .git" )
17
23
isdir (g) && return g
@@ -27,18 +33,34 @@ function git(d)
27
33
` $gitcmd --git-dir=$work_tree ` : ` $gitcmd --work-tree=$work_tree --git-dir=$git_dir `
28
34
end
29
35
36
+ """
37
+ Git.cmd(args; dir="")
38
+
39
+ Return a Git command from the given arguments, acting on the repository given in `dir`.
40
+ """
30
41
cmd (args:: Cmd ; dir= " " ) = ` $(git (dir)) $args `
31
42
run (args:: Cmd ; dir= " " , out= STDOUT) = Base. run (pipeline (cmd (args,dir= dir), out))
32
43
readstring (args:: Cmd ; dir= " " ) = Base. readstring (cmd (args,dir= dir))
33
44
readchomp (args:: Cmd ; dir= " " ) = Base. readchomp (cmd (args,dir= dir))
34
45
46
+ """
47
+ Git.success(args; dir="")
48
+
49
+ Determine whether the Git command using the given arguments on the given repository
50
+ executed successfully.
51
+ """
35
52
function success (args:: Cmd ; dir= " " )
36
53
g = git (dir)
37
54
Base. readchomp (` $g rev-parse --is-bare-repository` ) == " false" &&
38
55
Base. run (` $g update-index -q --really-refresh` )
39
56
Base. success (` $g $args ` )
40
57
end
41
58
59
+ """
60
+ Git.version()
61
+
62
+ Return the version of Git being used by the package.
63
+ """
42
64
function version ()
43
65
vs = split (readchomp (` version` ), ' ' )[3 ]
44
66
ns = split (vs, ' .' )
@@ -75,6 +97,11 @@ immutable State
75
97
work:: Compat.UTF8String
76
98
end
77
99
100
+ """
101
+ Git.snapshot(; dir="")
102
+
103
+ Return a `State` object that consisting of a snapshot of the given repository.
104
+ """
78
105
function snapshot (; dir= " " )
79
106
head = readchomp (` rev-parse HEAD` , dir= dir)
80
107
index = readchomp (` write-tree` , dir= dir)
@@ -90,6 +117,11 @@ function snapshot(; dir="")
90
117
State (head, index, work)
91
118
end
92
119
120
+ """
121
+ Git.restore(s; dir="")
122
+
123
+ Restore the given repository to the state `s`.
124
+ """
93
125
function restore (s:: State ; dir= " " )
94
126
run (` reset -q --` , dir= dir) # unstage everything
95
127
run (` read-tree $(s. work) ` , dir= dir) # move work tree to index
@@ -99,6 +131,12 @@ function restore(s::State; dir="")
99
131
run (` reset -q --soft $(s. head) ` , dir= dir) # restore head
100
132
end
101
133
134
+ """
135
+ Git.transact(f; dir="")
136
+
137
+ Attempt to execute the function `f`. If this fails, the repository is restored to its
138
+ state prior to execution.
139
+ """
102
140
function transact (f:: Function ; dir= " " )
103
141
state = snapshot (dir= dir)
104
142
try f () catch
@@ -107,6 +145,11 @@ function transact(f::Function; dir="")
107
145
end
108
146
end
109
147
148
+ """
149
+ Git.is_ancestor_of(a, b; dir="")
150
+
151
+ Determine whether the commit `a` is an ancestor of the commit `b` in the given repository.
152
+ """
110
153
function is_ancestor_of (a:: AbstractString , b:: AbstractString ; dir= " " )
111
154
A = readchomp (` rev-parse $a ` , dir= dir)
112
155
readchomp (` merge-base $A $b ` , dir= dir) == A
115
158
const GITHUB_REGEX =
116
159
r" ^(?:git@|git://|https://(?:[\w\.\+\- ]+@)?)github.com[:/](([^/].+)/(.+?))(?:\. git)?$" i
117
160
161
+ """
162
+ Git.set_remote_url(url; remote="origin", dir="")
163
+
164
+ Add a remote `remote` to the given repository from the URL `url`.
165
+ """
118
166
function set_remote_url (url:: AbstractString ; remote:: AbstractString = " origin" , dir= " " )
119
167
run (` config remote.$remote .url $url ` , dir= dir)
120
168
m = match (GITHUB_REGEX,url)
@@ -123,6 +171,11 @@ function set_remote_url(url::AbstractString; remote::AbstractString="origin", di
123
171
push != url && run (` config remote.$remote .pushurl $push ` , dir= dir)
124
172
end
125
173
174
+ """
175
+ Git.normalize_url(url)
176
+
177
+ Normalize the given URL to a valid GitHub repository URL.
178
+ """
126
179
function normalize_url (url:: AbstractString )
127
180
m = match (GITHUB_REGEX,url)
128
181
m === nothing ? url : " git://github.com/$(m. captures[1 ]) .git"
0 commit comments