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

Update check_git_status() to run under ROOT working directory #5441

Merged
merged 9 commits into from
Nov 2, 2021
14 changes: 14 additions & 0 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ def __exit__(self, exc_type, exc_val, exc_tb):
return True


class WorkingDirectory(contextlib.ContextDecorator):
# Usage: @WorkingDirectory(dir) decorator or 'with WorkingDirectory(dir):' context manager
def __init__(self, new_dir):
self.dir = new_dir # new dir
self.cwd = Path.cwd().resolve() # current dir

def __enter__(self):
os.chdir(self.dir)

def __exit__(self, exc_type, exc_val, exc_tb):
os.chdir(self.cwd)


def try_except(func):
# try-except function. Usage: @try_except decorator
def handler(*args, **kwargs):
Expand Down Expand Up @@ -203,6 +216,7 @@ def check_online():


@try_except
@WorkingDirectory(ROOT)
def check_git_status():
# Recommend 'git pull' if code is out of date
msg = ', for updates see https://github.com/ultralytics/yolov5'
Expand Down