Skip to content

Commit 8880ff2

Browse files
authored
Move the REPL functionality from GitCommand.jl to GitRepl.jl (#5)
1 parent d39ec41 commit 8880ff2

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,15 @@
44
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://JuliaVersionControl.github.io/GitRepl.jl/dev)
55
[![Build Status](https://github.com/JuliaVersionControl/GitRepl.jl/workflows/CI/badge.svg)](https://github.com/JuliaVersionControl/GitRepl.jl/actions)
66
[![Coverage](https://codecov.io/gh/JuliaVersionControl/GitRepl.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaVersionControl/GitRepl.jl)
7+
8+
## Git REPL mode
9+
10+
```julia
11+
julia> using GitRepl
12+
13+
julia> gitrepl() # you only need to run this once per Julia session
14+
15+
# Press , to enter the Git REPL mode
16+
17+
git> clone https://github.com/JuliaRegistries/General
18+
```

src/GitRepl.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,32 @@ module GitRepl
33
import GitCommand
44
import ReplMaker
55

6+
export gitrepl
7+
8+
const GIT_REPL_MODE_NAME = "GitRepl.jl Git REPL mode"
9+
const GIT_REPL_MODE_PROMPT_TEXT = "git> "
10+
const GIT_REPL_MODE_START_KEY = ','
11+
12+
function _gitrepl_parser(repl_input::AbstractString)
13+
return quote
14+
repl_input = $(Expr(:quote, repl_input))
15+
run(`$(GitRepl.GitCommand.git()) $(split(repl_input))`)
16+
return nothing
17+
end
18+
end
19+
20+
function gitrepl(; mode_name = GIT_REPL_MODE_NAME,
21+
prompt_text = GIT_REPL_MODE_PROMPT_TEXT,
22+
start_key = GIT_REPL_MODE_START_KEY,
23+
kwargs...)
24+
ReplMaker.initrepl(
25+
_gitrepl_parser;
26+
mode_name = mode_name,
27+
prompt_text = prompt_text,
28+
start_key = start_key,
29+
kwargs...,
30+
)
31+
return nothing
32+
end
33+
634
end # module

test/runtests.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
using GitRepl
22
using Test
33

4+
function withtempdir(f::Function)
5+
original_directory = pwd()
6+
mktempdir() do tmp_dir
7+
return f(tmp_dir)
8+
end
9+
cd(original_directory)
10+
return nothing
11+
end
12+
413
@testset "GitRepl.jl" begin
14+
withtempdir() do tmp_dir
15+
@test !isdir("GitRepl.jl")
16+
@test !isfile(joinpath("GitRepl.jl", "Project.toml"))
17+
expr = GitRepl._gitrepl_parser("clone https://github.com/JuliaVersionControl/GitRepl.jl")
18+
@test expr isa Expr
19+
@test !isdir("GitRepl.jl")
20+
@test !isfile(joinpath("GitRepl.jl", "Project.toml"))
21+
@eval $(expr)
22+
@test isdir("GitRepl.jl")
23+
@test isfile(joinpath("GitRepl.jl", "Project.toml"))
24+
end
525
end

0 commit comments

Comments
 (0)