check_git_status() Windows fix (#2015)
Browse files* check_git_status() Windows fix
* Update general.py
* Update general.py
* Update general.py
* Update general.py
* Update general.py
* Update general.py
- utils/general.py +8 -6
utils/general.py
CHANGED
@@ -4,6 +4,7 @@ import glob
|
|
4 |
import logging
|
5 |
import math
|
6 |
import os
|
|
|
7 |
import random
|
8 |
import re
|
9 |
import subprocess
|
@@ -65,14 +66,15 @@ def check_git_status():
|
|
65 |
assert check_online(), 'skipping check (offline)'
|
66 |
|
67 |
cmd = 'git fetch && git config --get remote.origin.url' # github repo url
|
68 |
-
url = subprocess.check_output(cmd, shell=True).decode()
|
69 |
-
|
70 |
-
n = int(subprocess.check_output(
|
71 |
if n > 0:
|
72 |
-
|
73 |
-
|
74 |
else:
|
75 |
-
|
|
|
76 |
except Exception as e:
|
77 |
print(e)
|
78 |
|
|
|
4 |
import logging
|
5 |
import math
|
6 |
import os
|
7 |
+
import platform
|
8 |
import random
|
9 |
import re
|
10 |
import subprocess
|
|
|
66 |
assert check_online(), 'skipping check (offline)'
|
67 |
|
68 |
cmd = 'git fetch && git config --get remote.origin.url' # github repo url
|
69 |
+
url = subprocess.check_output(cmd, shell=True).decode().rstrip()
|
70 |
+
branch = subprocess.check_output('git branch --show-current', shell=True).decode().rstrip() # current
|
71 |
+
n = int(subprocess.check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind
|
72 |
if n > 0:
|
73 |
+
s = f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \
|
74 |
+
f"Use 'git pull' to update or 'git clone {url}' to download latest."
|
75 |
else:
|
76 |
+
s = f'up to date with {url} ✅'
|
77 |
+
print(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s)
|
78 |
except Exception as e:
|
79 |
print(e)
|
80 |
|