Skip to content

Commit 9bb08e3

Browse files
ararslancarstenbauer
authored andcommitted
Add 0.7 and 1.0 support (#20)
1 parent 1473a64 commit 9bb08e3

File tree

5 files changed

+84
-64
lines changed

5 files changed

+84
-64
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
julia 0.6
2-
Compat 0.8.4
2+
Compat 0.47.0
33
BinDeps
44
@osx Homebrew

deps/build.jl

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
using Compat
2-
import BinDeps: download_cmd, unpack_cmd, splittarpath
3-
if is_apple()
2+
using Compat: @info
3+
using Compat.Sys: isapple, islinux, iswindows
4+
5+
using BinDeps
6+
using BinDeps: download_cmd, unpack_cmd, splittarpath
7+
8+
if isapple()
49
using Homebrew
510
end
611

712
function download_and_unpack(baseurl, filename)
813
downloadurl = baseurl * filename
9-
info("Downloading $filename from $downloadurl\nTo avoid this " *
10-
"download, install git manually and add it to your path " *
11-
"before\nrunning Pkg.add(\"Git\") or Pkg.build(\"Git\")")
14+
@info "Downloading $filename from $downloadurl\nTo avoid this " *
15+
"download, install git manually and add it to your path " *
16+
"before\nrunning Pkg.add(\"Git\") or Pkg.build(\"Git\")"
1217
dest = joinpath("usr", string(Sys.MACHINE))
1318
for dir in ("downloads", "usr", dest)
1419
isdir(dir) || mkdir(dir)
@@ -17,23 +22,24 @@ function download_and_unpack(baseurl, filename)
1722
isfile(filename) || run(download_cmd(downloadurl, filename))
1823
# TODO: checksum validation
1924
(b, ext, sec_ext) = splittarpath(filename)
20-
run(unpack_cmd(filename, dest, is_windows() ? ".7z" : ext, sec_ext))
25+
run(unpack_cmd(filename, dest, iswindows() ? ".7z" : ext, sec_ext))
2126
# TODO: make this less noisy on windows, see how WinRPM does it
2227
end
2328

2429
gitcmd = `git`
2530
gitver = "notfound"
2631
try
27-
gitver = readchomp(`$gitcmd --version`)
32+
global gitver = readchomp(`$gitcmd --version`)
33+
catch
2834
end
2935
if gitver == "notfound"
30-
if is_apple()
36+
if isapple()
3137
# we could allow other options, but lots of other packages already
3238
# depend on Homebrew.jl on mac and it needs a working git to function
3339
error("Working git not found on path, try running\nPkg.build(\"Homebrew\")")
3440
end
3541
baseurl = ""
36-
if is_linux() && (Sys.ARCH in (:x86_64, :i686, :i586, :i486, :i386))
42+
if islinux() && (Sys.ARCH in (:x86_64, :i686, :i586, :i486, :i386))
3743
# use conda for a non-root option on x86/amd64 linux
3844
# TODO? use conda-forge when we no longer build julia on centos 5
3945
gitver = "2.6.4"
@@ -47,7 +53,7 @@ if gitver == "notfound"
4753
zlibver = "1.2.8"
4854
zlibbase = "http://anaconda.org/anaconda/zlib/$zlibver/$plat"
4955
download_and_unpack(zlibbase, "zlib-$zlibver-3.tar.bz2")
50-
elseif is_windows()
56+
elseif iswindows()
5157
# download and extract portablegit
5258
gitver = "2.9.0"
5359
baseurl = "https://github.com/git-for-windows/git/releases/download/"
@@ -59,24 +65,27 @@ if gitver == "notfound"
5965
gitcmd = `$gitpath`
6066
end
6167
try
62-
gitver = readchomp(`$gitcmd --version`)
63-
info("Successfully installed $gitver to $gitcmd")
68+
global gitver = readchomp(`$gitcmd --version`)
69+
@info "Successfully installed $gitver to $gitcmd"
6470
# TODO: fix a warning about missing /templates here on linux
6571
# by setting an environment variable in deps.jl
6672
catch err
67-
error("Could not automatically install git, error was: $err\n" *
68-
(is_windows() ? "Report an issue at https://github.com/JuliaPackaging/Git.jl/issues/new" :
69-
"Try installing git via your system package manager then running\nPkg.build(\"Git\")"))
73+
s = if iswindows()
74+
"Report an issue at https://github.com/JuliaPackaging/Git.jl/issues/new"
75+
else
76+
"Try installing git via your system package manager then running\nPkg.build(\"Git\")"
77+
end
78+
error("Could not automatically install git, error was: $err\n" * s)
7079
end
7180
else
7281
try
7382
# this is in a try because some environments like centos 7
7483
# docker containers don't have `which` installed by default
75-
gitpath = chomp(readlines(is_windows() ? `where git` : `which git`)[1])
76-
gitcmd = `$gitpath`
84+
global gitpath = chomp(readlines(iswindows() ? `where git` : `which git`)[1])
85+
global gitcmd = `$gitpath`
86+
catch
7787
end
78-
info("Using $gitver found on path" * (gitcmd == `git` ?
79-
"" : " at $gitcmd"))
88+
@info "Using $gitver found on path" * (gitcmd == `git` ? "" : " at $gitcmd")
8089
end
8190
open("deps.jl", "w") do f
8291
println(f, "gitcmd = $gitcmd")

src/Git.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Git
55
# some utility functions for working with git repos
66
#
77
using Compat
8-
import Base: shell_escape
8+
using Base: shell_escape
99
export gitcmd # determined by deps/build.jl and saved in deps/deps.jl
1010

1111
depsjl = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
@@ -47,20 +47,20 @@ Return a Git command from the given arguments, acting on the repository given in
4747
cmd(args::Cmd; dir="") = `$(git(dir)) $args`
4848

4949
"""
50-
Git.run(args; dir="", out=STDOUT)
50+
Git.run(args; dir="", out=stdout)
5151
5252
Execute the Git command from the given arguments `args` on the repository `dir`, writing
5353
the results to the output stream `out`.
5454
"""
55-
run(args::Cmd; dir="", out=STDOUT) = Base.run(pipeline(cmd(args,dir=dir), out))
55+
run(args::Cmd; dir="", out=stdout) = Base.run(pipeline(cmd(args,dir=dir), out))
5656

5757
"""
5858
Git.readstring(args; dir="")
5959
6060
Read the result of the Git command using the given arguments on the given repository
6161
as a string.
6262
"""
63-
readstring(args::Cmd; dir="") = Base.readstring(cmd(args,dir=dir))
63+
readstring(args::Cmd; dir="") = read(cmd(args,dir=dir), String)
6464

6565
"""
6666
Git.readchomp(args; dir="")
@@ -147,7 +147,7 @@ single SHA1 or a vector of SHA1s.
147147
"""
148148
iscommit(name; dir="") = success(`cat-file commit $name`, dir=dir)
149149
function iscommit(sha1s::Vector; dir="")
150-
indexin(sha1s,split(readchomp(`log --all --format=%H`, dir=dir),"\n")).!=0
150+
indexin(sha1s,split(readchomp(`log --all --format=%H`, dir=dir),"\n")).!=nothing
151151
end
152152

153153
"""
@@ -172,7 +172,7 @@ Return the commit to which HEAD currently refers.
172172
head(; dir="") = readchomp(`rev-parse HEAD`, dir=dir)
173173

174174

175-
immutable State
175+
struct State
176176
head::String
177177
index::String
178178
work::String

test/gitutils.jl

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# This file was a part of Julia. License is MIT: http://julialang.org/license
22

3-
import Compat: readstring
3+
using Compat
44

5-
function write_and_readchomp(data, cmd::Cmd)
6-
r, w, p = readandwrite(cmd)
7-
print(w,data); close(w)
8-
v = readchomp(r)
9-
wait(p)
10-
return v
5+
if VERSION >= v"0.7.0-DEV.3427"
6+
function write_and_readchomp(data, cmd::Cmd)
7+
p = open(cmd, "r+")
8+
print(p.in, data)
9+
close(p.in)
10+
v = readchomp(p.out)
11+
wait(p)
12+
return v
13+
end
14+
else
15+
function write_and_readchomp(data, cmd::Cmd)
16+
r, w, p = readandwrite(cmd)
17+
print(w,data); close(w)
18+
v = readchomp(r)
19+
wait(p)
20+
return v
21+
end
1122
end
1223

1324
function mktree(d::Dict)
@@ -39,7 +50,7 @@ function verify_tree(d::Dict, tree::AbstractString)
3950
data = d[name]
4051
if isa(data, AbstractString)
4152
@test kind == "blob"
42-
@test data == readstring(`$gitcmd cat-file blob $sha1`)
53+
@test data == read(`$gitcmd cat-file blob $sha1`, String)
4354
elseif isa(data, Dict)
4455
@test kind == "tree"
4556
verify_tree(data, sha1)
@@ -64,7 +75,7 @@ function verify_work(d::Dict)
6475
@test ispath(name)
6576
if isa(data, AbstractString)
6677
@test isfile(name)
67-
@test readstring(name) == data
78+
@test read(name, String) == data
6879
elseif isa(data, Dict)
6980
cd(name) do
7081
verify_work(data)

test/runtests.jl

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
# This file was a part of Julia. License is MIT: http://julialang.org/license
22

33
using Git
4-
using Base.Test
4+
using Compat
5+
using Compat.Test
56

67
include("gitutils.jl")
78

89
@test Git.version() >= v"1.7.3"
910

10-
dir = string("tmp.",randstring())
11-
@test !ispath(dir)
12-
mkdir(dir)
13-
@test isdir(dir)
14-
try cd(dir) do
15-
run(`$gitcmd init -q`)
16-
run(`$gitcmd config user.name "Julia Tester"`)
17-
run(`$gitcmd config user.email [email protected]`)
18-
run(`$gitcmd commit -q --allow-empty -m "initial empty commit"`)
19-
git_verify(Dict(), Dict(), Dict())
11+
mktempdir() do dir
12+
cd(dir) do
13+
run(`$gitcmd init -q`)
14+
run(`$gitcmd config user.name "Julia Tester"`)
15+
run(`$gitcmd config user.email [email protected]`)
16+
run(`$gitcmd commit -q --allow-empty -m "initial empty commit"`)
17+
git_verify(Dict(), Dict(), Dict())
2018

21-
# each path can have one of these content in each of head, index, work
22-
# for a total of length(contents)^3 = 4^3 = 64 combinations.
23-
# each path can be in any of these 64 "superpositions" before & after
24-
# for a total of 64^2 = 4096 files needed to test all transitions
25-
# between before and after superpositions of git repo states.
19+
# each path can have one of these content in each of head, index, work
20+
# for a total of length(contents)^3 = 4^3 = 64 combinations.
21+
# each path can be in any of these 64 "superpositions" before & after
22+
# for a total of 64^2 = 4096 files needed to test all transitions
23+
# between before and after superpositions of git repo states.
2624

27-
contents = [nothing, "foo", "bar", Dict{Any,Any}("baz"=>"qux")]
28-
b = length(contents)
29-
states = [Dict([(base(b,k,6), contents[rem(div(k,b^p),b)+1]) for k=0:(b^3)^2-1]) for p=0:5]
25+
contents = [nothing, "foo", "bar", Dict{Any,Any}("baz"=>"qux")]
26+
b = length(contents)
27+
@static if VERSION >= v"0.7.0"
28+
states = [Dict([(string(k, base=b, pad=6), contents[rem(div(k,b^p),b)+1]) for k=0:(b^3)^2-1]) for p=0:5]
29+
else
30+
states = [Dict([(base(b, k, 6), contents[rem(div(k,b^p),b)+1]) for k=0:(b^3)^2-1]) for p=0:5]
31+
end
3032

31-
git_setup(states[1:3]...)
32-
try Git.transact() do
33-
git_setup(states[4:6]...)
34-
throw(nothing)
35-
end catch x
36-
x === nothing || rethrow()
33+
git_setup(states[1:3]...)
34+
try Git.transact() do
35+
git_setup(states[4:6]...)
36+
throw(nothing)
37+
end catch x
38+
x === nothing || rethrow()
39+
end
40+
git_verify(states[1:3]...)
3741
end
38-
git_verify(states[1:3]...)
39-
end
40-
finally
41-
rm(dir, recursive=true)
4242
end

0 commit comments

Comments
 (0)