Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't crash if .git/ is present but git is not installed #226

Merged
merged 3 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Fixed
- Fixed an issue where library symlinks with the same basename would present
problems ([#225])
- Don't crash if .git/ dir is present but git is not installed ([#226])

## [0.13.6] - 2021-12-02
### Changed
Expand Down Expand Up @@ -305,3 +306,4 @@ Initial release
[#210]: https://github.com/JonathonReinhart/staticx/pull/210
[#217]: https://github.com/JonathonReinhart/staticx/pull/217
[#225]: https://github.com/JonathonReinhart/staticx/pull/225
[#226]: https://github.com/JonathonReinhart/staticx/pull/226
36 changes: 20 additions & 16 deletions staticx/version.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from os.path import abspath, dirname, exists, join, normpath
from pathlib import Path
import subprocess
import sys

# This logic has been adapted from that of PyInstaller
# https://github.com/pyinstaller/pyinstaller/

PACKAGEPATH = abspath(dirname(__file__))
PROJPATH = dirname(PACKAGEPATH)
PACKAGEPATH = Path(__file__).absolute().parent
PROJPATH = PACKAGEPATH.parent

# Base version, which will be augmented with Git information
BASE_VERSION = '0.13.6'
Expand All @@ -32,19 +32,23 @@ def get_version():

# Git repo
# If a local git repository is present, use `git describe` to provide a rich version
gitdir = normpath(join(PROJPATH, '.git'))
if exists(gitdir):
tag, commits, rev = git_describe()

# Ensure the base version matches the Git tag
if tag != BASE_VERSION:
raise Exception('Git revision different from base version')

# No local version if we're on a tag
if commits == 0 and not rev.endswith('dirty'):
return BASE_VERSION

return '{}+{}-{}'.format(BASE_VERSION, commits, rev)
gitdir = PROJPATH / '.git'
if gitdir.exists():
try:
tag, commits, rev = git_describe()
except FileNotFoundError:
# git not installed
pass
else:
# Ensure the base version matches the Git tag
if tag != BASE_VERSION:
raise Exception('Git revision different from base version')

# No local version if we're on a tag
if commits == 0 and not rev.endswith('dirty'):
return BASE_VERSION

return '{}+{}-{}'.format(BASE_VERSION, commits, rev)


# Git archive
Expand Down