FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GitPython/test/test_positional_args.py at main · gitpython-developers/GitPython · GitHub
gitpython-developers
GitPython
Repository navigation
Code
Issues
7
(7)
Pull requests
3
(3)
Discussions
Actions
Security and quality
41
(41)
Insights
Expand file tree
Breadcrumbs
GitPython
/
test
/
test_positional_args.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (102 loc) · 5.27 KB
Breadcrumbs
GitPython
/
test
/
test_positional_args.py
Copy path
File metadata and controls
129 lines (102 loc) · 5.27 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
"""High-level operands must not become Git options."""
from
unittest
import
mock
import
pytest
from
git
import
Actor
,
Git
,
GitCommandError
,
Head
,
Remote
,
RemoteReference
,
Repo
,
TagReference
from
git
.
exc
import
UnsafeOptionError
@
pytest
.
mark
.
parametrize
(
"allow_unsafe_options"
, [
False
,
True
])
@
pytest
.
mark
.
parametrize
(
"refspec"
,
[
"--upload-pack=helper"
, [
"--upl=helper"
], [
"main"
,
"--dry-run"
],
"-uhelper"
,
"--arg value"
,
"--"
],
)
def
test_pull_rejects_option_shaped_refspec
(
tmp_path
,
refspec
,
allow_unsafe_options
):
repo
=
Repo
.
init
(
tmp_path
)
remote
=
Remote
(
repo
,
"origin"
)
with
mock
.
patch
.
object
(
Git
,
"_call_process"
,
side_effect
=
AssertionError
(
"Git must not run"
))
as
run
:
with
pytest
.
raises
(
UnsafeOptionError
):
remote
.
pull
(
refspec
,
allow_unsafe_options
=
allow_unsafe_options
)
run
.
assert_not_called
()
def
test_pull_rejects_option_shaped_remote
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
remote
=
Remote
(
repo
,
"--upload-pack=helper"
)
with
mock
.
patch
.
object
(
Git
,
"_call_process"
,
side_effect
=
AssertionError
(
"Git must not run"
))
as
run
:
with
pytest
.
raises
(
UnsafeOptionError
):
remote
.
pull
(
"main"
)
run
.
assert_not_called
()
def
test_pull_preserves_operand_and_explicit_option_values
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
remote
=
Remote
(
repo
,
"origin"
)
with
mock
.
patch
.
object
(
Git
,
"_call_process"
)
as
run
,
mock
.
patch
.
object
(
Remote
,
"_get_fetch_info_from_stderr"
,
return_value
=
[]
):
remote
.
pull
(
"refs/heads/topic"
,
upload_pack
=
"helper with spaces"
,
allow_unsafe_options
=
True
)
assert
run
.
call_args
[
0
]
==
(
"pull"
,
"--"
,
remote
, [
"refs/heads/topic"
])
assert
run
.
call_args
[
1
][
"upload_pack"
]
==
"helper with spaces"
def
test_delete_head_cannot_override_force
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
actor
=
Actor
(
"Test"
,
"test@example.com"
)
initial
=
repo
.
index
.
commit
(
"initial"
,
author
=
actor
,
committer
=
actor
)
branch
=
repo
.
create_head
(
"unmerged"
,
initial
)
branch
.
commit
=
repo
.
index
.
commit
(
"unmerged"
,
head
=
False
,
author
=
actor
,
committer
=
actor
)
with
pytest
.
raises
(
GitCommandError
):
repo
.
delete_head
(
"--force"
,
branch
,
force
=
False
)
assert
branch
.
is_valid
()
repo
.
delete_head
(
branch
,
force
=
True
)
assert
not
branch
.
is_valid
()
def
test_rename_head_cannot_select_current_branch
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
actor
=
Actor
(
"Test"
,
"test@example.com"
)
repo
.
index
.
commit
(
"initial"
,
author
=
actor
,
committer
=
actor
)
original
=
repo
.
active_branch
.
name
with
pytest
.
raises
(
GitCommandError
):
Head
(
repo
,
"refs/heads/--force"
).
rename
(
"renamed"
)
assert
repo
.
active_branch
.
name
==
original
def
test_tag_operands_follow_option_terminator
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
with
mock
.
patch
.
object
(
Git
,
"_call_process"
)
as
run
:
TagReference
.
create
(
repo
,
"topic"
,
"HEAD"
)
assert
run
.
call_args
[
0
]
==
(
"tag"
,
"--"
,
"topic"
,
"HEAD"
)
TagReference
.
delete
(
repo
,
"--list"
)
assert
run
.
call_args
[
0
]
==
(
"tag"
,
"-d"
,
"--"
,
"--list"
)
def
test_remote_ref_delete_preserves_operand
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
ref
=
RemoteReference
(
repo
,
"refs/remotes/--force"
)
with
mock
.
patch
.
object
(
Git
,
"_call_process"
)
as
run
:
RemoteReference
.
delete
(
repo
,
ref
)
assert
run
.
call_args
[
0
]
==
(
"branch"
,
"-d"
,
"-r"
,
"--"
,
ref
)
def
test_move_treats_option_shaped_source_as_filename
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
(
tmp_path
/
"--force"
).
write_text
(
"literal source"
)
repo
.
index
.
add
([
"--force"
])
assert
repo
.
index
.
move
([
"--force"
,
"destination"
])
==
[(
"--force"
,
"destination"
)]
assert
(
tmp_path
/
"destination"
).
read_text
()
==
"literal source"
assert
not
(
tmp_path
/
"--force"
).
exists
()
def
test_move_cannot_override_overwrite_protection
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
for
name
in
(
"--force"
,
"source"
,
"destination"
):
(
tmp_path
/
name
).
write_text
(
name
)
repo
.
index
.
add
([
"--force"
,
"source"
,
"destination"
])
with
pytest
.
raises
(
GitCommandError
):
repo
.
index
.
move
([
"--force"
,
"source"
,
"destination"
])
assert
(
tmp_path
/
"source"
).
read_text
()
==
"source"
assert
(
tmp_path
/
"destination"
).
read_text
()
==
"destination"
repo
.
index
.
move
([
"source"
,
"destination"
],
force
=
True
)
assert
(
tmp_path
/
"destination"
).
read_text
()
==
"source"
def
test_ignored_treats_option_shaped_path_as_filename
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
(
tmp_path
/
".gitignore"
).
write_text
(
"--verbose
\n
--arg value
\n
"
)
assert
repo
.
ignored
(
"--verbose"
,
"--arg value"
)
==
[
"--verbose"
,
"--arg value"
]
def
test_move_cannot_override_dry_run
(
tmp_path
):
repo
=
Repo
.
init
(
tmp_path
)
(
tmp_path
/
"source"
).
write_text
(
"source"
)
repo
.
index
.
add
([
"source"
])
with
pytest
.
raises
(
GitCommandError
):
repo
.
index
.
move
([
"--no-dry-run"
,
"source"
,
"destination"
],
dry_run
=
True
)
assert
(
tmp_path
/
"source"
).
read_text
()
==
"source"
assert
not
(
tmp_path
/
"destination"
).
exists
()
@
pytest
.
mark
.
parametrize
(
"name"
, [
"--prune"
,
"--all"
,
"--upload-pack=helper"
])
def
test_remote_update_rejects_option_shaped_name
(
tmp_path
,
name
):
repo
=
Repo
.
init
(
tmp_path
)
with
mock
.
patch
.
object
(
Git
,
"_call_process"
,
side_effect
=
AssertionError
(
"Git must not run"
))
as
run
:
with
pytest
.
raises
(
UnsafeOptionError
):
Remote
(
repo
,
name
).
update
()
run
.
assert_not_called
()
Back
|
FazBrowse Home
|
New Git URL