1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
class TestTreeOps < Test::Unit::TestCase
def setup
set_file_paths
@git = Git.open(@wdir)
end
def test_read_tree
in_temp_dir do
g = Git.clone(@wbare, 'test')
g.chdir do
g.branch('testbranch1').in_branch('tb commit 1') do
new_file('test-file1', 'blahblahblah2')
g.add
true
end
g.branch('testbranch2').in_branch('tb commit 2') do
new_file('test-file2', 'blahblahblah3')
g.add
true
end
g.branch('testbranch3').in_branch('tb commit 3') do
new_file('test-file3', 'blahblahblah4')
g.add
true
end
# test some read-trees
tr = g.with_temp_index do
g.read_tree('testbranch1')
g.read_tree('testbranch2', :prefix => 'b2/')
g.read_tree('testbranch3', :prefix => 'b2/b3/')
index = g.ls_files
assert(index['b2/test-file2'])
assert(index['b2/b3/test-file3'])
g.write_tree
end
assert_equal('2423ef1b38b3a140bbebf625ba024189c872e08b', tr)
# only prefixed read-trees
tr = g.with_temp_index do
g.add # add whats in our working tree
g.read_tree('testbranch1', :prefix => 'b1/')
g.read_tree('testbranch3', :prefix => 'b2/b3/')
index = g.ls_files
assert(index['example.txt'])
assert(index['b1/test-file1'])
assert(!index['b2/test-file2'])
assert(index['b2/b3/test-file3'])
g.write_tree
end
assert_equal('aa7349e1cdaf4b85cc6a6a0cf4f9b3f24879fa42', tr)
# new working directory too
tr = nil
g.with_temp_working do
tr = g.with_temp_index do
assert_raises Git::GitExecuteError do
g.add # add whats in our working tree - should be nothing
end
g.read_tree('testbranch1', :prefix => 'b1/')
g.read_tree('testbranch3', :prefix => 'b1/b3/')
index = g.ls_files
assert(!index['example.txt'])
assert(index['b1/test-file1'])
assert(!index['b2/test-file2'])
assert(index['b1/b3/test-file3'])
g.write_tree
end
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', tr)
end
c = g.commit_tree(tr, :parents => 'HEAD')
assert(c.commit?)
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)
tmp = Tempfile.new('tesxt')
tmppath = tmp.path
tmp.unlink
tr2 = g.with_index(tmppath) do
g.read_tree('testbranch1', :prefix => 'b1/')
g.read_tree('testbranch3', :prefix => 'b3/')
index = g.ls_files
assert(!index['b2/test-file2'])
assert(index['b3/test-file3'])
g.commit('hi')
end
assert(c.commit?)
files = g.ls_files
assert(!files['b1/example.txt'])
g.branch('newbranch').update_ref(c)
g.checkout('newbranch')
assert(!files['b1/example.txt'])
assert_equal('b40f7a9072cdec637725700668f8fdebe39e6d38', c.gtree.sha)
g.with_temp_working do
assert(!File.directory?('b1'))
g.checkout_index
assert(!File.directory?('b1'))
g.checkout_index(:all => true)
assert(File.directory?('b1'))
end
end
end
end
end
|