From d6f20c4da8ab0b6e948ac87b33cbf50c5aa6e22a Mon Sep 17 00:00:00 2001 From: Amir Pourmand Date: Sun, 24 Jul 2022 00:35:29 +0430 Subject: [PATCH 1/5] Add remote ultralytics and check git status with that --- utils/general.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index b049ce469a71..c52d58c9c9be 100755 --- a/utils/general.py +++ b/utils/general.py @@ -312,10 +312,21 @@ def check_git_status(): assert not is_docker(), s + 'skipping check (Docker image)' + msg assert check_online(), s + 'skipping check (offline)' + msg - cmd = 'git fetch && git config --get remote.origin.url' + result = check_output('git remote -v', shell=True).decode() + ultralytics_repo = 'https://github.com/ultralytics/yolov5' + remote_name = 'ultralytics' + for line in result.split('\n'): + if ultralytics_repo in line: + remote_name, _ = line.split('\t') + break + else: + check_output(f'git remote add {remote_name} {ultralytics_repo}', shell=True) + check_output(f'git fetch {remote_name}', shell=True) + + cmd = f'git fetch && git config --get remote.{remote_name}.url' url = check_output(cmd, shell=True, timeout=5).decode().strip().rstrip('.git') # git fetch branch = check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out - n = int(check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind + n = int(check_output(f'git rev-list {branch}..{remote_name}/master --count', shell=True)) # commits behind if n > 0: s += f"⚠️ YOLOv5 is out of date by {n} commit{'s' * (n > 1)}. Use `git pull` or `git clone {url}` to update." else: From 9e7ec7d9650a5fa21c04b67d053a908b4ef7289c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 31 Jul 2022 04:04:36 +0200 Subject: [PATCH 2/5] Simplify --- utils/general.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index 07b69a5cff99..fff686de79fc 100755 --- a/utils/general.py +++ b/utils/general.py @@ -310,23 +310,22 @@ def git_describe(path=ROOT): # path must be a directory @try_except @WorkingDirectory(ROOT) -def check_git_status(): +def check_git_status(repo='https://github.com/ultralytics/yolov5'): # Recommend 'git pull' if code is out of date - msg = ', for updates see https://github.com/ultralytics/yolov5' + msg = f', for updates see {repo}' s = colorstr('github: ') # string assert Path('.git').exists(), s + 'skipping check (not a git repository)' + msg assert not is_docker(), s + 'skipping check (Docker image)' + msg assert check_online(), s + 'skipping check (offline)' + msg result = check_output('git remote -v', shell=True).decode() - ultralytics_repo = 'https://github.com/ultralytics/yolov5' remote_name = 'ultralytics' for line in result.split('\n'): - if ultralytics_repo in line: + if repo in line: remote_name, _ = line.split('\t') break else: - check_output(f'git remote add {remote_name} {ultralytics_repo}', shell=True) + check_output(f'git remote add {remote_name} {repo}', shell=True) check_output(f'git fetch {remote_name}', shell=True) cmd = f'git fetch && git config --get remote.{remote_name}.url' From b5f4bd1d9bc989380091f933058c8429ee6aa3f8 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 31 Jul 2022 17:02:26 +0200 Subject: [PATCH 3/5] Update general.py --- utils/general.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/utils/general.py b/utils/general.py index fff686de79fc..276958c5035a 100755 --- a/utils/general.py +++ b/utils/general.py @@ -310,30 +310,29 @@ def git_describe(path=ROOT): # path must be a directory @try_except @WorkingDirectory(ROOT) -def check_git_status(repo='https://github.com/ultralytics/yolov5'): - # Recommend 'git pull' if code is out of date - msg = f', for updates see {repo}' +def check_git_status(repo='ultralytics/yolov5'): + # YOLOv5 status check, recommend 'git pull' if code is out of date + url = f'https://github.com/{repo}' + msg = f', for updates see {url}' s = colorstr('github: ') # string assert Path('.git').exists(), s + 'skipping check (not a git repository)' + msg assert not is_docker(), s + 'skipping check (Docker image)' + msg assert check_online(), s + 'skipping check (offline)' + msg - result = check_output('git remote -v', shell=True).decode() - remote_name = 'ultralytics' - for line in result.split('\n'): - if repo in line: - remote_name, _ = line.split('\t') - break + s = re.split(pattern=r'\s', string=check_output('git remote -v', shell=True).decode()) + matches = [repo in x for x in s] + if any(matches): + remote = s[matches.index(True) - 1] else: - check_output(f'git remote add {remote_name} {repo}', shell=True) - check_output(f'git fetch {remote_name}', shell=True) - - cmd = f'git fetch && git config --get remote.{remote_name}.url' + remote = 'ultralytics' + check_output(f'git remote add {remote} {url}', shell=True) + cmd = f'git fetch {remote} && git config --get remote.{remote}.url' url = check_output(cmd, shell=True, timeout=5).decode().strip().rstrip('.git') # git fetch branch = check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out - n = int(check_output(f'git rev-list {branch}..{remote_name}/master --count', shell=True)) # commits behind + n = int(check_output(f'git rev-list {branch}..{remote}/master --count', shell=True)) # commits behind if n > 0: - s += f"⚠️ YOLOv5 is out of date by {n} commit{'s' * (n > 1)}. Use `git pull` or `git clone {url}` to update." + pull = 'git pull' if remote == 'origin' else f'git pull {remote} master' + s += f"⚠️ YOLOv5 is out of date by {n} commit{'s' * (n > 1)}. Use `{pull}` or `git clone {url}` to update." else: s += f'up to date with {url} ✅' LOGGER.info(emojis(s)) # emoji-safe From 90bde61fb6e1b32c19932480e9b1e4ecc4350692 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 31 Jul 2022 17:04:14 +0200 Subject: [PATCH 4/5] Update general.py --- utils/general.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 276958c5035a..1f43593f2ae6 100755 --- a/utils/general.py +++ b/utils/general.py @@ -326,8 +326,7 @@ def check_git_status(repo='ultralytics/yolov5'): else: remote = 'ultralytics' check_output(f'git remote add {remote} {url}', shell=True) - cmd = f'git fetch {remote} && git config --get remote.{remote}.url' - url = check_output(cmd, shell=True, timeout=5).decode().strip().rstrip('.git') # git fetch + check_output(f'git fetch {remote}', shell=True, timeout=5) # git fetch branch = check_output('git rev-parse --abbrev-ref HEAD', shell=True).decode().strip() # checked out n = int(check_output(f'git rev-list {branch}..{remote}/master --count', shell=True)) # commits behind if n > 0: From a1d8efde2cdd6376173876aee195cad59b621ace Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 31 Jul 2022 17:09:10 +0200 Subject: [PATCH 5/5] s fix --- utils/general.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/general.py b/utils/general.py index 1f43593f2ae6..bab0a5d9ab34 100755 --- a/utils/general.py +++ b/utils/general.py @@ -319,10 +319,10 @@ def check_git_status(repo='ultralytics/yolov5'): assert not is_docker(), s + 'skipping check (Docker image)' + msg assert check_online(), s + 'skipping check (offline)' + msg - s = re.split(pattern=r'\s', string=check_output('git remote -v', shell=True).decode()) - matches = [repo in x for x in s] + splits = re.split(pattern=r'\s', string=check_output('git remote -v', shell=True).decode()) + matches = [repo in s for s in splits] if any(matches): - remote = s[matches.index(True) - 1] + remote = splits[matches.index(True) - 1] else: remote = 'ultralytics' check_output(f'git remote add {remote} {url}', shell=True)