Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
tango
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LOFAR2.0
tango
Commits
2de751b7
Commit
2de751b7
authored
3 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
L2SS-176
: Provide sane default where to look for a repo
parent
b16ce8e0
No related branches found
No related tags found
1 merge request
!35
Resolve L2SS-176 "Expose git version"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
devices/util/lofar_git.py
+39
-0
39 additions, 0 deletions
devices/util/lofar_git.py
with
39 additions
and
0 deletions
devices/util/lofar_git.py
0 → 100644
+
39
−
0
View file @
2de751b7
import
git
# pip3 install gitpython
import
os
def
get_repo
(
starting_directory
:
str
=
os
.
path
.
dirname
(
__file__
))
->
git
.
Repo
:
"""
Try finding the repository by traversing up the tree.
By default, the repository containing this module is returned.
"""
directory
=
starting_directory
try
:
return
git
.
Repo
(
directory
)
except
git
.
InvalidGitRepositoryError
:
pass
# We now have to traverse up the tree
while
directory
!=
"
/
"
and
os
.
path
.
exists
(
directory
):
# Go to parent
directory
=
os
.
path
.
abspath
(
directory
+
os
.
path
.
sep
+
"
..
"
)
try
:
return
git
.
Repo
(
directory
)
except
git
.
InvalidGitRepositoryError
:
pass
raise
git
.
InvalidGitRepositoryError
(
"
Could not find git repository root in {}
"
.
format
(
starting_directory
))
def
get_version
(
repo
:
git
.
Repo
=
None
)
->
str
:
"""
Return a version string for the current commit.
"""
if
repo
is
None
:
repo
=
get_repo
()
return
"
{} [{}{}]
"
.
format
(
repo
.
active_branch
,
repo
.
commit
(),
"
(dirty)
"
if
repo
.
is_dirty
()
else
""
)
if
__name__
==
"
__main__
"
:
print
(
get_version
())
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