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

check_git_status() Windows fix #2015

Merged
merged 7 commits into from
Jan 22, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Update general.py
  • Loading branch information
glenn-jocher committed Jan 22, 2021
commit 31fb3327689702eefc02c68cb2d4759ada3fd1a9
13 changes: 6 additions & 7 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,21 @@ def check_online():
def check_git_status():
# Recommend 'git pull' if code is out of date
print(colorstr('github: '), end='')
print('test 2 βœ…', end='')
print('test 1 ⚠', end='')
try:
assert Path('.git').exists(), 'skipping check (not a git repository)'
assert not Path('/workspace').exists(), 'skipping check (Docker image)' # not Path('/.dockerenv').exists()
assert check_online(), 'skipping check (offline)'

cmd = 'git fetch && git config --get remote.origin.url' # github repo url
url = subprocess.check_output(cmd, shell=True).decode('utf-8').rstrip()
branch = subprocess.check_output('git branch --show-current', shell=True).decode('utf-8').rstrip() # current
url = subprocess.check_output(cmd, shell=True).decode().rstrip()
branch = subprocess.check_output('git branch --show-current', shell=True).decode().rstrip() # current
n = int(subprocess.check_output(f'git rev-list {branch}..origin/master --count', shell=True)) # commits behind
if n > 0:
print(f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. "
f"Use 'git pull' to update or 'git clone {url}' to download latest.")
s = f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \
f"Use 'git pull' to update or 'git clone {url}' to download latest."
else:
print(f'up to date with {url} βœ…')
s = f'up to date with {url} βœ…'
print(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s)
except Exception as e:
print(e)

Expand Down