@@ -96,18 +96,51 @@ async def git_commit_everything(message):
96
96
subprocess .run (['git' , 'commit' , '-m' , message ], check = True )
97
97
98
98
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 :
103
105
return
104
106
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 ):
105
116
for file in files :
106
- print (f"{ file } " )
107
117
commit_messages = await diff_single_file (file )
108
118
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 )
111
144
112
145
if __name__ == "__main__" :
113
146
asyncio .run (main ())
0 commit comments