Skip to content

Commit 44ac4e6

Browse files
committed
Add docstrings for Git commands [ci skip]
1 parent 4b7a327 commit 44ac4e6

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/Git.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ depsjl = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
1212
isfile(depsjl) ? include(depsjl) : error("Git.jl not properly installed. " *
1313
"Please run\nPkg.build(\"Git\")")
1414

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+
"""
1521
function dir(d)
1622
g = joinpath(d,".git")
1723
isdir(g) && return g
@@ -27,18 +33,34 @@ function git(d)
2733
`$gitcmd --git-dir=$work_tree` : `$gitcmd --work-tree=$work_tree --git-dir=$git_dir`
2834
end
2935

36+
"""
37+
Git.cmd(args; dir="")
38+
39+
Return a Git command from the given arguments, acting on the repository given in `dir`.
40+
"""
3041
cmd(args::Cmd; dir="") = `$(git(dir)) $args`
3142
run(args::Cmd; dir="", out=STDOUT) = Base.run(pipeline(cmd(args,dir=dir), out))
3243
readstring(args::Cmd; dir="") = Base.readstring(cmd(args,dir=dir))
3344
readchomp(args::Cmd; dir="") = Base.readchomp(cmd(args,dir=dir))
3445

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+
"""
3552
function success(args::Cmd; dir="")
3653
g = git(dir)
3754
Base.readchomp(`$g rev-parse --is-bare-repository`) == "false" &&
3855
Base.run(`$g update-index -q --really-refresh`)
3956
Base.success(`$g $args`)
4057
end
4158

59+
"""
60+
Git.version()
61+
62+
Return the version of Git being used by the package.
63+
"""
4264
function version()
4365
vs = split(readchomp(`version`), ' ')[3]
4466
ns = split(vs, '.')
@@ -75,6 +97,11 @@ immutable State
7597
work::Compat.UTF8String
7698
end
7799

100+
"""
101+
Git.snapshot(; dir="")
102+
103+
Return a `State` object that consisting of a snapshot of the given repository.
104+
"""
78105
function snapshot(; dir="")
79106
head = readchomp(`rev-parse HEAD`, dir=dir)
80107
index = readchomp(`write-tree`, dir=dir)
@@ -90,6 +117,11 @@ function snapshot(; dir="")
90117
State(head, index, work)
91118
end
92119

120+
"""
121+
Git.restore(s; dir="")
122+
123+
Restore the given repository to the state `s`.
124+
"""
93125
function restore(s::State; dir="")
94126
run(`reset -q --`, dir=dir) # unstage everything
95127
run(`read-tree $(s.work)`, dir=dir) # move work tree to index
@@ -99,6 +131,12 @@ function restore(s::State; dir="")
99131
run(`reset -q --soft $(s.head)`, dir=dir) # restore head
100132
end
101133

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+
"""
102140
function transact(f::Function; dir="")
103141
state = snapshot(dir=dir)
104142
try f() catch
@@ -107,6 +145,11 @@ function transact(f::Function; dir="")
107145
end
108146
end
109147

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+
"""
110153
function is_ancestor_of(a::AbstractString, b::AbstractString; dir="")
111154
A = readchomp(`rev-parse $a`, dir=dir)
112155
readchomp(`merge-base $A $b`, dir=dir) == A
@@ -115,6 +158,11 @@ end
115158
const GITHUB_REGEX =
116159
r"^(?:git@|git://|https://(?:[\w\.\+\-]+@)?)github.com[:/](([^/].+)/(.+?))(?:\.git)?$"i
117160

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+
"""
118166
function set_remote_url(url::AbstractString; remote::AbstractString="origin", dir="")
119167
run(`config remote.$remote.url $url`, dir=dir)
120168
m = match(GITHUB_REGEX,url)
@@ -123,6 +171,11 @@ function set_remote_url(url::AbstractString; remote::AbstractString="origin", di
123171
push != url && run(`config remote.$remote.pushurl $push`, dir=dir)
124172
end
125173

174+
"""
175+
Git.normalize_url(url)
176+
177+
Normalize the given URL to a valid GitHub repository URL.
178+
"""
126179
function normalize_url(url::AbstractString)
127180
m = match(GITHUB_REGEX,url)
128181
m === nothing ? url : "git://github.com/$(m.captures[1]).git"

0 commit comments

Comments
 (0)