Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod-tests
Commits
2b6ab4a10a1a
Commit
fb858a8d
authored
Feb 15, 2020
by
Georges Racinet
🦑
Browse files
Moved bookmarks tests aside
parent
dd2a03f35b5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
tests/test_bookmarks.py
0 → 100644
View file @
2b6ab4a1
from
.utils
import
needs
from
.utils.hg
import
LocalRepo
@
needs
.
fs_access
def
test_push_bookmarks_default_branch
(
test_project
,
tmpdir
):
repo_path
=
tmpdir
.
join
(
'repo1'
)
url
=
test_project
.
owner_basic_auth_url
repo
=
LocalRepo
.
init
(
repo_path
)
# As usual, let's make a first public changeset
repo_path
.
join
(
'foo'
).
write
(
'foo0'
)
repo
.
hg
(
'commit'
,
'-Am'
,
"Commit 0"
)
repo
.
hg
(
'phase'
,
'-p'
,
"."
)
repo
.
hg
(
'push'
,
url
)
repo_path
.
join
(
'foo'
).
write
(
'foo1'
)
repo
.
hg
(
'commit'
,
'-m'
,
"Commit 1"
)
repo
.
hg
(
'bookmark'
,
'-r'
,
'.'
,
'book1'
)
print
(
repo
.
graphlog
())
code
,
out
,
err
=
repo
.
hg_unchecked
(
'push'
,
'-B'
,
'book1'
,
url
)
assert
code
!=
0
,
"Bookmarks should be forbidden by default"
assert
'forbidden'
in
out
.
lower
()
# now let's allow bookmarks on non-topic changesets
# for the time being, bookmarks are still considered to create
# multiple heads, i.e., branchmap() ignores them
test_project
.
extend_hgrc
(
"[experimental]"
,
"single-head-per-branch = no"
,
"hg-git.bookmarks-on-named-branches = yes"
)
repo
.
hg
(
'push'
,
'-B'
,
'book1'
,
url
)
branches
=
test_project
.
api_branches
()
# even though the 'default' named branch only has bookmarked heads,
# the 'branch/default' GitLab branch should not be pruned, because it is
# also GitLab's default branch (hence also the HEAD of the inner Git repo)
assert
set
(
branches
)
==
{
'branch/default'
,
'book1'
}
assert
branches
[
'branch/default'
][
'commit'
][
'title'
]
==
'Commit 0'
assert
branches
[
'book1'
][
'commit'
][
'title'
]
==
'Commit 1'
# on the other hand, bookmarks on topics are still refused
repo
.
hg
(
'up'
,
'0'
)
repo_path
.
join
(
'foo'
).
write
(
'foo3'
)
repo
.
hg
(
'topic'
,
'topbook'
)
repo
.
hg
(
'commit'
,
'-m'
,
"ontopic"
)
repo
.
hg
(
'bookmark'
,
'-r'
,
'.'
,
'book-on-top'
)
code
,
out
,
err
=
repo
.
hg_unchecked
(
'push'
,
'-B'
,
'book-on-top'
,
url
)
assert
code
!=
0
,
"Bookmarks on topics should be forbidden"
assert
'topbook'
in
out
assert
'book-on-top'
in
out
assert
repo
.
hg
(
'log'
,
'-T'
,
'{node}'
,
'-r'
,
'book-on-top'
)
in
out
# now let's try with a second bookmark on the same branch
# (used to be a limitation of our modified hg-git)
repo
.
hg
(
'up'
,
'0'
)
repo_path
.
join
(
'foo'
).
write
(
'foo2'
)
repo
.
hg
(
'commit'
,
'-m'
,
"Commit 2"
)
repo
.
hg
(
'bookmark'
,
'-r'
,
'.'
,
'book2'
)
# it's also necessary to force-push
repo
.
hg
(
'push'
,
'-f'
,
'-B'
,
'book2'
,
url
)
branches
=
test_project
.
api_branches
()
assert
set
(
branches
)
==
{
'branch/default'
,
'book1'
,
'book2'
}
assert
branches
[
'branch/default'
][
'commit'
][
'title'
]
==
'Commit 0'
assert
branches
[
'book1'
][
'commit'
][
'title'
]
==
'Commit 1'
assert
branches
[
'book2'
][
'commit'
][
'title'
]
==
'Commit 2'
@
needs
.
fs_access
def
test_push_bookmarks_non_default_branch
(
test_project
,
tmpdir
):
repo_path
=
tmpdir
.
join
(
'repo1'
)
url
=
test_project
.
owner_basic_auth_url
repo
=
LocalRepo
.
init
(
repo_path
)
# As usual, let's make a first public changeset
repo_path
.
join
(
'foo'
).
write
(
'foo default'
)
repo
.
hg
(
'commit'
,
'-Am'
,
"Commit on default"
)
repo
.
hg
(
'phase'
,
'-p'
,
"."
)
repo
.
hg
(
'push'
,
url
)
repo
.
hg
(
'branch'
,
'other'
)
repo_path
.
join
(
'foo'
).
write
(
'foo branch'
)
repo
.
hg
(
'commit'
,
'-m'
,
"Commit 0"
)
repo
.
hg
(
'push'
,
'--new-branch'
,
url
)
# Just to be sure
branches
=
test_project
.
api_branches
()
assert
set
(
branches
)
==
{
'branch/default'
,
'branch/other'
}
repo_path
.
join
(
'foo'
).
write
(
'foo1'
)
repo
.
hg
(
'commit'
,
'-m'
,
"Commit 1"
)
repo
.
hg
(
'bookmark'
,
'-r'
,
'.'
,
'book1'
)
print
(
repo
.
graphlog
())
code
,
out
,
err
=
repo
.
hg_unchecked
(
'push'
,
'-B'
,
'book1'
,
url
)
assert
code
!=
0
,
"Bookmarks should be forbidden by default"
assert
'forbidden'
in
out
.
lower
()
# now let's allow bookmarks on non-topic changesets
# for the time being, bookmarks are still considered to create
# multiple heads, i.e., branchmap() ignores them
test_project
.
extend_hgrc
(
"[experimental]"
,
"single-head-per-branch = no"
,
"hg-git.bookmarks-on-named-branches = yes"
)
repo
.
hg
(
'push'
,
'-B'
,
'book1'
,
url
)
# hg branch 'other' has no non bookmarked head, therefore the GitLab
# branch 'branch/other' has been replaced by the bookmark.
branches
=
test_project
.
api_branches
()
assert
set
(
branches
)
==
{
'branch/default'
,
'book1'
}
assert
branches
[
'branch/default'
][
'commit'
][
'title'
]
==
'Commit on default'
assert
branches
[
'book1'
][
'commit'
][
'title'
]
==
'Commit 1'
# on the other hand, bookmarks on topics are still refused
repo
.
hg
(
'up'
,
'1'
)
repo_path
.
join
(
'foo'
).
write
(
'foo3'
)
repo
.
hg
(
'topic'
,
'topbook'
)
repo
.
hg
(
'commit'
,
'-m'
,
"ontopic"
)
repo
.
hg
(
'bookmark'
,
'-r'
,
'.'
,
'book-on-top'
)
code
,
out
,
err
=
repo
.
hg_unchecked
(
'push'
,
'-B'
,
'book-on-top'
,
url
)
assert
code
!=
0
,
"Bookmarks on topics should be forbidden"
assert
'topbook'
in
out
assert
'book-on-top'
in
out
assert
repo
.
hg
(
'log'
,
'-T'
,
'{node}'
,
'-r'
,
'book-on-top'
)
in
out
# now let's try with a second bookmark on the same branch
# (used to be a limitation of our modified hg-git)
repo
.
hg
(
'up'
,
'1'
)
repo_path
.
join
(
'foo'
).
write
(
'foo2'
)
repo
.
hg
(
'commit'
,
'-m'
,
"Commit 2"
)
repo
.
hg
(
'bookmark'
,
'-r'
,
'.'
,
'book2'
)
# it's also necessary to force-push
repo
.
hg
(
'push'
,
'-f'
,
'-B'
,
'book2'
,
url
)
# New bookmark is listed in GitLab branch, 'branch/other' isn't
branches
=
test_project
.
api_branches
()
assert
set
(
branches
)
==
{
'branch/default'
,
'book1'
,
'book2'
}
assert
branches
[
'book1'
][
'commit'
][
'title'
]
==
'Commit 1'
assert
branches
[
'book2'
][
'commit'
][
'title'
]
==
'Commit 2'
# let's add a non bookmarked head and check that it becomes 'branch/other'
# again
repo
.
hg
(
'up'
,
'1'
)
repo_path
.
join
(
'foo'
).
write
(
'not a bookmark'
)
repo
.
hg
(
'commit'
,
'-m'
,
"Not bookmarked"
)
# let's be sure 'book1' hasn't moved
assert
repo
.
hg
(
'bookmarks'
,
'-l'
,
'book1'
,
'-T'
,
'{rev}'
).
strip
()
==
'2'
repo
.
hg
(
'push'
,
'-f'
,
'-r'
,
'.'
,
url
)
branches
=
test_project
.
api_branches
()
assert
set
(
branches
)
==
{
'branch/default'
,
'branch/other'
,
'book1'
,
'book2'
}
assert
branches
[
'book1'
][
'commit'
][
'title'
]
==
'Commit 1'
assert
branches
[
'book2'
][
'commit'
][
'title'
]
==
'Commit 2'
assert
branches
[
'branch/other'
][
'commit'
][
'title'
]
==
'Not bookmarked'
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment