Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit 043eb5e

Browse files
DilumAluthgegiordanoericphanson
authored
Remove all uses of functions that use withenv (#46)
Co-authored-by: Mosè Giordano <[email protected]> Co-authored-by: Eric Hanson <[email protected]> Co-authored-by: Mosè Giordano <[email protected]> Co-authored-by: Eric Hanson <[email protected]>
1 parent 47c5097 commit 043eb5e

File tree

7 files changed

+46
-88
lines changed

7 files changed

+46
-88
lines changed

Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
name = "GitCommand"
22
uuid = "49b5b516-ca3f-4003-a081-42bdcf55082d"
33
authors = ["Dilum Aluthge", "Brown Center for Biomedical Informatics"]
4-
version = "2.2.0"
4+
version = "2.2.1"
55

66
[deps]
7-
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
87
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"
98
ReplMaker = "b873ce64-0db9-51f5-a568-4457d8e49576"
109

1110
[compat]
12-
JLLWrappers = "1.1"
1311
Git_jll = "2.31"
12+
JLLWrappers = "1.1"
1413
ReplMaker = "0.2.3"
1514
julia = "1.6"
1615

1716
[extras]
17+
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
1818
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1919

2020
[targets]
21-
test = ["Test"]
21+
test = ["JLLWrappers", "Test"]

src/GitCommand.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module GitCommand
22

3-
import JLLWrappers
43
import Git_jll
54
import ReplMaker
65

@@ -12,9 +11,7 @@ const GIT_REPL_MODE_NAME = "GitCommand.jl Git REPL mode"
1211
const GIT_REPL_MODE_PROMPT_TEXT = "git> "
1312
const GIT_REPL_MODE_START_KEY = ','
1413

15-
include("env.jl")
1614
include("git.jl")
1715
include("repl.jl")
18-
include("utils.jl")
1916

2017
end # end module GitCommand

src/env.jl

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/git.jl

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,41 @@
11
function _git_cmd(str::AbstractString;
22
adjust_PATH::Bool = true,
33
adjust_LIBPATH::Bool = true)
4-
git_path, env_mapping = _env_mapping(; adjust_PATH, adjust_LIBPATH)
5-
return addenv(`$(git_path) $(split(str))`, env_mapping)
4+
cmd = git(; adjust_PATH, adjust_LIBPATH)
5+
return `$(cmd) $(split(str))`
66
end
77

88
macro git_cmd(ex)
99
return _git_cmd(ex)
1010
end
1111

12-
function _gitrepl_parser(repl_input::AbstractString)
13-
return quote
14-
GitCommand.git() do git
15-
repl_input = $(Expr(:quote, repl_input))
16-
run(`$(git) $(split(repl_input))`)
17-
return nothing
18-
end
19-
end
20-
end
12+
function git(; adjust_PATH::Bool = true, adjust_LIBPATH::Bool = true)
13+
@static if Sys.iswindows()
14+
return Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
15+
else
16+
root = Git_jll.artifact_dir
2117

22-
function git(;
23-
adjust_PATH::Bool = true,
24-
adjust_LIBPATH::Bool = true)
25-
git_path, env_mapping = _env_mapping(; adjust_PATH, adjust_LIBPATH)
26-
return addenv(`$(git_path)`, env_mapping...)
18+
libexec = joinpath(root, "libexec")
19+
libexec_git_core = joinpath(libexec, "git-core")
20+
21+
share = joinpath(root, "share")
22+
share_git_core = joinpath(share, "git-core")
23+
share_git_core_templates = joinpath(share_git_core, "templates")
24+
25+
ssl_cert = joinpath(dirname(Sys.BINDIR), "share", "julia", "cert.pem")
26+
27+
env_mapping = Dict{String,String}()
28+
env_mapping["GIT_EXEC_PATH"] = libexec_git_core
29+
env_mapping["GIT_SSL_CAINFO"] = ssl_cert
30+
env_mapping["GIT_TEMPLATE_DIR"] = share_git_core_templates
31+
32+
original_cmd = Git_jll.git(; adjust_PATH, adjust_LIBPATH)::Cmd
33+
return addenv(original_cmd, env_mapping...)::Cmd
34+
end
2735
end
2836

2937
# This function should be deprecated, it's kept only for backward-compatibility
38+
# We will remove it soon in a breaking release
3039
function git(f::Function;
3140
adjust_PATH::Bool = true,
3241
adjust_LIBPATH::Bool = true)

src/repl.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import ReplMaker
22

3+
function _gitrepl_parser(repl_input::AbstractString)
4+
return quote
5+
GitCommand.git() do git
6+
repl_input = $(Expr(:quote, repl_input))
7+
run(`$(git) $(split(repl_input))`)
8+
return nothing
9+
end
10+
end
11+
end
12+
313
function gitrepl(; mode_name = GIT_REPL_MODE_NAME,
414
prompt_text = GIT_REPL_MODE_PROMPT_TEXT,
515
start_key = GIT_REPL_MODE_START_KEY,

src/utils.jl

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/runtests.jl

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
using GitCommand
22
using Test
3-
using JLLWrappers
43

5-
get_env(env) = get(ENV, env, nothing)
6-
const orig_libpath = get_env(JLLWrappers.LIBPATH_env)
7-
const orig_execpath = get_env("GIT_EXEC_PATH")
8-
const orig_cainfo = get_env("GIT_SSL_CAINFO")
9-
const orig_templatedir = get_env("GIT_TEMPLATE_DIR")
4+
import JLLWrappers
5+
6+
get_env(name) = get(ENV, name, nothing)
7+
const orig_libpath = deepcopy(get_env(JLLWrappers.LIBPATH_env))
8+
const orig_execpath = deepcopy(get_env("GIT_EXEC_PATH"))
9+
const orig_cainfo = deepcopy(get_env("GIT_SSL_CAINFO"))
10+
const orig_templatedir = deepcopy(get_env("GIT_TEMPLATE_DIR"))
1011

1112
include("test-utils.jl")
1213

1314
@testset "GitCommand.jl" begin
14-
if Sys.iswindows()
15-
@test GitCommand._separator() == ';'
16-
else
17-
@test GitCommand._separator() == ':'
18-
end
19-
2015
with_temp_dir() do tmp_dir
2116
@test !isdir("GitCommand.jl")
2217
@test !isfile(joinpath("GitCommand.jl", "Project.toml"))

0 commit comments

Comments
 (0)