Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method of git() that bypasses cmd parsing. #36

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Git"
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
authors = ["Dilum Aluthge", "contributors"]
version = "1.1.0"
version = "1.2.0"

[deps]
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@ julia> using Git
julia> run(`$(git()) clone https://github.com/JuliaRegistries/General`)
```

This can equivalently be written with explicitly split arguments as

```
julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
```

to bypass the parsing of the command string.

To read a single line of output from a git command you can use `readchomp`,

```
julia> cd("General")

julia> readchomp(`$(git()) remote get-url origin`)
"https://github.com/JuliaRegistries/General"
```

and `readlines` for multiple lines.

```
julia> readlines(`$(git()) log`)
```

## Acknowledgements

- 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.
5 changes: 5 additions & 0 deletions src/Git.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
The Git module allows you to use command-line Git in your Julia
packages. This is implemented with the `git` function, which returns a
`Cmd` object giving access to command-line Git.
"""
module Git

import Git_jll
Expand Down
16 changes: 15 additions & 1 deletion src/git_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ Return a `Cmd` for running Git.
## Example

```julia
julia> run(`$(git()) clone https://github.com/JuliaRegistries/General`)
julia> run(`\$(git()) clone https://github.com/JuliaRegistries/General`)
```

This can equivalently be written with explicitly split arguments as

```
julia> run(git(["clone", "https://github.com/JuliaRegistries/General"]))
```

to bypass the parsing of the command string.
"""
function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
@static if Sys.iswindows()
Expand All @@ -33,3 +41,9 @@ function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
return addenv(original_cmd, env_mapping...)::Cmd
end
end

function git(args::AbstractVector{<:AbstractString}; kwargs...)
cmd = git(; kwargs...)
append!(cmd.exec, args)
return cmd
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ end
withtempdir() do tmp_dir
@test !isdir("Git.jl")
@test !isfile(joinpath("Git.jl", "Project.toml"))
run(`$(git()) clone https://github.com/JuliaVersionControl/Git.jl`)
run(git(["clone", "https://github.com/JuliaVersionControl/Git.jl"]))
@test isdir("Git.jl")
@test isfile(joinpath("Git.jl", "Project.toml"))
end
Expand Down