FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GitPython/git/test/test_fun.py at py2 · gitpython-developers/GitPython · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
gitpython-developers
/
GitPython
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
989
Star
5.2k
Code
Issues
8
Pull requests
2
Discussions
Actions
Security and quality
34
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
GitPython
/
git
/
test
/
test_fun.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
293 lines (242 loc) · 10.2 KB
Breadcrumbs
GitPython
/
git
/
test
/
test_fun.py
Copy path
File metadata and controls
293 lines (242 loc) · 10.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
from
io
import
BytesIO
from
stat
import
S_IFDIR
,
S_IFREG
,
S_IFLNK
from
os
import
stat
import
os
.
path
as
osp
from
unittest
import
skipIf
,
SkipTest
from
git
import
Git
from
git
.
compat
import
PY3
from
git
.
index
import
IndexFile
from
git
.
index
.
fun
import
(
aggressive_tree_merge
)
from
git
.
objects
.
fun
import
(
traverse_tree_recursive
,
traverse_trees_recursive
,
tree_to_stream
,
tree_entries_from_data
,
)
from
git
.
repo
.
fun
import
(
find_worktree_git_dir
)
from
git
.
test
.
lib
import
(
assert_true
,
TestBase
,
with_rw_repo
,
with_rw_directory
)
from
git
.
util
import
bin_to_hex
,
cygpath
,
join_path_native
from
gitdb
.
base
import
IStream
from
gitdb
.
typ
import
str_tree_type
class
TestFun
(
TestBase
):
def
_assert_index_entries
(
self
,
entries
,
trees
):
index
=
IndexFile
.
from_tree
(
self
.
rorepo
,
*
[
self
.
rorepo
.
tree
(
bin_to_hex
(
t
).
decode
(
'ascii'
))
for
t
in
trees
])
assert
entries
assert
len
(
index
.
entries
)
==
len
(
entries
)
for
entry
in
entries
:
assert
(
entry
.
path
,
entry
.
stage
)
in
index
.
entries
# END assert entry matches fully
def
test_aggressive_tree_merge
(
self
):
# head tree with additions, removals and modification compared to its predecessor
odb
=
self
.
rorepo
.
odb
HC
=
self
.
rorepo
.
commit
(
"6c1faef799095f3990e9970bc2cb10aa0221cf9c"
)
H
=
HC
.
tree
B
=
HC
.
parents
[
0
].
tree
# entries from single tree
trees
=
[
H
.
binsha
]
self
.
_assert_index_entries
(
aggressive_tree_merge
(
odb
,
trees
),
trees
)
# from multiple trees
trees
=
[
B
.
binsha
,
H
.
binsha
]
self
.
_assert_index_entries
(
aggressive_tree_merge
(
odb
,
trees
),
trees
)
# three way, no conflict
tree
=
self
.
rorepo
.
tree
B
=
tree
(
"35a09c0534e89b2d43ec4101a5fb54576b577905"
)
H
=
tree
(
"4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4"
)
M
=
tree
(
"1f2b19de3301e76ab3a6187a49c9c93ff78bafbd"
)
trees
=
[
B
.
binsha
,
H
.
binsha
,
M
.
binsha
]
self
.
_assert_index_entries
(
aggressive_tree_merge
(
odb
,
trees
),
trees
)
# three-way, conflict in at least one file, both modified
B
=
tree
(
"a7a4388eeaa4b6b94192dce67257a34c4a6cbd26"
)
H
=
tree
(
"f9cec00938d9059882bb8eabdaf2f775943e00e5"
)
M
=
tree
(
"44a601a068f4f543f73fd9c49e264c931b1e1652"
)
trees
=
[
B
.
binsha
,
H
.
binsha
,
M
.
binsha
]
self
.
_assert_index_entries
(
aggressive_tree_merge
(
odb
,
trees
),
trees
)
# too many trees
self
.
failUnlessRaises
(
ValueError
,
aggressive_tree_merge
,
odb
,
trees
*
2
)
def
mktree
(
self
,
odb
,
entries
):
"""create a tree from the given tree entries and safe it to the database"""
sio
=
BytesIO
()
tree_to_stream
(
entries
,
sio
.
write
)
sio
.
seek
(
0
)
istream
=
odb
.
store
(
IStream
(
str_tree_type
,
len
(
sio
.
getvalue
()),
sio
))
return
istream
.
binsha
@
with_rw_repo
(
'0.1.6'
)
def
test_three_way_merge
(
self
,
rwrepo
):
def
mkfile
(
name
,
sha
,
executable
=
0
):
return
(
sha
,
S_IFREG
|
0o644
|
executable
*
0o111
,
name
)
def
mkcommit
(
name
,
sha
):
return
(
sha
,
S_IFDIR
|
S_IFLNK
,
name
)
def
assert_entries
(
entries
,
num_entries
,
has_conflict
=
False
):
assert
len
(
entries
)
==
num_entries
assert
has_conflict
==
(
len
([
e
for
e
in
entries
if
e
.
stage
!=
0
])
>
0
)
mktree
=
self
.
mktree
shaa
=
b"
\1
"
*
20
shab
=
b"
\2
"
*
20
shac
=
b"
\3
"
*
20
odb
=
rwrepo
.
odb
# base tree
bfn
=
'basefile'
fbase
=
mkfile
(
bfn
,
shaa
)
tb
=
mktree
(
odb
, [
fbase
])
# non-conflicting new files, same data
fa
=
mkfile
(
'1'
,
shab
)
th
=
mktree
(
odb
, [
fbase
,
fa
])
fb
=
mkfile
(
'2'
,
shac
)
tm
=
mktree
(
odb
, [
fbase
,
fb
])
# two new files, same base file
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
3
)
# both delete same file, add own one
fa
=
mkfile
(
'1'
,
shab
)
th
=
mktree
(
odb
, [
fa
])
fb
=
mkfile
(
'2'
,
shac
)
tm
=
mktree
(
odb
, [
fb
])
# two new files
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
2
)
# same file added in both, differently
fa
=
mkfile
(
'1'
,
shab
)
th
=
mktree
(
odb
, [
fa
])
fb
=
mkfile
(
'1'
,
shac
)
tm
=
mktree
(
odb
, [
fb
])
# expect conflict
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
2
,
True
)
# same file added, different mode
fa
=
mkfile
(
'1'
,
shab
)
th
=
mktree
(
odb
, [
fa
])
fb
=
mkcommit
(
'1'
,
shab
)
tm
=
mktree
(
odb
, [
fb
])
# expect conflict
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
2
,
True
)
# same file added in both
fa
=
mkfile
(
'1'
,
shab
)
th
=
mktree
(
odb
, [
fa
])
fb
=
mkfile
(
'1'
,
shab
)
tm
=
mktree
(
odb
, [
fb
])
# expect conflict
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
1
)
# modify same base file, differently
fa
=
mkfile
(
bfn
,
shab
)
th
=
mktree
(
odb
, [
fa
])
fb
=
mkfile
(
bfn
,
shac
)
tm
=
mktree
(
odb
, [
fb
])
# conflict, 3 versions on 3 stages
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
3
,
True
)
# change mode on same base file, by making one a commit, the other executable
# no content change ( this is totally unlikely to happen in the real world )
fa
=
mkcommit
(
bfn
,
shaa
)
th
=
mktree
(
odb
, [
fa
])
fb
=
mkfile
(
bfn
,
shaa
,
executable
=
1
)
tm
=
mktree
(
odb
, [
fb
])
# conflict, 3 versions on 3 stages, because of different mode
trees
=
[
tb
,
th
,
tm
]
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
3
,
True
)
for
is_them
in
range
(
2
):
# only we/they change contents
fa
=
mkfile
(
bfn
,
shab
)
th
=
mktree
(
odb
, [
fa
])
trees
=
[
tb
,
th
,
tb
]
if
is_them
:
trees
=
[
tb
,
tb
,
th
]
entries
=
aggressive_tree_merge
(
odb
,
trees
)
assert
len
(
entries
)
==
1
and
entries
[
0
].
binsha
==
shab
# only we/they change the mode
fa
=
mkcommit
(
bfn
,
shaa
)
th
=
mktree
(
odb
, [
fa
])
trees
=
[
tb
,
th
,
tb
]
if
is_them
:
trees
=
[
tb
,
tb
,
th
]
entries
=
aggressive_tree_merge
(
odb
,
trees
)
assert
len
(
entries
)
==
1
and
entries
[
0
].
binsha
==
shaa
and
entries
[
0
].
mode
==
fa
[
1
]
# one side deletes, the other changes = conflict
fa
=
mkfile
(
bfn
,
shab
)
th
=
mktree
(
odb
, [
fa
])
tm
=
mktree
(
odb
, [])
trees
=
[
tb
,
th
,
tm
]
if
is_them
:
trees
=
[
tb
,
tm
,
th
]
# as one is deleted, there are only 2 entries
assert_entries
(
aggressive_tree_merge
(
odb
,
trees
),
2
,
True
)
# END handle ours, theirs
def
_assert_tree_entries
(
self
,
entries
,
num_trees
):
for
entry
in
entries
:
assert
len
(
entry
)
==
num_trees
paths
=
{
e
[
2
]
for
e
in
entry
if
e
}
# only one path per set of entries
assert
len
(
paths
)
==
1
# END verify entry
def
test_tree_traversal
(
self
):
# low level tree tarversal
odb
=
self
.
rorepo
.
odb
H
=
self
.
rorepo
.
tree
(
'29eb123beb1c55e5db4aa652d843adccbd09ae18'
)
# head tree
M
=
self
.
rorepo
.
tree
(
'e14e3f143e7260de9581aee27e5a9b2645db72de'
)
# merge tree
B
=
self
.
rorepo
.
tree
(
'f606937a7a21237c866efafcad33675e6539c103'
)
# base tree
B_old
=
self
.
rorepo
.
tree
(
'1f66cfbbce58b4b552b041707a12d437cc5f400a'
)
# old base tree
# two very different trees
entries
=
traverse_trees_recursive
(
odb
, [
B_old
.
binsha
,
H
.
binsha
],
''
)
self
.
_assert_tree_entries
(
entries
,
2
)
oentries
=
traverse_trees_recursive
(
odb
, [
H
.
binsha
,
B_old
.
binsha
],
''
)
assert
len
(
oentries
)
==
len
(
entries
)
self
.
_assert_tree_entries
(
oentries
,
2
)
# single tree
is_no_tree
=
lambda
i
,
d
:
i
.
type
!=
'tree'
entries
=
traverse_trees_recursive
(
odb
, [
B
.
binsha
],
''
)
assert
len
(
entries
)
==
len
(
list
(
B
.
traverse
(
predicate
=
is_no_tree
)))
self
.
_assert_tree_entries
(
entries
,
1
)
# two trees
entries
=
traverse_trees_recursive
(
odb
, [
B
.
binsha
,
H
.
binsha
],
''
)
self
.
_assert_tree_entries
(
entries
,
2
)
# tree trees
entries
=
traverse_trees_recursive
(
odb
, [
B
.
binsha
,
H
.
binsha
,
M
.
binsha
],
''
)
self
.
_assert_tree_entries
(
entries
,
3
)
def
test_tree_traversal_single
(
self
):
max_count
=
50
count
=
0
odb
=
self
.
rorepo
.
odb
for
commit
in
self
.
rorepo
.
commit
(
"29eb123beb1c55e5db4aa652d843adccbd09ae18"
).
traverse
():
if
count
>=
max_count
:
break
count
+=
1
entries
=
traverse_tree_recursive
(
odb
,
commit
.
tree
.
binsha
,
''
)
assert
entries
# END for each commit
@
with_rw_directory
def
test_linked_worktree_traversal
(
self
,
rw_dir
):
"""Check that we can identify a linked worktree based on a .git file"""
git
=
Git
(
rw_dir
)
if
git
.
version_info
[:
3
]
<
(
2
,
5
,
1
):
raise
SkipTest
(
"worktree feature unsupported"
)
rw_master
=
self
.
rorepo
.
clone
(
join_path_native
(
rw_dir
,
'master_repo'
))
branch
=
rw_master
.
create_head
(
'aaaaaaaa'
)
worktree_path
=
join_path_native
(
rw_dir
,
'worktree_repo'
)
if
Git
.
is_cygwin
():
worktree_path
=
cygpath
(
worktree_path
)
rw_master
.
git
.
worktree
(
'add'
,
worktree_path
,
branch
.
name
)
dotgit
=
osp
.
join
(
worktree_path
,
".git"
)
statbuf
=
stat
(
dotgit
)
assert_true
(
statbuf
.
st_mode
&
S_IFREG
)
gitdir
=
find_worktree_git_dir
(
dotgit
)
self
.
assertIsNotNone
(
gitdir
)
statbuf
=
stat
(
gitdir
)
assert_true
(
statbuf
.
st_mode
&
S_IFDIR
)
@
skipIf
(
PY3
,
'odd types returned ... maybe figure it out one day'
)
def
test_tree_entries_from_data_with_failing_name_decode_py2
(
self
):
r
=
tree_entries_from_data
(
b'100644
\x9f
\0
aaa'
)
assert
r
==
[(
'aaa'
,
33188
,
u'
\udc9f
'
)],
r
@
skipIf
(
not
PY3
,
'odd types returned ... maybe figure it out one day'
)
def
test_tree_entries_from_data_with_failing_name_decode_py3
(
self
):
r
=
tree_entries_from_data
(
b'100644
\x9f
\0
aaa'
)
assert
r
==
[(
b'aaa'
,
33188
,
'
\udc9f
'
)],
r
Back
|
FazBrowse Home
|
New Git URL