• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37474

pending completion
#37474

push

local

web-flow
irinterp: Allow setting all IR flags (#48993)

Currently, `IR_FLAG_NOTHROW` is the only flag that irinterp is allowed to
set on statements, under the assumption that in order for a call to
be irinterp-eligible, it must have been proven `:foldable`, thus `:effect_free`,
and thus `IR_FLAG_EFFECT_FREE` was assumed to have been set. That reasoning
was sound at the time this code was written, but have since introduced
`EFFECT_FREE_IF_INACCESSIBLEMEMONLY`, which breaks the reasoning that
an `:effect_free` inference for the whole function implies the flag on
every statement. As a result, we were failing to DCE otherwise dead
statements if the IR came from irinterp.

3 of 3 new or added lines in 1 file covered. (100.0%)

70258 of 82316 relevant lines covered (85.35%)

32461773.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/stdlib/LibGit2/src/remote.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
"""
4
    GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractString) -> GitRemote
5

6
Look up a remote git repository using its name and URL. Uses the default fetch refspec.
7

8
# Examples
9
```julia
10
repo = LibGit2.init(repo_path)
11
remote = LibGit2.GitRemote(repo, "upstream", repo_url)
12
```
13
"""
14
function GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractString)
×
15
    ensure_initialized()
×
16
    rmt_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
17
    @check ccall((:git_remote_create, :libgit2), Cint,
×
18
                (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring, Cstring),
19
                rmt_ptr_ptr, repo.ptr, rmt_name, rmt_url)
20
    return GitRemote(repo, rmt_ptr_ptr[])
×
21
end
22

23
"""
24
    GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractString, fetch_spec::AbstractString) -> GitRemote
25

26
Look up a remote git repository using the repository's name and URL,
27
as well as specifications for how to fetch from the remote
28
(e.g. which remote branch to fetch from).
29

30
# Examples
31
```julia
32
repo = LibGit2.init(repo_path)
33
refspec = "+refs/heads/mybranch:refs/remotes/origin/mybranch"
34
remote = LibGit2.GitRemote(repo, "upstream", repo_url, refspec)
35
```
36
"""
37
function GitRemote(repo::GitRepo, rmt_name::AbstractString, rmt_url::AbstractString, fetch_spec::AbstractString)
×
38
    ensure_initialized()
×
39
    rmt_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
40
    @check ccall((:git_remote_create_with_fetchspec, :libgit2), Cint,
×
41
                (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring, Cstring, Cstring),
42
                rmt_ptr_ptr, repo.ptr, rmt_name, rmt_url, fetch_spec)
43
    return GitRemote(repo, rmt_ptr_ptr[])
×
44
end
45

46
"""
47
    GitRemoteAnon(repo::GitRepo, url::AbstractString) -> GitRemote
48

49
Look up a remote git repository using only its URL, not its name.
50

51
# Examples
52
```julia
53
repo = LibGit2.init(repo_path)
54
remote = LibGit2.GitRemoteAnon(repo, repo_url)
55
```
56
"""
57
function GitRemoteAnon(repo::GitRepo, url::AbstractString)
×
58
    ensure_initialized()
×
59
    rmt_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
60
    @check ccall((:git_remote_create_anonymous, :libgit2), Cint,
×
61
                (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring),
62
                rmt_ptr_ptr, repo.ptr, url)
63
    return GitRemote(repo, rmt_ptr_ptr[])
×
64
end
65

66
"""
67
    lookup_remote(repo::GitRepo, remote_name::AbstractString) -> Union{GitRemote, Nothing}
68

69
Determine if the `remote_name` specified exists within the `repo`. Return
70
either a [`GitRemote`](@ref) to the remote name if it exists, or [`nothing`](@ref)
71
if not.
72

73
# Examples
74
```julia
75
repo = LibGit2.GitRepo(path)
76
remote_name = "test"
77
LibGit2.lookup_remote(repo, remote_name) # will return nothing
78
```
79
"""
80
function lookup_remote(repo::GitRepo, remote_name::AbstractString)
×
81
    ensure_initialized()
×
82
    rmt_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
83
    err = ccall((:git_remote_lookup, :libgit2), Cint,
×
84
                (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring),
85
                rmt_ptr_ptr, repo.ptr, remote_name)
86
    if err == Int(Error.GIT_OK)
×
87
        return GitRemote(repo, rmt_ptr_ptr[])
×
88
    elseif err == Int(Error.ENOTFOUND)
×
89
        return nothing
×
90
    else
91
        throw(Error.GitError(err))
×
92
    end
93
end
94

