Compare commits
No commits in common. "7fc5426cc86982a36581ecccb6888361c3a79375" and "e5c0187e315a57dde60c0d6c35e31d791e2e58e0" have entirely different histories.
7fc5426cc8
...
e5c0187e31
@ -4,6 +4,7 @@ repos:
|
||||
hooks:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-yaml
|
||||
- id: debug-statements
|
||||
- id: double-quote-string-fixer
|
||||
- id: name-tests-test
|
||||
|
19
LICENSE
19
LICENSE
@ -1,19 +0,0 @@
|
||||
Copyright (c) 2025 Adwaith-Rajesh
|
||||
|
||||
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.
|
88
README.md
88
README.md
@ -1,88 +0,0 @@
|
||||
# git-changes
|
||||
|
||||
I just want to manage my commit messages.
|
||||
|
||||
---
|
||||
|
||||
## Why?
|
||||
|
||||
i just want to keep track of the changes that I make. Instead of adding many changes at once and then writing a long commit message, I just want to add the each change with a message and then commit them.
|
||||
|
||||
---
|
||||
|
||||
## Installation
|
||||
|
||||
```console
|
||||
pip3 install git-changes
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
### Initializing
|
||||
|
||||
After installing run the below command in a **git repo**
|
||||
|
||||
```console
|
||||
gitc --init
|
||||
```
|
||||
|
||||
### Adding changes with messages
|
||||
|
||||
```console
|
||||
$ git addm file -m 'adding a new file' --type=fix
|
||||
[fix] adding a new file
|
||||
```
|
||||
|
||||
The `--type` is optional. The currently supported choices for `--type` are
|
||||
|
||||
```console
|
||||
$ git addm -help
|
||||
usage: gitc-add [-h] -m MESSAGE [--type {feat,fix,docs,style,refactor,perf,test,build,ci,chore,revert}]
|
||||
|
||||
options:
|
||||
-h, --help show this help message and exit
|
||||
-m MESSAGE, --message MESSAGE
|
||||
Message to add
|
||||
--type {feat,fix,docs,style,refactor,perf,test,build,ci,chore,revert}
|
||||
The type of the change
|
||||
```
|
||||
|
||||
|
||||
### Show Message
|
||||
|
||||
To list all the messages that will added to the next commit, run
|
||||
|
||||
```console
|
||||
$ git show-messages
|
||||
[fix] new hello file
|
||||
[fix] adding a new file
|
||||
[perf] fix some_function
|
||||
[refactor] change var name
|
||||
```
|
||||
|
||||
### Commit
|
||||
|
||||
In order to commit with all these message all you have to do is run.
|
||||
|
||||
```console
|
||||
$ git commit
|
||||
```
|
||||
This will open up commit message editor with all the set message for the current commit.
|
||||
|
||||

|
||||
|
||||
> NOTE: you cannot simply save and exit this file; since this is a template you have to make
|
||||
> some changes to it. I suggest adding a title that summarizes all these changes.
|
||||
|
||||
After a successful commit all the messages will be automatically removed.
|
||||
|
||||
```console
|
||||
$ git show-messages
|
||||
No commit messages yet!.. To add new message run
|
||||
git addm -m <message> [--type]
|
||||
|
||||
```
|
||||
|
||||
### Bye...
|
BIN
docs/image.png
BIN
docs/image.png
Binary file not shown.
Before Width: | Height: | Size: 53 KiB |
@ -1,18 +1,16 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import configparser
|
||||
import os
|
||||
import stat
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
GIT_DIR = Path('.git')
|
||||
GIT_COMMIT_MSG_FILE = GIT_DIR / 'current_message.txt'
|
||||
GIT_COMMIT_MSG_FILE_BK = GIT_DIR / 'current_message.txt.bk'
|
||||
GIT_POST_COMMIT_FILE = GIT_DIR / 'hooks/post-commit'
|
||||
GIT_CONFIG_FILE = GIT_DIR / 'config'
|
||||
|
||||
COMMIT_TYPES = [
|
||||
'feat',
|
||||
@ -26,7 +24,6 @@ COMMIT_TYPES = [
|
||||
'ci',
|
||||
'chore',
|
||||
'revert',
|
||||
'dev',
|
||||
]
|
||||
|
||||
|
||||
@ -37,28 +34,9 @@ def _write_post_commit_file() -> None:
|
||||
os.chmod(GIT_POST_COMMIT_FILE, os.stat(GIT_POST_COMMIT_FILE).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
||||
|
||||
|
||||
def _set_aliases() -> None:
|
||||
git_config = configparser.ConfigParser()
|
||||
git_config.read(GIT_CONFIG_FILE)
|
||||
|
||||
if not git_config.has_section('alias'):
|
||||
git_config.add_section('alias')
|
||||
git_config.set('alias', 'addm', '!gitc-add')
|
||||
git_config.set('alias', 'show-messages', '!gitc-show-messages')
|
||||
|
||||
if not git_config.has_section('commit'):
|
||||
git_config.add_section('commit')
|
||||
|
||||
git_config.set('commit', 'template', str(GIT_COMMIT_MSG_FILE))
|
||||
|
||||
with open(GIT_CONFIG_FILE, 'w') as f:
|
||||
git_config.write(f)
|
||||
|
||||
|
||||
def _init() -> None:
|
||||
GIT_COMMIT_MSG_FILE.touch()
|
||||
_write_post_commit_file()
|
||||
_set_aliases()
|
||||
|
||||
|
||||
def _add_msg_to_file(message: str, type: str) -> str:
|
||||
@ -71,41 +49,23 @@ def _add_msg_to_file(message: str, type: str) -> str:
|
||||
|
||||
def _print_commit_msg() -> None:
|
||||
with open(GIT_COMMIT_MSG_FILE, 'r') as f:
|
||||
print(f.read().strip() or 'No commit messages yet!.. To add new message run\ngit addm -m <message> [--type]')
|
||||
print(f.read().strip() or 'No commit messages yet!.. To add new message run\ngitc <message> [--type]')
|
||||
|
||||
|
||||
def _reset_commit_msg_file() -> None:
|
||||
GIT_COMMIT_MSG_FILE.write_text('')
|
||||
|
||||
|
||||
def _run_git_add(args: list[str]) -> int:
|
||||
git_add = subprocess.run(['git', 'add', *args])
|
||||
return git_add.returncode
|
||||
|
||||
|
||||
def git_add() -> int:
|
||||
add_parser = argparse.ArgumentParser()
|
||||
add_parser.add_argument('-m', '--message', required=True, help='Message to add')
|
||||
add_parser.add_argument('--type', choices=COMMIT_TYPES, default='dev', help='The type of the change')
|
||||
|
||||
args, rest = add_parser.parse_known_args()
|
||||
if args.message and (_run_git_add(rest) == 0):
|
||||
print(_add_msg_to_file(args.message, args.type))
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
def show_messages() -> int:
|
||||
_print_commit_msg()
|
||||
return 0
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('message', help='message for the change', nargs='?')
|
||||
|
||||
grp = parser.add_mutually_exclusive_group()
|
||||
grp.add_argument('--type', choices=COMMIT_TYPES, default='feat', help='The type of the change')
|
||||
grp.add_argument('--init', action='store_true', help='Initialize everything')
|
||||
grp.add_argument('--reset', action='store_true', help='Reset commit messages')
|
||||
grp.add_argument('--show-msg', action='store_true', help='Show the current commit message')
|
||||
grp.add_argument('--reset', action='store_true', help='reset commit messages')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@ -115,10 +75,19 @@ def main() -> int:
|
||||
|
||||
if args.init:
|
||||
_init()
|
||||
os.execvp('git', ('git', 'config', '--local', 'commit.template', GIT_COMMIT_MSG_FILE))
|
||||
|
||||
if args.show_msg:
|
||||
_print_commit_msg()
|
||||
return 0
|
||||
|
||||
if args.reset:
|
||||
_reset_commit_msg_file()
|
||||
return 0
|
||||
|
||||
_init()
|
||||
|
||||
if args.message:
|
||||
print(_add_msg_to_file(args.message, args.type))
|
||||
|
||||
return 0
|
||||
|
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "git-changes"
|
||||
version = "0.0.3"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
{name="Adwaith-Rajesh", email="me@adwaith.dev"}
|
||||
]
|
||||
@ -13,19 +13,17 @@ classifiers = [
|
||||
]
|
||||
license = "MIT"
|
||||
license-files = ["LICENSE"]
|
||||
dependencies = [
|
||||
"argcomplete>=3.6.2",
|
||||
]
|
||||
|
||||
|
||||
[project.scripts]
|
||||
gitc = "git_changes:main"
|
||||
gitc-add = "git_changes:git_add"
|
||||
gitc-show-messages = "git_changes:show_messages"
|
||||
|
||||
[build-system]
|
||||
requires = ["setuptools>=61.0"]
|
||||
|
||||
[tool.setuptools]
|
||||
py-modules = ["git_changes"]
|
||||
|
||||
# [tool.setuptools.packages.find]
|
||||
# exclude = ["test", "tests"]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user