@@ -13,7 +13,7 @@ isfile(depsjl) ? include(depsjl) : error("Git.jl not properly installed. " *
13
13
" Please run\n Pkg.build(\" Git\" )" )
14
14
15
15
"""
16
- Git.dir([d] )
16
+ Git.dir(d )
17
17
18
18
Return the path to the default `.git` for the given repository directory, or the
19
19
path to use in place of the default `.git`.
@@ -24,6 +24,12 @@ function dir(d)
24
24
normpath (d, Base. readchomp (setenv (` $gitcmd rev-parse --git-dir` , dir= d)))
25
25
end
26
26
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
+ """
27
33
git () = gitcmd
28
34
function git (d)
29
35
isempty (d) && return gitcmd
39
45
Return a Git command from the given arguments, acting on the repository given in `dir`.
40
46
"""
41
47
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
+ """
42
55
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
+ """
43
63
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
+ """
44
71
readchomp (args:: Cmd ; dir= " " ) = Base. readchomp (cmd (args,dir= dir))
45
72
46
73
"""
@@ -71,25 +98,79 @@ function version()
71
98
end
72
99
end
73
100
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
+ """
74
107
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
+ """
75
114
different (verA:: AbstractString , verB:: AbstractString , path:: AbstractString ; dir= " " ) =
76
115
! success (` diff-tree --quiet $verA $verB -- $path ` , dir= dir)
77
116
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
+ """
78
123
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)
81
124
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)
82
132
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)
83
140
unstaged (paths; dir= " " ) = ! success (` diff-files --quiet -- $paths ` , dir= dir)
84
141
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
+ """
85
148
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
+ """
86
158
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
+ """
87
165
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
+ """
88
172
head (; dir= " " ) = readchomp (` rev-parse HEAD` , dir= dir)
89
173
90
- function iscommit (sha1s:: Vector ; dir= " " )
91
- indexin (sha1s,split (readchomp (` log --all --format=%H` , dir= dir)," \n " )).!= 0
92
- end
93
174
94
175
immutable State
95
176
head:: Compat.UTF8String
100
181
"""
101
182
Git.snapshot(; dir="")
102
183
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.
104
185
"""
105
186
function snapshot (; dir= " " )
106
187
head = readchomp (` rev-parse HEAD` , dir= dir)
@@ -118,7 +199,7 @@ function snapshot(; dir="")
118
199
end
119
200
120
201
"""
121
- Git.restore(s; dir="")
202
+ Git.restore(s::State ; dir="")
122
203
123
204
Restore the given repository to the state `s`.
124
205
"""
0 commit comments