Skip to content

Commit 46ce401

Browse files
Add a method of git() that bypasses cmd parsing. (#36)
1 parent b941046 commit 46ce401

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Git"
22
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
33
authors = ["Dilum Aluthge", "contributors"]
4-
version = "1.1.0"
4+
version = "1.2.0"
55

66
[deps]
77
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ julia> using Git
2222
julia> run(`$(git()) clone https://github.com/JuliaRegistries/General`)
2323
```
2424

25+
This can equivalently be written with explicitly split arguments as
26+
27+
```
28+
julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
29+
```
30+
31+
to bypass the parsing of the command string.
32+
33+
To read a single line of output from a git command you can use `readchomp`,
34+
35+
```
36+
julia> cd("General")
37+
38+
julia> readchomp(`$(git()) remote get-url origin`)
39+
"https://github.com/JuliaRegistries/General"
40+
```
41+
42+
and `readlines` for multiple lines.
43+
44+
```
45+
julia> readlines(`$(git()) log`)
46+
```
47+
2548
## Acknowledgements
2649

2750
- This work was supported in part by National Institutes of Health grants U54GM115677, R01LM011963, and R25MH116440. The content is solely the responsibility of the authors and does not necessarily represent the official views of the National Institutes of Health.

src/Git.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
The Git module allows you to use command-line Git in your Julia
3+
packages. This is implemented with the `git` function, which returns a
4+
`Cmd` object giving access to command-line Git.
5+
"""
16
module Git
27

38
import Git_jll

src/git_function.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ Return a `Cmd` for running Git.
66
## Example
77
88
```julia
9-
julia> run(`$(git()) clone https://github.com/JuliaRegistries/General`)
9+
julia> run(`\$(git()) clone https://github.com/JuliaRegistries/General`)
1010
```
11+
12+
This can equivalently be written with explicitly split arguments as
13+
14+
```
15+
julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
16+
```
17+
18+
to bypass the parsing of the command string.
1119
"""
1220
function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
1321
@static if Sys.iswindows()
@@ -33,3 +41,9 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
3341
return addenv(original_cmd, env_mapping...)::Cmd
3442
end
3543
end
44+
45+
function git(args::AbstractVector{<:AbstractString}; kwargs...)
46+
cmd = git(; kwargs...)
47+
append!(cmd.exec, args)
48+
return cmd
49+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
withtempdir() do tmp_dir
3131
@test !isdir("Git.jl")
3232
@test !isfile(joinpath("Git.jl", "Project.toml"))
33-
run(`$(git()) clone https://github.com/JuliaVersionControl/Git.jl`)
33+
run(git(["clone", "https://github.com/JuliaVersionControl/Git.jl"]))
3434
@test isdir("Git.jl")
3535
@test isfile(joinpath("Git.jl", "Project.toml"))
3636
end

0 commit comments

Comments
 (0)