Skip to content

Commit 1436a6e

Browse files
authored
Merge pull request #1286 from effigies/fix/missing-git
FIX: Tolerate missing git
2 parents 4098598 + 46a765d commit 1436a6e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

nibabel/pkg_info.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import sys
4+
from contextlib import suppress
45
from subprocess import run
56

67
from packaging.version import Version
@@ -102,14 +103,16 @@ def pkg_commit_hash(pkg_path: str | None = None) -> tuple[str, str]:
102103
ver = Version(__version__)
103104
if ver.local is not None and ver.local.startswith('g'):
104105
return 'installation', ver.local[1:8]
105-
# maybe we are in a repository
106-
proc = run(
107-
('git', 'rev-parse', '--short', 'HEAD'),
108-
capture_output=True,
109-
cwd=pkg_path,
110-
)
111-
if proc.stdout:
112-
return 'repository', proc.stdout.decode().strip()
106+
# maybe we are in a repository, but consider that we may not have git
107+
with suppress(FileNotFoundError):
108+
proc = run(
109+
('git', 'rev-parse', '--short', 'HEAD'),
110+
capture_output=True,
111+
cwd=pkg_path,
112+
)
113+
if proc.stdout:
114+
return 'repository', proc.stdout.decode().strip()
115+
113116
return '(none found)', '<not found>'
114117

115118

0 commit comments

Comments
 (0)