mirror of
https://codeberg.org/james-smith-za/git-tidy-python.git
synced 2026-01-15 19:29:25 +02:00
Compare commits
No commits in common. "263882fd427a6f9a4bdfc4d409a4ffdcc2b165db" and "a0ce83fb7266d38c4923de031e3708f4ad8a9ae1" have entirely different histories.
263882fd42
...
a0ce83fb72
3 changed files with 12 additions and 70 deletions
18
README.md
18
README.md
|
|
@ -14,29 +14,20 @@ git fetch --all --prune # prune is to delete unnecessary remote refs
|
||||||
git merge origin/main main --ff-only
|
git merge origin/main main --ff-only
|
||||||
git branch --merged | grep -v main | xargs git branch -d
|
git branch --merged | grep -v main | xargs git branch -d
|
||||||
```
|
```
|
||||||
|
|
||||||
with some extra convenience and (I hope) safety features.
|
with some extra convenience and (I hope) safety features.
|
||||||
|
|
||||||
## Using
|
## Using
|
||||||
|
|
||||||
The actual script is named `git_tidy.py`. After cloning, you can copy (or symlink)
|
The actual script is named `git-tidy`. After cloning, you can copy (or symlink)
|
||||||
it to somewhere on your path (e.g. `~/bin/git-tidy`).
|
it to somewhere on your path (I use `~/bin/`).
|
||||||
|
|
||||||
Alternatively, you can use a package manager such as
|
|
||||||
[`uv`](https://docs.astral.sh/uv/concepts/tools/). My personal preference is
|
|
||||||
this, as `uv` will place the tool on the PATH for you and you can get straight
|
|
||||||
to using it.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
uv tool install https://codeberg.org/james-smith-za/git-tidy-python.git
|
|
||||||
```
|
|
||||||
|
|
||||||
Then when you `cd` to your git repository, you can type
|
Then when you `cd` to your git repository, you can type
|
||||||
```bash
|
```bash
|
||||||
git tidy
|
git tidy
|
||||||
```
|
```
|
||||||
and it'll do its thing! Only the Python standard library is used, no additional
|
and it'll do its thing! Only the Python standard library is used, no additional
|
||||||
packages are required. I have tested (manually) with Python 3.8 through to
|
packages are required.
|
||||||
3.13, so I would imagine that future versions should work just fine.
|
|
||||||
|
|
||||||
## Background
|
## Background
|
||||||
|
|
||||||
|
|
@ -45,6 +36,7 @@ redo this program in Go at some point, which will make it easier to distribute
|
||||||
for people who don't have Python installed by default (i.e. Windows users). But
|
for people who don't have Python installed by default (i.e. Windows users). But
|
||||||
I'm not sure when I'll get to that.
|
I'm not sure when I'll get to that.
|
||||||
|
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
I'd like to actually get a set of unit-tests in place, but I'm not sure how to
|
I'd like to actually get a set of unit-tests in place, but I'm not sure how to
|
||||||
|
|
|
||||||
15
git_tidy.py → git-tidy
Normal file → Executable file
15
git_tidy.py → git-tidy
Normal file → Executable file
|
|
@ -1,26 +1,21 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Copyright 2023-2025 James Smith
|
|
||||||
# git-tidy is free software: you can redistribute it and/or modify it under the terms of the GNU
|
# git-tidy is free software: you can redistribute it and/or modify it under the terms of the GNU
|
||||||
# General Public License as published by the Free Software Foundation, either version 3 of the
|
# General Public License as published by the Free Software Foundation, either version 3 of the
|
||||||
# License, or (at your option) any later version.
|
# License, or (at your option) any later version.
|
||||||
|
|
||||||
# git-tidy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
# git-tidy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||||
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
# the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||||
# Public License for more details.
|
# Public License for more details.
|
||||||
|
|
||||||
# You should have received a copy of the GNU General Public License along with git-tidy. If not, see
|
# You should have received a copy of the GNU General Public License along with git-tidy. If not, see
|
||||||
# <https://www.gnu.org/licenses/>.
|
# <https://www.gnu.org/licenses/>.
|
||||||
"""git-tidy utility."""
|
"""git-tidy utility."""
|
||||||
|
|
||||||
import argparse
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from typing import List, Tuple, Union
|
from typing import List, Tuple, Union
|
||||||
|
|
||||||
try:
|
|
||||||
from importlib.metadata import version
|
|
||||||
except ImportError:
|
|
||||||
# Python < 3.8
|
|
||||||
from importlib_metadata import version
|
|
||||||
|
|
||||||
common_default_branches = [
|
common_default_branches = [
|
||||||
"main",
|
"main",
|
||||||
"master",
|
"master",
|
||||||
|
|
@ -132,10 +127,6 @@ def get_default_branch() -> str:
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main function."""
|
"""Main function."""
|
||||||
parser = argparse.ArgumentParser(description="A time-saving device for a developer using git.")
|
|
||||||
parser.add_argument("--version", action="version", version=f"git-tidy {version('git-tidy-python')}")
|
|
||||||
parser.parse_args()
|
|
||||||
|
|
||||||
default_branch = get_default_branch()
|
default_branch = get_default_branch()
|
||||||
print(f"Switching to {default_branch}")
|
print(f"Switching to {default_branch}")
|
||||||
run(["git", "checkout", default_branch])
|
run(["git", "checkout", default_branch])
|
||||||
|
|
@ -1,54 +1,13 @@
|
||||||
[build-system]
|
[tool.black]
|
||||||
requires = ["setuptools>=45", "setuptools-scm[toml]>=6.2", "wheel"]
|
|
||||||
build-backend = "setuptools.build_meta"
|
|
||||||
|
|
||||||
[project]
|
|
||||||
name = "git-tidy-python"
|
|
||||||
dynamic = ["version"]
|
|
||||||
description = "A time-saving device for a developer using git."
|
|
||||||
authors = [
|
|
||||||
{name = "James Smith"}
|
|
||||||
]
|
|
||||||
readme = "README.md"
|
|
||||||
license = {text = "GPL-3.0-or-later"}
|
|
||||||
requires-python = ">=3.8"
|
|
||||||
dependencies = []
|
|
||||||
keywords = ["git", "cli", "developer-tools", "automation", "branch-management"]
|
|
||||||
classifiers = [
|
|
||||||
"Development Status :: 4 - Beta",
|
|
||||||
"Environment :: Console",
|
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
|
|
||||||
"Operating System :: OS Independent",
|
|
||||||
"Programming Language :: Python :: 3",
|
|
||||||
"Programming Language :: Python :: 3.6",
|
|
||||||
"Programming Language :: Python :: 3.7",
|
|
||||||
"Programming Language :: Python :: 3.8",
|
|
||||||
"Programming Language :: Python :: 3.9",
|
|
||||||
"Programming Language :: Python :: 3.10",
|
|
||||||
"Programming Language :: Python :: 3.11",
|
|
||||||
"Programming Language :: Python :: 3.12",
|
|
||||||
"Topic :: Software Development :: Version Control :: Git",
|
|
||||||
"Topic :: Utilities"
|
|
||||||
]
|
|
||||||
|
|
||||||
[project.scripts]
|
|
||||||
git-tidy = "git_tidy:main"
|
|
||||||
|
|
||||||
[tool.setuptools]
|
|
||||||
py-modules = ["git_tidy"]
|
|
||||||
|
|
||||||
[tool.ruff]
|
|
||||||
line-length = 120
|
line-length = 120
|
||||||
|
include = '\.pyi?$'
|
||||||
exclude ='''
|
exclude ='''
|
||||||
/(
|
/(
|
||||||
| \.git
|
| \.git
|
||||||
| \.mypy_cache
|
| \.mypy_cache
|
||||||
)/
|
)/
|
||||||
'''
|
'''
|
||||||
|
|
||||||
[tool.isort]
|
[tool.isort]
|
||||||
profile = "black"
|
profile = "black"
|
||||||
line_length = 120
|
line_length = 120
|
||||||
|
|
||||||
[tool.setuptools_scm]
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue