Raise custom exception for NoUpstreamBranch.

Originally I merged these two commands to reduce the number of
subprocess spawns, but I found that the majority of execution time
was git status anyway. These ones are fairly cheap.
This commit is contained in:
voussoir 2020-02-19 12:01:13 -08:00
parent d0c5d8ff43
commit e557c1a64f

View file

@ -16,6 +16,9 @@ GIT = winwhich.which('git')
# A file4 # A file4
# ?? file3 # ?? file3
class NoUpstreamBranch(Exception):
pass
def check_output(command): def check_output(command):
output = subprocess.check_output(command, stderr=subprocess.STDOUT) output = subprocess.check_output(command, stderr=subprocess.STDOUT)
return output return output
@ -46,9 +49,16 @@ def checkup_committed():
return (committed, details) return (committed, details)
def checkup_pushed(): def checkup_pushed():
command = [GIT, 'rev-parse', '@', '@{u}'] command = [GIT, 'rev-parse', '@']
output = check_output(command) my_head = check_output(command).strip().decode()
(my_head, remote_head) = output.strip().decode().splitlines()
command = [GIT, 'rev-parse', '@{u}']
try:
remote_head = check_output(command).strip().decode()
except subprocess.CalledProcessError as exc:
command = [GIT, 'rev-parse', '--abbrev-ref', 'HEAD']
current_branch = check_output(command).strip().decode()
raise NoUpstreamBranch(current_branch)
if my_head == remote_head: if my_head == remote_head:
to_push = 0 to_push = 0