Skip to content

Commit

Permalink
Separate the actual push from the checking that push is good in dev.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakert committed Nov 12, 2019
1 parent 957922c commit ea6fa22
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ def run_dangerously() -> None:
watch()
elif cmd == 'branch':
branch(args)
elif cmd == 'push':
push()
elif cmd == 'check':
check(args)
elif cmd in ('test', 'tests'):
test(args)
elif cmd == 'push':
push(args)
elif cmd in ('safe_push', 'safepush'):
safe_push(args)
elif cmd == 'release':
release(args)
else:
Expand Down Expand Up @@ -181,23 +183,26 @@ def reset_db() -> None:
import magic.database
magic.database.db().nuke_database()

def push(args: List[str]) -> None:
def safe_push(args: List[str]) -> None:
print('>>>> Stashing local changes')
label = 'dev-py-stash-at-' + str(time.time())
subprocess.check_call(['git', 'stash', 'save', label])
print('>>>> Rebasing branch on Master')
subprocess.check_call(['git', 'pull', 'origin', 'master', '--rebase'])
print('>>>> Checking')
test(args)
print('>>>> Pushing')
branch_name = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode()
subprocess.check_call(['git', 'push', '--set-upstream', 'origin', branch_name])
push()
print('>>>> Checking for stashed changes')
output = subprocess.check_output(['git', 'stash', 'list'], stderr=subprocess.STDOUT)
if label in str(output):
print('>>>> Popping stashed changes')
subprocess.call(['git', 'stash', 'pop'])

def push():
print('>>>> Pushing')
branch_name = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode()
subprocess.check_call(['git', 'push', '--set-upstream', 'origin', branch_name])

def pull_request(argv: List[str]) -> None:
print('>>>> Pull request')
subprocess.check_call(['hub', 'pull-request', *argv])
Expand Down Expand Up @@ -269,7 +274,7 @@ def test(args: List[str]) -> None:
unit(args)

def release(args: List[str]) -> None:
push(args)
safe_push(args)
pull_request(args)

def find_files(needle: str = '', file_extension: str = '') -> List[str]:
Expand Down

0 comments on commit ea6fa22

Please sign in to comment.