Skip to content

Commit 0ea9fe1

Browse files
authored
create single commit message (#2)
* create single commit message Create * feat: Add single commit option in auto_commit.py * refactor: Simplify git commit function * fix: Update VERSION to 1.0.1 * docs: Update VERSION file to 1.0.1 * fix: Update VERSION to 1.0.1
1 parent ef49250 commit 0ea9fe1

File tree

3 files changed

+47
-7
lines changed

3 files changed

+47
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ If ollama server is running, run the script using the command
3131
python3 auto_commit.py
3232
```
3333

34+
Create commit per file
35+
36+
```
37+
python3 auto_commit.py single
38+
```
39+
3440

3541

3642
### Miscellaneous

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.0.1

auto_commit.py

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,51 @@ async def git_commit_everything(message):
9696
subprocess.run(['git', 'commit', '-m', message], check=True)
9797

9898

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

107+
try:
108+
subprocess.run(['git', 'add', file], check=True)
109+
except:
110+
print("An exception occurred")
111+
# Commit with the provided message
112+
subprocess.run(['git', 'commit', file, '-m', message], check=True)
113+
114+
115+
async def commit_comment_per_file(files):
105116
for file in files:
106-
print(f"{file}")
107117
commit_messages = await diff_single_file(file)
108118
commit_messages_text = "\n".join(commit_messages)
109-
print(f"{commit_messages_text}")
110-
await git_commit_everything(commit_messages_text)
119+
print(f"{file}: {commit_messages_text}")
120+
await git_commit_file(file, commit_messages_text)
121+
122+
123+
async def comit_comment_all(files):
124+
all_message = []
125+
for file in files:
126+
commit_messages = await diff_single_file(file)
127+
commit_messages_text = "\n".join(commit_messages)
128+
print(f"{file}: {commit_messages_text}")
129+
all_message.extend(commit_messages)
130+
await git_commit_everything(message="\n".join(all_message))
131+
132+
133+
async def main():
134+
files = await get_changed_files()
135+
if not files:
136+
print("No changes detected.")
137+
return
138+
is_commit_per_file = True if (
139+
len(sys.argv) > 1 and sys.argv[1] == 'single') else False
140+
if is_commit_per_file:
141+
await commit_comment_per_file(files)
142+
else:
143+
await comit_comment_all(files)
111144

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

0 commit comments

Comments
 (0)