Created
October 8, 2018 05:46
-
-
Save RonnyPfannschmidt/b7cada5152e9c6c2d03568f2b1b01575 to your computer and use it in GitHub Desktop.
Spread-Branch.ipynb
This file contains hidden or 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
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from typing import Optional, List\n", | |
| "import git\n", | |
| "repo = git.Repo(\".\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def target_and_commits(repo: git.Repo, branch : Optional[git.Head] = None):\n", | |
| " branch = branch or repo.active_branch\n", | |
| " return branch, list(repo.iter_commits(f'master..{branch.name}'))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def create_picks(repo: git.Repo, branch: Optional[git.Head] = None, commits: Optional[List[git.Commit]] = None):\n", | |
| " if commits is None:\n", | |
| " branch, commits = target_and_commits(repo)\n", | |
| " try:\n", | |
| " for i, commit in enumerate(commits):\n", | |
| " print(i, commit)\n", | |
| " new_head = repo.create_head(f\"{branch.name}-{i}\", 'master')\n", | |
| " new_head.checkout()\n", | |
| " repo.git.cherry_pick(commit)\n", | |
| " finally:\n", | |
| " branch.checkout()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "0 88598a3682752ff751d978c41eb0309545ade1eb\n", | |
| "1 9f2ea5f99917ee832d4a55097e5d5be9b9a96a44\n", | |
| "2 bf93e27afb492565a884d9632f21538bbcb7daca\n", | |
| "3 06432c4ec41792938964978727f939da43ebadc3\n", | |
| "4 6d67f43c3b3cba1908c39e0db8758302c11ed92f\n", | |
| "5 b54b4943748985490149676ce2b7b50cdf9e27b9\n", | |
| "6 196cf6b163375b068e098a0005f2a7d40987eb99\n", | |
| "7 81ce1e971f707ef32fbee8e4eecce7eddb1d592f\n", | |
| "8 a4c372689030b6853f1bbb0f17ebd6567763e4cf\n", | |
| "9 7d2ffb97c4b2b60f009a6ca5c61e1da12311c47e\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "create_picks(repo)\n" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.6.5" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment