Skip to content

Commit

Permalink
Use git to get repo root (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Aug 15, 2024
1 parent 6702087 commit 1d0aed8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions wpiformat/wpiformat/task.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Task base classes for wpiformat."""

from abc import ABCMeta, abstractmethod
import os
import subprocess


class Task(metaclass=ABCMeta):
Expand Down Expand Up @@ -29,12 +29,12 @@ def get_repo_root():
An empty string is returned if no repository root was found.
"""
current_dir = os.path.abspath(os.getcwd())
while current_dir != os.path.dirname(current_dir):
if os.path.exists(current_dir + os.sep + ".git"):
return current_dir
current_dir = os.path.dirname(current_dir)
return ""
return subprocess.run(
["git", "rev-parse", "--show-toplevel"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
encoding="ascii",
).stdout.rstrip()

@staticmethod
def should_process_file(config_file, name):
Expand Down

0 comments on commit 1d0aed8

Please sign in to comment.