Last active
December 1, 2025 04:40
-
-
Save Mause/539aa04a538c03128bf5a191d6029e94 to your computer and use it in GitHub Desktop.
git-pick-me
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
| *.egg-info | |
| __pycache__/ |
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
| 3.12 |
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
| #!/usr/bin/env python3 | |
| import re | |
| from os.path import basename, expanduser | |
| from subprocess import CalledProcessError, check_call, check_output | |
| import rich_click as click | |
| def validate_branch(ctx: click.Context, param: click.Parameter, branch: str) -> str: | |
| if " " in branch: | |
| raise click.BadParameter("Branch name cannot contain spaces") | |
| return branch | |
| def validate_commit_hash( | |
| ctx: click.Context, param: click.Parameter, commits: tuple[str, ...] | |
| ) -> tuple[str, ...]: | |
| for commit in commits: | |
| if not re.match("^[a-z0-9]+$", commit): | |
| raise click.BadParameter("Commit should be alphanumeric") | |
| return commits | |
| @click.command() | |
| @click.argument( | |
| "branch", | |
| help="The branch to create and cherry-pick into.", | |
| callback=validate_branch, | |
| ) | |
| @click.argument( | |
| "commits", | |
| nargs=-1, | |
| required=True, | |
| help="The commit hashes to cherry-pick.", | |
| callback=validate_commit_hash, | |
| ) | |
| def main(branch: str, commits: list[str]) -> None: | |
| "Cherry-pick a commit to a new branch." | |
| new_branch = branch | |
| commit_hashes = list(commits) | |
| assert commit_hashes | |
| default_branch = ( | |
| check_output( | |
| ["git", "symbolic-ref", "refs/remotes/origin/HEAD", "--short"], text=True | |
| ) | |
| .strip() | |
| .split("/", 1)[1] | |
| ) | |
| top_level = basename( | |
| check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip() | |
| ) | |
| new_dir = expanduser(f"~/{top_level}-{new_branch}") | |
| try: | |
| check_call( | |
| ["git", "worktree", "add", "-b", new_branch, new_dir, default_branch] | |
| ) | |
| check_call(["git", "town", "set-parent", default_branch], cwd=new_dir) | |
| check_call(["git", "cherry-pick", *commit_hashes], cwd=new_dir) | |
| except CalledProcessError as e: | |
| raise click.ClickException("Failed to call git") from e | |
| if __name__ == "__main__": | |
| main() |
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
| The MIT License (MIT) | |
| Copyright (c) 2025 Elliana May <[email protected]> | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is | |
| furnished to do so, subject to the following conditions: | |
| The above copyright notice and this permission notice shall be included in | |
| all copies or substantial portions of the Software. | |
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
| THE SOFTWARE. |
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
| [project] | |
| name = "git_pick_me" | |
| version = "0.1.1" | |
| description = "A tool to help you pick the best git commits." | |
| requires-python = ">=3.10" | |
| license = "MIT" | |
| license-files = ["LICENSE"] | |
| authors = [{ name = "Elliana May", email = "[email protected]" }] | |
| dependencies = [ | |
| "rich-click>=1.9.4", | |
| ] | |
| [project.scripts] | |
| git-pick-me = "git_pick_me:main" | |
| [build-system] | |
| requires = ["flit_core >=3.11,<4"] | |
| build-backend = "flit_core.buildapi" | |
| [tool.ruff.lint] | |
| select = ["I", "ANN", "F", "E"] | |
| [[tool.uv.index]] | |
| name = "pypi" | |
| url = "https://pypi.org/simple" | |
| default = true |
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
| version = 1 | |
| revision = 3 | |
| requires-python = ">=3.10" | |
| [[package]] | |
| name = "click" | |
| version = "8.3.0" | |
| source = { registry = "https://pypi.org/simple" } | |
| dependencies = [ | |
| { name = "colorama", marker = "sys_platform == 'win32'" }, | |
| ] | |
| sdist = { url = "https://files.pythonhosted.org/packages/46/61/de6cd827efad202d7057d93e0fed9294b96952e188f7384832791c7b2254/click-8.3.0.tar.gz", hash = "sha256:e7b8232224eba16f4ebe410c25ced9f7875cb5f3263ffc93cc3e8da705e229c4", size = 276943, upload-time = "2025-09-18T17:32:23.696Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/db/d3/9dcc0f5797f070ec8edf30fbadfb200e71d9db6b84d211e3b2085a7589a0/click-8.3.0-py3-none-any.whl", hash = "sha256:9b9f285302c6e3064f4330c05f05b81945b2a39544279343e6e7c5f27a9baddc", size = 107295, upload-time = "2025-09-18T17:32:22.42Z" }, | |
| ] | |
| [[package]] | |
| name = "colorama" | |
| version = "0.4.6" | |
| source = { registry = "https://pypi.org/simple" } | |
| sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" }, | |
| ] | |
| [[package]] | |
| name = "git-pick-me" | |
| version = "0.1.1" | |
| source = { editable = "." } | |
| dependencies = [ | |
| { name = "rich-click" }, | |
| ] | |
| [package.metadata] | |
| requires-dist = [{ name = "rich-click", specifier = ">=1.9.4" }] | |
| [[package]] | |
| name = "markdown-it-py" | |
| version = "4.0.0" | |
| source = { registry = "https://pypi.org/simple" } | |
| dependencies = [ | |
| { name = "mdurl" }, | |
| ] | |
| sdist = { url = "https://files.pythonhosted.org/packages/5b/f5/4ec618ed16cc4f8fb3b701563655a69816155e79e24a17b651541804721d/markdown_it_py-4.0.0.tar.gz", hash = "sha256:cb0a2b4aa34f932c007117b194e945bd74e0ec24133ceb5bac59009cda1cb9f3", size = 73070, upload-time = "2025-08-11T12:57:52.854Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/94/54/e7d793b573f298e1c9013b8c4dade17d481164aa517d1d7148619c2cedbf/markdown_it_py-4.0.0-py3-none-any.whl", hash = "sha256:87327c59b172c5011896038353a81343b6754500a08cd7a4973bb48c6d578147", size = 87321, upload-time = "2025-08-11T12:57:51.923Z" }, | |
| ] | |
| [[package]] | |
| name = "mdurl" | |
| version = "0.1.2" | |
| source = { registry = "https://pypi.org/simple" } | |
| sdist = { url = "https://files.pythonhosted.org/packages/d6/54/cfe61301667036ec958cb99bd3efefba235e65cdeb9c84d24a8293ba1d90/mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba", size = 8729, upload-time = "2022-08-14T12:40:10.846Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" }, | |
| ] | |
| [[package]] | |
| name = "pygments" | |
| version = "2.19.2" | |
| source = { registry = "https://pypi.org/simple" } | |
| sdist = { url = "https://files.pythonhosted.org/packages/b0/77/a5b8c569bf593b0140bde72ea885a803b82086995367bf2037de0159d924/pygments-2.19.2.tar.gz", hash = "sha256:636cb2477cec7f8952536970bc533bc43743542f70392ae026374600add5b887", size = 4968631, upload-time = "2025-06-21T13:39:12.283Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/c7/21/705964c7812476f378728bdf590ca4b771ec72385c533964653c68e86bdc/pygments-2.19.2-py3-none-any.whl", hash = "sha256:86540386c03d588bb81d44bc3928634ff26449851e99741617ecb9037ee5ec0b", size = 1225217, upload-time = "2025-06-21T13:39:07.939Z" }, | |
| ] | |
| [[package]] | |
| name = "rich" | |
| version = "14.2.0" | |
| source = { registry = "https://pypi.org/simple" } | |
| dependencies = [ | |
| { name = "markdown-it-py" }, | |
| { name = "pygments" }, | |
| ] | |
| sdist = { url = "https://files.pythonhosted.org/packages/fb/d2/8920e102050a0de7bfabeb4c4614a49248cf8d5d7a8d01885fbb24dc767a/rich-14.2.0.tar.gz", hash = "sha256:73ff50c7c0c1c77c8243079283f4edb376f0f6442433aecb8ce7e6d0b92d1fe4", size = 219990, upload-time = "2025-10-09T14:16:53.064Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/25/7a/b0178788f8dc6cafce37a212c99565fa1fe7872c70c6c9c1e1a372d9d88f/rich-14.2.0-py3-none-any.whl", hash = "sha256:76bc51fe2e57d2b1be1f96c524b890b816e334ab4c1e45888799bfaab0021edd", size = 243393, upload-time = "2025-10-09T14:16:51.245Z" }, | |
| ] | |
| [[package]] | |
| name = "rich-click" | |
| version = "1.9.4" | |
| source = { registry = "https://pypi.org/simple" } | |
| dependencies = [ | |
| { name = "click" }, | |
| { name = "colorama", marker = "sys_platform == 'win32'" }, | |
| { name = "rich" }, | |
| { name = "typing-extensions", marker = "python_full_version < '3.11'" }, | |
| ] | |
| sdist = { url = "https://files.pythonhosted.org/packages/bf/d8/f2c1b7e9a645ba40f756d7a5b195fc104729bc6b19061ba3ab385f342931/rich_click-1.9.4.tar.gz", hash = "sha256:af73dc68e85f3bebb80ce302a642b9fe3b65f3df0ceb42eb9a27c467c1b678c8", size = 73632, upload-time = "2025-10-25T01:08:49.142Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/5b/6a/1f03adcb3cc7beb6f63aecc21565e9d515ccee653187fc4619cd0b42713b/rich_click-1.9.4-py3-none-any.whl", hash = "sha256:d70f39938bcecaf5543e8750828cbea94ef51853f7d0e174cda1e10543767389", size = 70245, upload-time = "2025-10-25T01:08:47.939Z" }, | |
| ] | |
| [[package]] | |
| name = "typing-extensions" | |
| version = "4.15.0" | |
| source = { registry = "https://pypi.org/simple" } | |
| sdist = { url = "https://files.pythonhosted.org/packages/72/94/1a15dd82efb362ac84269196e94cf00f187f7ed21c242792a923cdb1c61f/typing_extensions-4.15.0.tar.gz", hash = "sha256:0cea48d173cc12fa28ecabc3b837ea3cf6f38c6d1136f85cbaaf598984861466", size = 109391, upload-time = "2025-08-25T13:49:26.313Z" } | |
| wheels = [ | |
| { url = "https://files.pythonhosted.org/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl", hash = "sha256:f0fa19c6845758ab08074a0cfa8b7aecb71c999ca73d62883bc25cc018c4e548", size = 44614, upload-time = "2025-08-25T13:49:24.86Z" }, | |
| ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment