Skip to content

Commit

Permalink
some helpers for fixups in exercise branches
Browse files Browse the repository at this point in the history
  • Loading branch information
hjwp committed Jul 1, 2019
1 parent 43267b1 commit 696ff72
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
29 changes: 29 additions & 0 deletions reset-exercise-branches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python
import subprocess
from pathlib import Path
from chapters import CHAPTERS


def run(cmds):
print(' '.join(cmds))
p = subprocess.run(
cmds,
cwd=Path(__file__).parent / 'code',
capture_output=True,
)
if p.returncode:
raise Exception(p.stderr.decode())
output = p.stdout.decode()
print(output)
return output


all_branches = run(['git', 'branch', '-a'],)

for chapter in CHAPTERS:
exercise_chapter = f'{chapter}_exercise'
if exercise_chapter not in all_branches:
continue
run(['git', 'checkout', exercise_chapter])
run(['git', 'reset', '--hard', f'origin/{exercise_chapter}'])
run(['git', 'checkout', 'master'])
37 changes: 37 additions & 0 deletions update-exercise-branches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
import sys
import subprocess
from pathlib import Path


def run(cmds):
print(' '.join(cmds))
p = subprocess.run(
cmds,
cwd=Path(__file__).parent / 'code',
capture_output=True,
)
if p.returncode:
raise Exception(p.stderr.decode())
output = p.stdout.decode()
print(output)
return output

all_branches = run(['git', 'branch', '-a'],)


def main(chapter):
exercise_chapter = f'{chapter}_exercise'
assert exercise_chapter in all_branches

run(['git', 'checkout', exercise_chapter])
commits = list(reversed(run([
'git', 'log', '--pretty=%h',
f'{exercise_chapter}^{{/{chapter}_ends}}..{exercise_chapter}',
]).split()))
run(['git', 'reset', '--hard', chapter])
run(['git', 'cherry-pick', *commits])

if __name__ == '__main__':
chapter = sys.argv[1]
main(chapter)

0 comments on commit 696ff72

Please sign in to comment.