Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit a540165

Browse files
git: comprehensive testing of Git.transact & fixes to pass testing.
1 parent 35c6dfd commit a540165

File tree

2 files changed

+32
-42
lines changed

2 files changed

+32
-42
lines changed

base/git.jl

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@ head() = readchomp(`git rev-parse HEAD`)
2222
function transact(f::Function)
2323
head = readchomp(`git rev-parse HEAD`)
2424
index = readchomp(`git write-tree`)
25-
worktree = try
25+
work = try
2626
run(`git add --all`)
2727
run(`git add .`)
2828
readchomp(`git write-tree`)
2929
finally
30-
run(`git read-tree $index`) # restore index
30+
run(`git read-tree $index`) # restore index
3131
end
3232
try f() catch
33-
run(`git reset -q --`) # unstage everything
34-
run(`git checkout -q -f $worktree -- .`) # retore work tree
35-
run(`git clean -qdf`) # remove everything else
36-
run(`git read-tree $index`) # restore index
37-
run(`git reset -q --soft $head`) # restore head
33+
run(`git reset -q --`) # unstage everything
34+
run(`git read-tree $work`) # move work tree to index
35+
run(`git checkout-index -fa`) # check the index out to work
36+
run(`git clean -qdf`) # remove everything else
37+
run(`git read-tree $index`) # restore index
38+
run(`git reset -q --soft $head`) # restore head
3839
rethrow()
3940
end
4041
end

test/git.jl

+24-35
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,35 @@
11
import Base.Git
2+
include("gitutils.jl")
23

34
dir = string("tmp.",randstring())
45
@test !ispath(dir)
56
mkdir(dir)
67
@test isdir(dir)
7-
try # ensure directory removal
8-
cd(dir) do
8+
try cd(dir) do
99

10-
run(`git init -q`)
11-
run(`git commit -q --allow-empty -m "initial empty commit"`)
10+
run(`git init -q`)
11+
run(`git commit -q --allow-empty -m "initial empty commit"`)
12+
verify_tree(Dict(), "HEAD")
13+
verify_work(Dict())
1214

13-
for a=["unchanged","changed","removed"], b=["tracked","untracked"]
14-
run(`echo -n before` > "$a.$b")
15-
b == "tracked" && run(`git add $a.$b`)
16-
end
15+
# each path can have one of these content in each of head, index, work
16+
# for a total of length(contents)^3 = 4^3 = 64 combinations.
17+
# each path can be in any of these 64 "superpositions" before & after
18+
# for a total of 64^2 = 4096 files needed to test all transitions
19+
# between before and after superpositions of git repo states.
1720

18-
try Git.transact() do
19-
for a=["added","changed"], b=["tracked","untracked"]
20-
run(`rm -f $a.$b`) # FIXME: delete this pending #2640
21-
run(`echo -n after` > "$a.$b")
22-
@test isfile("$a.$b")
23-
@test readall("$a.$b") == "after"
24-
end
25-
for b=["tracked","untracked"]
26-
run(`rm removed.$b`)
27-
@test !ispath("removed.$b")
28-
end
29-
run(`git add added.tracked`)
30-
throw(nothing)
31-
end catch x
32-
is(x,nothing) || rethrow()
33-
end
21+
contents = [nothing, "foo", "bar", {"baz"=>"qux"}]
22+
b = length(contents)
23+
files = 0:(b^3)^2-1
24+
states = [ [ base(b,k,6) => contents[rem(div(k,b^p),b)+1] for k in files ] for p=0:5 ]
3425

35-
for a=["unchanged","changed","removed"], b=["tracked","untracked"]
36-
@test isfile("$a.$b")
37-
@test readall("$a.$b") == "before"
38-
end
39-
for b=["tracked","untracked"]
40-
@test !ispath("added.$b")
41-
end
26+
git_setup(states[1:3]...)
27+
try Git.transact() do
28+
git_setup(states[4:6]...)
29+
throw(nothing)
30+
end catch x
31+
is(x,nothing) || rethrow()
32+
end
33+
git_verify(states[1:3]...)
4234

43-
end # cd
44-
finally
45-
run(`rm -rf $dir`)
46-
end
35+
end finally run(`rm -rf $dir`) end

0 commit comments

Comments
 (0)