95
function get(::Type{GitRemote}, repo::GitRepo, rmt_name::AbstractString)
×
96
    ensure_initialized()
×
97
    rmt_ptr_ptr = Ref{Ptr{Cvoid}}(C_NULL)
×
98
    @check ccall((:git_remote_lookup, :libgit2), Cint,
×
99
                (Ptr{Ptr{Cvoid}}, Ptr{Cvoid}, Cstring),
100
                rmt_ptr_ptr, repo.ptr, rmt_name)
101
    return GitRemote(repo, rmt_ptr_ptr[])
×
102
end
103

104
"""
105
    url(rmt::GitRemote)
106

107
Get the fetch URL of a remote git repository.
108

109
# Examples
110
```julia-repl
111
julia> repo_url = "https://github.com/JuliaLang/Example.jl";
112

113
julia> repo = LibGit2.init(mktempdir());
114

115
julia> remote = LibGit2.GitRemote(repo, "origin", repo_url);
116

117
julia> LibGit2.url(remote)
118
"https://github.com/JuliaLang/Example.jl"
119
```
120
"""
121
function url(rmt::GitRemote)
×
122
    ensure_initialized()
×
123
    url_ptr = ccall((:git_remote_url, :libgit2), Cstring, (Ptr{Cvoid},), rmt.ptr)
×
124
    url_ptr == C_NULL && return ""
×
125
    return unsafe_string(url_ptr)
×
126
end
127

128
"""
129
    push_url(rmt::GitRemote)
130

131
Get the push URL of a remote git repository.
132

133
# Examples
134
```julia-repl
135
julia> repo_url = "https://github.com/JuliaLang/Example.jl";
136

137
julia> repo = LibGit2.init(mktempdir());
138

139
julia> LibGit2.set_remote_push_url(repo, "origin", repo_url);
140

141
julia> LibGit2.push_url(LibGit2.get(LibGit2.GitRemote, repo, "origin"))
142
"https://github.com/JuliaLang/Example.jl"
143
```
144
"""
145
function push_url(rmt::GitRemote)
×
146
    ensure_initialized()
×
147
    url_ptr = ccall((:git_remote_pushurl, :libgit2), Cstring, (Ptr{Cvoid},), rmt.ptr)
×
148
    url_ptr == C_NULL && return ""
×
149
    return unsafe_string(url_ptr)
×
150
end
151

152
"""
153
    name(rmt::GitRemote)
154

155
Get the name of a remote repository, for instance `"origin"`.
156
If the remote is anonymous (see [`GitRemoteAnon`](@ref))
157
the name will be an empty string `""`.
158

159
# Examples
160
```julia-repl
161
julia> repo_url = "https://github.com/JuliaLang/Example.jl";
162

163
julia> repo = LibGit2.clone(cache_repo, "test_directory");
164

165
julia> remote = LibGit2.GitRemote(repo, "origin", repo_url);
166

167
julia> name(remote)
168
"origin"
169
```
170
"""
171
function name(rmt::GitRemote)
×
172
    ensure_initialized()
×
173
    name_ptr = ccall((:git_remote_name, :libgit2), Cstring, (Ptr{Cvoid},), rmt.ptr)
×
174
    name_ptr == C_NULL && return ""
×
175
    return unsafe_string(name_ptr)
×
176
end
177

178
"""
179
    fetch_refspecs(rmt::GitRemote) -> Vector{String}
180

181
Get the *fetch* refspecs for the specified `rmt`. These refspecs contain
182
information about which branch(es) to fetch from.
183

184
# Examples
185
```julia-repl
186
julia> remote = LibGit2.get(LibGit2.GitRemote, repo, "upstream");
187

188
julia> LibGit2.add_fetch!(repo, remote, "upstream");
189

190
julia> LibGit2.fetch_refspecs(remote)
191
String["+refs/heads/*:refs/remotes/upstream/*"]
192
```
193
"""
194
function fetch_refspecs(rmt::GitRemote)
×
195
    ensure_initialized()
×
196
    sa_ref = Ref(StrArrayStruct())
×
197
    @check ccall((:git_remote_get_fetch_refspecs, :libgit2), Cint,
×
198
                 (Ptr{StrArrayStruct}, Ptr{Cvoid}), sa_ref, rmt.ptr)
199
    res = convert(Vector{String}, sa_ref[])
×
200
    free(sa_ref)
×
201
    res
×
202
end
203

204
"""
205
    push_refspecs(rmt::GitRemote) -> Vector{String}
206

207
Get the *push* refspecs for the specified `rmt`. These refspecs contain
208
information about which branch(es) to push to.
209

210
# Examples
211
```julia-repl
212
julia> remote = LibGit2.get(LibGit2.GitRemote, repo, "upstream");
213

214
julia> LibGit2.add_push!(repo, remote, "refs/heads/master");
215

216
julia> close(remote);
217

218
julia> remote = LibGit2.get(LibGit2.GitRemote, repo, "upstream");
219

220
julia> LibGit2.push_refspecs(remote)
221
String["refs/heads/master"]
222
```
223
"""
224
function push_refspecs(rmt::GitRemote)
×
225
    ensure_initialized()
×
226
    sa_ref = Ref(StrArrayStruct())
×
227
    @check ccall((:git_remote_get_push_refspecs, :libgit2), Cint,
×
228
                 (Ptr{StrArrayStruct}, Ptr{Cvoid}), sa_ref, rmt.ptr)
229
    res = convert(Vector{String}, sa_ref[])
×
230
    free(sa_ref)
×
231
    res
×
232
end
233

234
"""
235
    add_fetch!(repo::GitRepo, rmt::GitRemote, fetch_spec::String)
236

237
Add a *fetch* refspec for the specified `rmt`. This refspec will contain
238
information about which branch(es) to fetch from.
239

240
# Examples
241
```julia-repl
242
julia> LibGit2.add_fetch!(repo, remote, "upstream");
243

244
julia> LibGit2.fetch_refspecs(remote)
245
String["+refs/heads/*:refs/remotes/upstream/*"]
246
```
247
"""
248
function add_fetch!(repo::GitRepo, rmt::GitRemote, fetch_spec::String)
×
249
    ensure_initialized()
×
250
    @check ccall((:git_remote_add_fetch, :libgit2), Cint,
×
251
                 (Ptr{Cvoid}, Cstring, Cstring), repo.ptr,
252
                 name(rmt), fetch_spec)
253
end
254

255
"""
256
    add_push!(repo::GitRepo, rmt::GitRemote, push_spec::String)
257

258
Add a *push* refspec for the specified `rmt`. This refspec will contain
259
information about which branch(es) to push to.
260

261
# Examples
262
```julia-repl
263
julia> LibGit2.add_push!(repo, remote, "refs/heads/master");
264

265
julia> remote = LibGit2.get(LibGit2.GitRemote, repo, branch);
266

267
julia> LibGit2.push_refspecs(remote)
268
String["refs/heads/master"]
269
```
270

271
!!! note
272
    You may need to [`close`](@ref) and reopen the `GitRemote`
273
    in question after updating its push refspecs in order for
274
    the change to take effect and for calls to [`push`](@ref)
275
    to work.
276
"""
277
function add_push!(repo::GitRepo, rmt::GitRemote, push_spec::String)
×
278
    ensure_initialized()
×
279
    @check ccall((:git_remote_add_push, :libgit2), Cint,
×
280
                 (Ptr{Cvoid}, Cstring, Cstring), repo.ptr,
281
                 name(rmt), push_spec)
282
end
283

284
"""
285
    fetch(rmt::GitRemote, refspecs; options::FetchOptions=FetchOptions(), msg="")
286

287
Fetch from the specified `rmt` remote git repository, using `refspecs` to
288
determine which remote branch(es) to fetch.
289
The keyword arguments are:
290
  * `options`: determines the options for the fetch, e.g. whether to prune afterwards.
291
    See [`FetchOptions`](@ref) for more information.
292
  * `msg`: a message to insert into the reflogs.
293
"""
294
function fetch(rmt::GitRemote, refspecs::Vector{<:AbstractString};
×
295
               options::FetchOptions = FetchOptions(),
296
               msg::AbstractString="")
297
    ensure_initialized()
×
298
    msg = "libgit2.fetch: $msg"
×
299
    @check ccall((:git_remote_fetch, :libgit2), Cint,
×
300
                 (Ptr{Cvoid}, Ptr{StrArrayStruct}, Ptr{FetchOptions}, Cstring),
301
                 rmt.ptr, isempty(refspecs) ? C_NULL : refspecs, Ref(options), msg)
302
end
303

304
"""
305
    push(rmt::GitRemote, refspecs; force::Bool=false, options::PushOptions=PushOptions())
306

307
Push to the specified `rmt` remote git repository, using `refspecs` to
308
determine which remote branch(es) to push to.
309
The keyword arguments are:
310
  * `force`: if `true`, a force-push will occur, disregarding conflicts.
311
  * `options`: determines the options for the push, e.g. which proxy headers to use.
312
    See [`PushOptions`](@ref) for more information.
313

314
!!! note
315
    You can add information about the push refspecs in two other ways: by setting
316
    an option in the repository's `GitConfig` (with `push.default` as the key) or
317
    by calling [`add_push!`](@ref). Otherwise you will need to explicitly specify
318
    a push refspec in the call to `push` for it to have any effect, like so:
319
    `LibGit2.push(repo, refspecs=["refs/heads/master"])`.
320
"""
321
function push(rmt::GitRemote, refspecs::Vector{<:AbstractString};
×
322
              force::Bool = false, options::PushOptions = PushOptions())
323
    ensure_initialized()
×
324
    @check ccall((:git_remote_push, :libgit2), Cint,
×
325
                 (Ptr{Cvoid}, Ptr{StrArrayStruct}, Ptr{PushOptions}),
326
                 rmt.ptr, isempty(refspecs) ? C_NULL : refspecs, Ref(options))
327
end
328

329
"""
330
    remote_delete(repo::GitRepo, remote_name::AbstractString) -> Nothing
331

332
Delete the `remote_name` from the git `repo`.
333
"""
334
function remote_delete(repo::GitRepo, remote_name::AbstractString)
×
335
    ensure_initialized()
×
336
    @check ccall((:git_remote_delete, :libgit2), Cint,
×
337
                 (Ptr{Cvoid}, Cstring),
338
                 repo.ptr, remote_name)
339
end
340

341
Base.show(io::IO, rmt::GitRemote) = print(io, "GitRemote:\nRemote name: ", name(rmt), " url: ", url(rmt))
×
342

343

344
"""
345
    set_remote_fetch_url(repo::GitRepo, remote_name, url)
346
    set_remote_fetch_url(path::String, remote_name, url)
347

348
Set the fetch `url` for the specified `remote_name` for the [`GitRepo`](@ref) or the git repository
349
located at `path`. Typically git repos use `"origin"` as the remote name.
350
"""
351
function set_remote_fetch_url end
352

353
function set_remote_fetch_url(repo::GitRepo, remote_name::AbstractString, url::AbstractString)
×
354
    ensure_initialized()
×
355
    @check ccall((:git_remote_set_url, :libgit2), Cint,
×
356
                 (Ptr{Cvoid}, Cstring, Cstring),
357
                 repo.ptr, remote_name, url)
358
end
359

360
function set_remote_fetch_url(path::AbstractString, remote_name::AbstractString, url::AbstractString)
×
361
    with(GitRepo, path) do repo
×
362
        set_remote_fetch_url(repo, remote_name, url)
×
363
    end
364
end
365

366

367
"""
368
    set_remote_push_url(repo::GitRepo, remote_name, url)
369
    set_remote_push_url(path::String, remote_name, url)
370

371
Set the push `url` for the specified `remote_name` for the [`GitRepo`](@ref) or the git repository
372
located at `path`. Typically git repos use `"origin"` as the remote name.
373
"""
374
function set_remote_push_url end
375

376
function set_remote_push_url(repo::GitRepo, remote_name::AbstractString, url::AbstractString)
×
377
    ensure_initialized()
×
378
    @check ccall((:git_remote_set_pushurl, :libgit2), Cint,
×
379
                 (Ptr{Cvoid}, Cstring, Cstring),
380
                 repo.ptr, remote_name, url)
381
end
382

383
function set_remote_push_url(path::AbstractString, remote_name::AbstractString, url::AbstractString)
×
384
    with(GitRepo, path) do repo
×
385
        set_remote_push_url(repo, remote_name, url)
×
386
    end
387
end
388

389

390
"""
391
    set_remote_url(repo::GitRepo, remote_name, url)
392
    set_remote_url(repo::String, remote_name, url)
393

394
Set both the fetch and push `url` for `remote_name` for the [`GitRepo`](@ref) or the git repository
395
located at `path`. Typically git repos use `"origin"` as the remote name.
396

397
# Examples
398
```julia
399
repo_path = joinpath(tempdir(), "Example")
400
repo = LibGit2.init(repo_path)
401
LibGit2.set_remote_url(repo, "upstream", "https://github.com/JuliaLang/Example.jl")
402
LibGit2.set_remote_url(repo_path, "upstream2", "https://github.com/JuliaLang/Example2.jl")
403
```
404
"""
405
function set_remote_url end
406

407
function set_remote_url(repo::GitRepo, remote_name::AbstractString, url::AbstractString)
×
408
    set_remote_fetch_url(repo, remote_name, url)
×
409
    set_remote_push_url(repo, remote_name, url)
×
410
end
411

412
function set_remote_url(path::AbstractString, remote_name::AbstractString, url::AbstractString)
×
413
    with(GitRepo, path) do repo
×
414
        set_remote_url(repo, remote_name, url)
×
415
    end
416
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc