Skip to content

Commit cefe25c

Browse files
committed
Complete addition of docstrings
1 parent 44ac4e6 commit cefe25c

File tree

1 file changed

+89
-8
lines changed

1 file changed

+89
-8
lines changed

src/Git.jl

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ isfile(depsjl) ? include(depsjl) : error("Git.jl not properly installed. " *
1313
"Please run\nPkg.build(\"Git\")")
1414

1515
"""
16-
Git.dir([d])
16+
Git.dir(d)
1717
1818
Return the path to the default `.git` for the given repository directory, or the
1919
path to use in place of the default `.git`.
@@ -24,6 +24,12 @@ function dir(d)
2424
normpath(d, Base.readchomp(setenv(`$gitcmd rev-parse --git-dir`, dir=d)))
2525
end
2626

27+
"""
28+
Git.git([d])
29+
30+
Return a Git command that refers to the work tree and directory given by `d`, or the
31+
current work tree and directory of `d` is not specified.
32+
"""
2733
git() = gitcmd
2834
function git(d)
2935
isempty(d) && return gitcmd
@@ -39,8 +45,29 @@ end
3945
Return a Git command from the given arguments, acting on the repository given in `dir`.
4046
"""
4147
cmd(args::Cmd; dir="") = `$(git(dir)) $args`
48+
49+
"""
50+
Git.run(args; dir="", out=STDOUT)
51+
52+
Execute the Git command from the given arguments `args` on the repository `dir`, writing
53+
the results to the output stream `out`.
54+
"""
4255
run(args::Cmd; dir="", out=STDOUT) = Base.run(pipeline(cmd(args,dir=dir), out))
56+
57+
"""
58+
Git.readstring(args; dir="")
59+
60+
Read the result of the Git command using the given arguments on the given repository
61+
as a string.
62+
"""
4363
readstring(args::Cmd; dir="") = Base.readstring(cmd(args,dir=dir))
64+
65+
"""
66+
Git.readchomp(args; dir="")
67+
68+
Read the result of the Git command using the given arguments on the given repository
69+
as a string, removing a single trailing newline if present.
70+
"""
4471
readchomp(args::Cmd; dir="") = Base.readchomp(cmd(args,dir=dir))
4572

4673
"""
@@ -71,25 +98,79 @@ function version()
7198
end
7299
end
73100

101+
"""
102+
Git.modules(args; dir="")
103+
104+
Apply the Git command with the given arguments on the given repository to the
105+
configuration file `.gitmodules` and read the result as a string.
106+
"""
74107
modules(args::Cmd; dir="") = readchomp(`config -f .gitmodules $args`, dir=dir)
108+
109+
"""
110+
Git.different(verA, verB, path; dir="")
111+
112+
Determine whether two trees are different with respect to the given path.
113+
"""
75114
different(verA::AbstractString, verB::AbstractString, path::AbstractString; dir="") =
76115
!success(`diff-tree --quiet $verA $verB -- $path`, dir=dir)
77116

117+
"""
118+
Git.dirty([paths]; dir="")
119+
120+
Determine whether the paths in the given repository are dirty, i.e. contain modified but
121+
uncommitted tracked files.
122+
"""
78123
dirty(; dir="") = !success(`diff-index --quiet HEAD`, dir=dir)
79-
staged(; dir="") = !success(`diff-index --quiet --cached HEAD`, dir=dir)
80-
unstaged(; dir="") = !success(`diff-files --quiet`, dir=dir)
81124
dirty(paths; dir="") = !success(`diff-index --quiet HEAD -- $paths`, dir=dir)
125+
126+
"""
127+
Git.staged([paths]; dir="")
128+
129+
Determine whether the paths in the given repository contain staged files.
130+
"""
131+
staged(; dir="") = !success(`diff-index --quiet --cached HEAD`, dir=dir)
82132
staged(paths; dir="") = !success(`diff-index --quiet --cached HEAD -- $paths`, dir=dir)
133+
134+
"""
135+
Git.unstaged([paths]; dir="")
136+
137+
Determine whether the paths in the given repository contain unstaged files.
138+
"""
139+
unstaged(; dir="") = !success(`diff-files --quiet`, dir=dir)
83140
unstaged(paths; dir="") = !success(`diff-files --quiet -- $paths`, dir=dir)
84141

142+
"""
143+
Git.iscommit(name; dir="")
144+
145+
Determine whether `name` refers to a commit in the repository `dir`. `name` can be a
146+
single SHA1 or a vector of SHA1s.
147+
"""
85148
iscommit(name; dir="") = success(`cat-file commit $name`, dir=dir)
149+
function iscommit(sha1s::Vector; dir="")
150+
indexin(sha1s,split(readchomp(`log --all --format=%H`, dir=dir),"\n")).!=0
151+
end
152+
153+
"""
154+
Git.attached(; dir="")
155+
156+
Determine whether HEAD is attached to a commit in the given respository.
157+
"""
86158
attached(; dir="") = success(`symbolic-ref -q HEAD`, dir=dir)
159+
160+
"""
161+
Git.branch(; dir="")
162+
163+
Return the name of the current active branch in the given repository.
164+
"""
87165
branch(; dir="") = readchomp(`rev-parse --symbolic-full-name --abbrev-ref HEAD`, dir=dir)
166+
167+
"""
168+
Git.head(; dir="")
169+
170+
Return the commit to which HEAD currently refers.
171+
"""
88172
head(; dir="") = readchomp(`rev-parse HEAD`, dir=dir)
89173

90-
function iscommit(sha1s::Vector; dir="")
91-
indexin(sha1s,split(readchomp(`log --all --format=%H`, dir=dir),"\n")).!=0
92-
end
93174

94175
immutable State
95176
head::Compat.UTF8String
@@ -100,7 +181,7 @@ end
100181
"""
101182
Git.snapshot(; dir="")
102183
103-
Return a `State` object that consisting of a snapshot of the given repository.
184+
Return a `State` object that captures a snapshot of the given repository.
104185
"""
105186
function snapshot(; dir="")
106187
head = readchomp(`rev-parse HEAD`, dir=dir)
@@ -118,7 +199,7 @@ function snapshot(; dir="")
118199
end
119200

120201
"""
121-
Git.restore(s; dir="")
202+
Git.restore(s::State; dir="")
122203
123204
Restore the given repository to the state `s`.
124205
"""

0 commit comments

Comments
 (0)