Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
py-heptapod
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
This instance will be upgraded to Heptapod 17.11.0rc1 on 2025-04-24 between 17:00 and 18:00 UTC+2
Show more breadcrumbs
heptapod
py-heptapod
Commits
3b02a4ed
Commit
3b02a4ed
authored
5 years ago
by
Georges Racinet
Browse files
Options
Downloads
Patches
Plain Diff
testhelpers: write_commit parent kwarg
parent
9e636c1c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
heptapod/testhelpers.py
+20
-1
20 additions, 1 deletion
heptapod/testhelpers.py
heptapod/tests/test_testhelpers.py
+28
-1
28 additions, 1 deletion
heptapod/tests/test_testhelpers.py
with
48 additions
and
2 deletions
heptapod/testhelpers.py
+
20
−
1
View file @
3b02a4ed
...
...
@@ -56,7 +56,7 @@
ui
=
make_ui
(
base_ui
,
config
=
config
)
return
cls
(
hg
.
repository
(
ui
,
path
))
def
write_commit
(
self
,
rpath
,
content
=
None
,
message
=
None
):
def
write_commit
(
self
,
rpath
,
content
=
None
,
message
=
None
,
parent
=
None
):
"""
Write content at rpath and commit in one call.
This is meant to allow fast and efficient preparation of
...
...
@@ -72,6 +72,10 @@
If not specified, will be replaced by random content.
:param message: message commit. If not specified, defaults to
``content``
:param parent: binary node value. If specified, the repository is
updated to it first. Useful to produce branching
histories. This is single valued, because the purpose
of this method is not to produce merge commits.
:returns: binary node for the resulting commit.
"""
rpath
=
str
(
rpath
)
...
...
@@ -81,6 +85,9 @@
content
=
"
some content that should be random
"
if
message
is
None
:
message
=
content
if
parent
is
not
None
:
self
.
update_bin
(
parent
)
flags
=
'
wb
'
if
isinstance
(
content
,
bytes
)
else
'
w
'
with
open
(
path
,
flags
)
as
fobj
:
fobj
.
write
(
content
)
...
...
@@ -95,3 +102,15 @@
return
cmdutil
.
commit
(
repo
.
ui
,
repo
,
commitfun
,
(
path
,
),
dict
(
addremove
=
True
,
message
=
message
))
def
update_bin
(
self
,
bin_node
):
"""
Update to a revision specified by its node in binary form.
This is separated in order to avoid ambiguities
"""
# maybe we'll do something lower level later
self
.
update
(
node
.
hex
(
bin_node
))
def
update
(
self
,
rev
):
repo
=
self
.
repo
cmdutil
.
findcmd
(
'
update
'
,
commands
.
table
)[
1
][
0
](
repo
.
ui
,
repo
,
rev
)
This diff is collapsed.
Click to expand it.
heptapod/tests/test_testhelpers.py
+
28
−
1
View file @
3b02a4ed
...
...
@@ -67,7 +67,6 @@
def
test_init_config_extension
(
tmpdir
):
from
mercurial
import
ui
as
uimod
ui
=
uimod
.
ui
.
load
()
ui
.
setconfig
(
'
foo
'
,
'
bar
'
,
'
yes
'
,
source
=
'
tests
'
)
ui
.
setconfig
(
'
extensions
'
,
'
heptapod
'
,
HGEXT_HEPTA_SOURCE
,
source
=
'
tests
'
)
...
...
@@ -80,3 +79,31 @@
assert
wrapper
.
repo
.
ui
.
configbool
(
'
foo
'
,
'
bar
'
)
exts
=
dict
(
extensions
.
extensions
(
wrapper
.
repo
.
ui
))
assert_is_hepta_ext
(
exts
.
get
(
'
heptapod
'
))
def
test_update
(
tmpdir
):
wrapper
=
LocalRepoWrapper
.
init
(
tmpdir
)
wrapper
.
write_commit
(
'
foo
'
,
content
=
'
Foo 0
'
)
node1
=
wrapper
.
write_commit
(
'
foo
'
,
content
=
'
Foo 1
'
)
foo
=
tmpdir
.
join
(
'
foo
'
)
assert
foo
.
read
()
==
'
Foo 1
'
wrapper
.
update
(
'
0
'
)
assert
foo
.
read
()
==
'
Foo 0
'
wrapper
.
update_bin
(
NULL_ID
)
assert
not
foo
.
isfile
()
wrapper
.
update_bin
(
node1
)
assert
foo
.
read
()
==
'
Foo 1
'
def
test_write_commit_branching
(
tmpdir
):
"""
Demonstrate the use of write_commit with parent.
"""
wrapper
=
LocalRepoWrapper
.
init
(
tmpdir
)
node0
=
wrapper
.
write_commit
(
'
foo
'
,
content
=
'
Foo 0
'
)
wrapper
.
write_commit
(
'
foo
'
,
content
=
'
Foo 1
'
)
nodebr
=
wrapper
.
write_commit
(
'
foo
'
,
content
=
'
Foo branch
'
,
parent
=
node0
)
ctxbr
=
wrapper
.
repo
[
nodebr
]
assert
[
c
.
node
()
for
c
in
ctxbr
.
parents
()]
==
[
node0
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment