Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Handle FileNotFound error in checking git repository version #6284

Merged
merged 2 commits into from
Oct 30, 2019
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
1 change: 1 addition & 0 deletions changelog.d/6284.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent errors from appearing on Synapse startup if `git` is not installed.
10 changes: 6 additions & 4 deletions synapse/util/versionstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_version_string(module):
try:
null = open(os.devnull, "w")
cwd = os.path.dirname(os.path.abspath(module.__file__))

try:
git_branch = (
subprocess.check_output(
Expand All @@ -51,7 +52,8 @@ def get_version_string(module):
.decode("ascii")
)
git_branch = "b=" + git_branch
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
# FileNotFoundError can arise when git is not installed
git_branch = ""

try:
Expand All @@ -63,7 +65,7 @@ def get_version_string(module):
.decode("ascii")
)
git_tag = "t=" + git_tag
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
git_tag = ""

try:
Expand All @@ -74,7 +76,7 @@ def get_version_string(module):
.strip()
.decode("ascii")
)
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
git_commit = ""

try:
Expand All @@ -89,7 +91,7 @@ def get_version_string(module):
)

git_dirty = "dirty" if is_dirty else ""
except subprocess.CalledProcessError:
except (subprocess.CalledProcessError, FileNotFoundError):
git_dirty = ""

if git_branch or git_tag or git_commit or git_dirty:
Expand Down