Skip to content

Commit 42ea6fa

Browse files
committed
get_git_root_path: check $GIT_DIR first
1 parent c1d2dec commit 42ea6fa

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/fontv/utilities.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ def get_git_root_path(filepath):
4141
:raises: IOError if unable to detect the root of the git repository through this path traversal
4242
"""
4343

44+
if "GIT_DIR" in os.environ:
45+
dot_git = os.path.abspath(os.environ["GIT_DIR"])
46+
if git.repo.fun.is_git_dir(dot_git):
47+
return os.path.dirname(dot_git)
48+
4449
# begin by defining directory that contains font as the git root needle
4550
gitroot_path = os.path.dirname(os.path.abspath(filepath))
4651

tests/test_utilities.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ def test_utilities_get_gitrootpath_function_raises_ioerror_six_levels_up():
8888
get_git_root_path(filepath)
8989

9090

91+
def test_utilities_get_gitrootpath_uses_git_dir_env_var():
92+
os.environ["GIT_DIR"] = os.path.abspath(".git")
93+
filepath = "/this/isnt/even/a/path/but/it/doesnt/matter"
94+
gitdir_path = get_git_root_path(filepath)
95+
assert os.path.basename(gitdir_path) == "font-v"
96+
assert os.path.isdir(gitdir_path) is True
97+
98+
9199
def test_utilities_is_font_ttf():
92100
assert is_font("Test-Regular.ttf") is True
93101

0 commit comments

Comments
 (0)