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

Use git to get repo root #284

Merged
merged 1 commit into from
Aug 15, 2024
Merged
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
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