Compare commits

...

10 Commits

Author SHA1 Message Date
7fc5426cc8
added dev type
make dev default, indacates a change for a project that is currently in dev
version bump
2025-08-23 21:44:01 +05:30
4c32582ad5
version bump 2025-08-19 22:35:11 +05:30
9e71ba8814
Added MIT license #1 2025-08-19 22:34:24 +05:30
bd77cd3676
fix #2
[chore] removed onedev buildscpec
[fix] use subprocess instead of execvp

using execvp means that we have to add the messages before git-add
switching to subprocess allows us to check whether git-add was successfull
and if it was, then add the message.

ondev buildspec was removed as we have switched to gittea
2025-08-19 22:30:59 +05:30
376f5ac101
Add image 2025-08-09 23:05:22 +05:30
ac0fc26960
updated readme to include add and show message 2025-08-09 23:04:25 +05:30
e6a3e9f16e
update the add command 2025-08-09 23:04:02 +05:30
8f79123953
set aliases for adding and showing messages 2025-08-09 22:38:49 +05:30
f4dcc3ddd4
Added README 2025-08-09 16:49:10 +05:30
829999cc60
build file
[feat] added build file for onedev
[fix] remove check yaml
2025-08-09 16:18:36 +05:30
6 changed files with 160 additions and 21 deletions

View File

@ -4,7 +4,6 @@ repos:
hooks: hooks:
- id: trailing-whitespace - id: trailing-whitespace
- id: end-of-file-fixer - id: end-of-file-fixer
- id: check-yaml
- id: debug-statements - id: debug-statements
- id: double-quote-string-fixer - id: double-quote-string-fixer
- id: name-tests-test - id: name-tests-test

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
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 Normal file
View File

@ -0,0 +1,88 @@
# 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.
![Terminal image](docs/image.png)
> 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 Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -1,16 +1,18 @@
from __future__ import annotations from __future__ import annotations
import argparse import argparse
import configparser
import os import os
import stat import stat
import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
GIT_DIR = Path('.git') GIT_DIR = Path('.git')
GIT_COMMIT_MSG_FILE = GIT_DIR / 'current_message.txt' 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_POST_COMMIT_FILE = GIT_DIR / 'hooks/post-commit'
GIT_CONFIG_FILE = GIT_DIR / 'config'
COMMIT_TYPES = [ COMMIT_TYPES = [
'feat', 'feat',
@ -24,6 +26,7 @@ COMMIT_TYPES = [
'ci', 'ci',
'chore', 'chore',
'revert', 'revert',
'dev',
] ]
@ -34,9 +37,28 @@ 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) 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: def _init() -> None:
GIT_COMMIT_MSG_FILE.touch() GIT_COMMIT_MSG_FILE.touch()
_write_post_commit_file() _write_post_commit_file()
_set_aliases()
def _add_msg_to_file(message: str, type: str) -> str: def _add_msg_to_file(message: str, type: str) -> str:
@ -49,23 +71,41 @@ def _add_msg_to_file(message: str, type: str) -> str:
def _print_commit_msg() -> None: def _print_commit_msg() -> None:
with open(GIT_COMMIT_MSG_FILE, 'r') as f: with open(GIT_COMMIT_MSG_FILE, 'r') as f:
print(f.read().strip() or 'No commit messages yet!.. To add new message run\ngitc <message> [--type]') print(f.read().strip() or 'No commit messages yet!.. To add new message run\ngit addm -m <message> [--type]')
def _reset_commit_msg_file() -> None: def _reset_commit_msg_file() -> None:
GIT_COMMIT_MSG_FILE.write_text('') 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: def main() -> int:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('message', help='message for the change', nargs='?')
grp = parser.add_mutually_exclusive_group() 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('--init', action='store_true', help='Initialize everything')
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')
grp.add_argument('--reset', action='store_true', help='reset commit messages')
args = parser.parse_args() args = parser.parse_args()
@ -75,19 +115,10 @@ def main() -> int:
if args.init: if args.init:
_init() _init()
os.execvp('git', ('git', 'config', '--local', 'commit.template', GIT_COMMIT_MSG_FILE))
if args.show_msg:
_print_commit_msg()
return 0 return 0
if args.reset: if args.reset:
_reset_commit_msg_file() _reset_commit_msg_file()
return 0 return 0
_init()
if args.message:
print(_add_msg_to_file(args.message, args.type))
return 0 return 0

View File

@ -1,6 +1,6 @@
[project] [project]
name = "git-changes" name = "git-changes"
version = "0.0.1" version = "0.0.3"
authors = [ authors = [
{name="Adwaith-Rajesh", email="me@adwaith.dev"} {name="Adwaith-Rajesh", email="me@adwaith.dev"}
] ]
@ -13,17 +13,19 @@ classifiers = [
] ]
license = "MIT" license = "MIT"
license-files = ["LICENSE"] license-files = ["LICENSE"]
dependencies = [
"argcomplete>=3.6.2",
]
[project.scripts] [project.scripts]
gitc = "git_changes:main" gitc = "git_changes:main"
gitc-add = "git_changes:git_add"
gitc-show-messages = "git_changes:show_messages"
[build-system] [build-system]
requires = ["setuptools>=61.0"] requires = ["setuptools>=61.0"]
[tool.setuptools]
py-modules = ["git_changes"]
# [tool.setuptools.packages.find] # [tool.setuptools.packages.find]
# exclude = ["test", "tests"] # exclude = ["test", "tests"]