@@ -18,7 +18,6 @@ use asyncgit::{
1818 self , get_config_string, CommitId , HookResult ,
1919 PrepareCommitMsgSource , RepoPathRef , RepoState ,
2020 } ,
21- StatusItem , StatusItemType ,
2221} ;
2322use crossterm:: event:: Event ;
2423use easy_cast:: Cast ;
@@ -28,10 +27,11 @@ use ratatui::{
2827 Frame ,
2928} ;
3029
30+ use std:: process:: Command ;
3131use std:: {
3232 fmt:: Write as _,
3333 fs:: { read_to_string, File } ,
34- io:: { Read , Write } ,
34+ io:: Read ,
3535 path:: PathBuf ,
3636 str:: FromStr ,
3737} ;
@@ -144,47 +144,18 @@ impl CommitPopup {
144144 }
145145 }
146146
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" ) ;
166151
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 ( ) ?;
188159
189160 ExternalEditorPopup :: open_file_in_editor (
190161 & self . repo . borrow ( ) ,
@@ -199,7 +170,7 @@ impl CommitPopup {
199170 std:: fs:: remove_file ( & file_path) ?;
200171
201172 message =
202- commit_message_prettify ( & self . repo . borrow ( ) , message) ?;
173+ commit_message_prettify ( & self . repo . borrow ( ) , & message) ?;
203174 self . input . set_text ( message) ;
204175 self . input . show ( ) ?;
205176
@@ -210,7 +181,7 @@ impl CommitPopup {
210181 let msg = self . input . get_text ( ) . to_string ( ) ;
211182
212183 if matches ! (
213- self . commit_with_msg( msg) ?,
184+ self . commit_with_msg( & msg) ?,
214185 CommitResult :: CommitDone
215186 ) {
216187 self . options
@@ -227,10 +198,7 @@ impl CommitPopup {
227198 Ok ( ( ) )
228199 }
229200
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 > {
234202 // on exit verify should always be on
235203 let verify = self . verify ;
236204 self . verify = true ;
0 commit comments