-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some helpers for fixups in exercise branches
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |