Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ If ollama server is running, run the script using the command
python3 auto_commit.py
```

Create commit per file

```
python3 auto_commit.py single
```



### Miscellaneous
Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.1
47 changes: 40 additions & 7 deletions auto_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,51 @@ async def git_commit_everything(message):
subprocess.run(['git', 'commit', '-m', message], check=True)


async def main():
files = await get_changed_files()
if not files:
print("No changes detected.")
async def git_commit_file(file, message):
"""
Stages all changes (including new, modified, deleted files), commits with the given message,
and pushes the commit to the current branch on the default remote ('origin').
"""
if not message:
return

try:
subprocess.run(['git', 'add', file], check=True)
except:
print("An exception occurred")
# Commit with the provided message
subprocess.run(['git', 'commit', file, '-m', message], check=True)


async def commit_comment_per_file(files):
for file in files:
print(f"{file}")
commit_messages = await diff_single_file(file)
commit_messages_text = "\n".join(commit_messages)
print(f"{commit_messages_text}")
await git_commit_everything(commit_messages_text)
print(f"{file}: {commit_messages_text}")
await git_commit_file(file, commit_messages_text)


async def comit_comment_all(files):
all_message = []
for file in files:
commit_messages = await diff_single_file(file)
commit_messages_text = "\n".join(commit_messages)
print(f"{file}: {commit_messages_text}")
all_message.extend(commit_messages)
await git_commit_everything(message="\n".join(all_message))


async def main():
files = await get_changed_files()
if not files:
print("No changes detected.")
return
is_commit_per_file = True if (
len(sys.argv) > 1 and sys.argv[1] == 'single') else False
if is_commit_per_file:
await commit_comment_per_file(files)
else:
await comit_comment_all(files)

if __name__ == "__main__":
asyncio.run(main())