@@ -18,7 +18,6 @@ use asyncgit::{
18
18
self , get_config_string, CommitId , HookResult ,
19
19
PrepareCommitMsgSource , RepoPathRef , RepoState ,
20
20
} ,
21
- StatusItem , StatusItemType ,
22
21
} ;
23
22
use crossterm:: event:: Event ;
24
23
use easy_cast:: Cast ;
@@ -28,10 +27,11 @@ use ratatui::{
28
27
Frame ,
29
28
} ;
30
29
30
+ use std:: process:: Command ;
31
31
use std:: {
32
32
fmt:: Write as _,
33
33
fs:: { read_to_string, File } ,
34
- io:: { Read , Write } ,
34
+ io:: Read ,
35
35
path:: PathBuf ,
36
36
str:: FromStr ,
37
37
} ;
@@ -144,47 +144,18 @@ impl CommitPopup {
144
144
}
145
145
}
146
146
147
- const fn item_status_char (
148
- item_type : StatusItemType ,
149
- ) -> & ' static str {
150
- match item_type {
151
- StatusItemType :: Modified => "modified" ,
152
- StatusItemType :: New => "new file" ,
153
- StatusItemType :: Deleted => "deleted" ,
154
- StatusItemType :: Renamed => "renamed" ,
155
- StatusItemType :: Typechange => " " ,
156
- StatusItemType :: Conflicted => "conflicted" ,
157
- }
158
- }
159
-
160
- pub fn show_editor (
161
- & mut self ,
162
- changes : Vec < StatusItem > ,
163
- ) -> Result < ( ) > {
164
- let file_path = sync:: repo_dir ( & self . repo . borrow ( ) ) ?
165
- . join ( "COMMIT_EDITMSG" ) ;
147
+ pub fn show_editor ( & mut self ) -> Result < ( ) > {
148
+ let git_dir = sync:: repo_dir ( & self . repo . borrow ( ) ) ?;
149
+ let work_dir = sync:: repo_work_dir ( & self . repo . borrow ( ) ) ?;
150
+ let file_path = git_dir. join ( "COMMIT_EDITMSG" ) ;
166
151
167
- {
168
- let mut file = File :: create ( & file_path) ?;
169
- file. write_fmt ( format_args ! (
170
- "{}\n " ,
171
- self . input. get_text( )
172
- ) ) ?;
173
- file. write_all (
174
- strings:: commit_editor_msg ( & self . key_config )
175
- . as_bytes ( ) ,
176
- ) ?;
177
-
178
- file. write_all ( b"\n #\n # Changes to be committed:" ) ?;
179
-
180
- for change in changes {
181
- let status_char =
182
- Self :: item_status_char ( change. status ) ;
183
- let message =
184
- format ! ( "\n #\t {status_char}: {}" , change. path) ;
185
- file. write_all ( message. as_bytes ( ) ) ?;
186
- }
187
- }
152
+ Command :: new ( "git" )
153
+ . arg ( "commit" )
154
+ . arg ( "--verbose" )
155
+ . env ( "EDITOR" , "false" )
156
+ . env ( "GIT_DIR" , git_dir)
157
+ . env ( "GIT_WORK_TREE" , work_dir)
158
+ . output ( ) ?;
188
159
189
160
ExternalEditorPopup :: open_file_in_editor (
190
161
& self . repo . borrow ( ) ,
@@ -199,7 +170,7 @@ impl CommitPopup {
199
170
std:: fs:: remove_file ( & file_path) ?;
200
171
201
172
message =
202
- commit_message_prettify ( & self . repo . borrow ( ) , message) ?;
173
+ commit_message_prettify ( & self . repo . borrow ( ) , & message) ?;
203
174
self . input . set_text ( message) ;
204
175
self . input . show ( ) ?;
205
176
@@ -210,7 +181,7 @@ impl CommitPopup {
210
181
let msg = self . input . get_text ( ) . to_string ( ) ;
211
182
212
183
if matches ! (
213
- self . commit_with_msg( msg) ?,
184
+ self . commit_with_msg( & msg) ?,
214
185
CommitResult :: CommitDone
215
186
) {
216
187
self . options
@@ -227,10 +198,7 @@ impl CommitPopup {
227
198
Ok ( ( ) )
228
199
}
229
200
230
- fn commit_with_msg (
231
- & mut self ,
232
- msg : String ,
233
- ) -> Result < CommitResult > {
201
+ fn commit_with_msg ( & mut self , msg : & str ) -> Result < CommitResult > {
234
202
// on exit verify should always be on
235
203
let verify = self . verify ;
236
204
self . verify = true ;
0 commit comments