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
Service Desk
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
Show more breadcrumbs
heptapod
py-heptapod
Merge requests
!111
More test helpers
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
More test helpers
topic/default/testhelpers
into
branch/default
Overview
0
Commits
2
Pipelines
8
Changes
3
Merged
Georges Racinet
requested to merge
topic/default/testhelpers
into
branch/default
1 month ago
Overview
0
Commits
2
Pipelines
8
Changes
1
Expand
Will be useful to avoid duplication in HGitaly tests
0
0
Merge request reports
Compare
version 1
version 3
bba4ca24
1 month ago
version 2
092bc715
1 month ago
version 1
7521db96
1 month ago
branch/default (base)
and
version 2
latest version
a5fd743b
2 commits,
1 month ago
version 3
bba4ca24
2 commits,
1 month ago
version 2
092bc715
2 commits,
1 month ago
version 1
7521db96
2 commits,
1 month ago
Show latest version
1 file
+
24
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
heptapod/testhelpers/git.py
+
24
−
6
Options
@@ -14,6 +14,7 @@
typically solved by installing Git system-wide.
"""
import
os
import
re
import
shutil
import
subprocess
from
mercurial
import
pycompat
@@ -35,6 +36,15 @@
return
{
ref
:
info
[
'
title
'
]
for
ref
,
info
in
branches
.
items
()}
def
git_version
():
out
=
subprocess
.
check_output
((
'
git
'
,
'
version
'
)).
decode
().
strip
()
m
=
re
.
match
(
r
'
git version (\d+)\.(\d+)\.(\d+)
'
,
out
)
return
tuple
(
int
(
m
.
group
(
i
))
for
i
in
range
(
1
,
4
))
GIT_VERSION
=
git_version
()
class
GitRepo
(
object
):
"""
Represent a Git repository, relying on the Git executable.
@@ -111,7 +121,7 @@
return
{
split
[
1
]:
split
[
0
]
for
split
in
(
line
.
split
(
b
'
'
,
1
)
for
line
in
lines
)}
def
raw_refs
(
self
):
def
raw_refs
(
self
,
with_root_refs
=
False
):
"""
Use `git for-each-ref` to query all refs, including
"
root refs
"
The output is the full `stdout` of the Git process, as bytes.
@@ -127,10 +137,12 @@
Git sorts the output on `refname` (e.g., `refs/heads/main` or `HEAD`)
by default, which is fine to compare two repositories.
"""
return
self
.
git
(
'
for-each-ref
'
,
'
--include-root-refs
'
,
'
--format
'
,
'
%(objectname)s %(refname) %(symref)
'
,
)
git_args
=
[
'
for-each-ref
'
,
'
--format
'
,
'
%(objectname)s %(refname) %(symref)
'
]
if
with_root_refs
:
git_args
.
append
(
'
--include-root-refs
'
)
# pragma no cover
return
self
.
git
(
*
git_args
)
def
__eq__
(
self
,
other
):
"""
True iff the two repos have the same content.
@@ -141,4 +153,10 @@
if
not
isinstance
(
other
,
GitRepo
):
return
False
return
self
.
raw_refs
()
==
other
.
raw_refs
()
opts
=
dict
(
with_root_refs
=
True
)
if
GIT_VERSION
<
(
2
,
45
,
0
):
# pragma no cover
opts
[
'
with_root_refs
'
]
=
False
if
self
.
get_symref
(
'
HEAD
'
)
!=
other
.
get_symref
(
'
HEAD
'
):
return
False
return
self
.
raw_refs
(
**
opts
)
==
other
.
raw_refs
(
**
opts
)
Loading