@@ -102,9 +102,7 @@ export const handle_conflict_markers = async (
102102 file . content
103103 )
104104 } else {
105- if ( file . content !== '' ) {
106- new_content = file . content
107- }
105+ new_content = file . content
108106 }
109107
110108 const tabs_to_close : vscode . Tab [ ] = [ ]
@@ -129,31 +127,21 @@ export const handle_conflict_markers = async (
129127 workspace_root
130128 } )
131129
132- if ( new_content . trim ( ) == '' ) {
133- original_states . push ( {
134- file_path : file . file_path ,
135- content : rename_source_content ,
136- workspace_name : file . workspace_name ,
137- file_path_to_restore : file . renamed_from ,
138- file_state : 'deleted'
139- } )
140- } else {
141- const directory = path . dirname ( safe_path )
142- if ( ! fs . existsSync ( directory ) ) {
143- await fs . promises . mkdir ( directory , { recursive : true } )
144- }
145- await vscode . workspace . fs . writeFile (
146- vscode . Uri . file ( safe_path ) ,
147- Buffer . from ( new_content , 'utf8' )
148- )
149-
150- original_states . push ( {
151- file_path : file . file_path ,
152- content : rename_source_content ,
153- workspace_name : file . workspace_name ,
154- file_path_to_restore : file . renamed_from
155- } )
130+ const directory = path . dirname ( safe_path )
131+ if ( ! fs . existsSync ( directory ) ) {
132+ await fs . promises . mkdir ( directory , { recursive : true } )
156133 }
134+ await vscode . workspace . fs . writeFile (
135+ vscode . Uri . file ( safe_path ) ,
136+ Buffer . from ( new_content , 'utf8' )
137+ )
138+
139+ original_states . push ( {
140+ file_path : file . file_path ,
141+ content : rename_source_content ,
142+ workspace_name : file . workspace_name ,
143+ file_path_to_restore : file . renamed_from
144+ } )
157145 } catch ( error ) {
158146 failed_files . push ( file )
159147 }
@@ -166,50 +154,19 @@ export const handle_conflict_markers = async (
166154 file . content
167155 )
168156
169- if ( current_content . trim ( ) == '' ) {
170- const tabs_to_close : vscode . Tab [ ] = [ ]
171- for ( const tab_group of vscode . window . tabGroups . all ) {
172- tabs_to_close . push (
173- ...tab_group . tabs . filter ( ( tab ) => {
174- const tab_uri = ( tab . input as any ) ?. uri as
175- | vscode . Uri
176- | undefined
177- return tab_uri && tab_uri . fsPath === safe_path
178- } )
179- )
180- }
181-
182- if ( tabs_to_close . length > 0 ) {
183- await vscode . window . tabGroups . close ( tabs_to_close )
184- }
185-
186- await vscode . workspace . fs . delete ( vscode . Uri . file ( safe_path ) )
187- await remove_directory_if_empty ( {
188- dir_path : path . dirname ( safe_path ) ,
189- workspace_root
190- } )
191-
192- original_states . push ( {
193- file_path : file . file_path ,
194- content : original_content ,
195- workspace_name : file . workspace_name ,
196- file_state : 'deleted'
197- } )
198- } else {
199- if ( current_content !== original_content ) {
200- await vscode . workspace . fs . writeFile (
201- vscode . Uri . file ( safe_path ) ,
202- Buffer . from ( current_content , 'utf8' )
203- )
204- }
205-
206- original_states . push ( {
207- file_path : file . file_path ,
208- content : original_content ,
209- workspace_name : file . workspace_name
210- } )
157+ if ( current_content !== original_content ) {
158+ await vscode . workspace . fs . writeFile (
159+ vscode . Uri . file ( safe_path ) ,
160+ Buffer . from ( current_content , 'utf8' )
161+ )
211162 }
212163
164+ original_states . push ( {
165+ file_path : file . file_path ,
166+ content : original_content ,
167+ workspace_name : file . workspace_name
168+ } )
169+
213170 Logger . info ( {
214171 function_name : 'handle_conflict_markers' ,
215172 message : 'Applied conflict markers edit to file' ,
@@ -224,16 +181,6 @@ export const handle_conflict_markers = async (
224181 failed_files . push ( file )
225182 }
226183 } else if ( ! file_exists ) {
227- if ( file . content == '' ) {
228- original_states . push ( {
229- file_path : file . file_path ,
230- content : '' ,
231- file_state : 'new' ,
232- workspace_name : file . workspace_name
233- } )
234- continue
235- }
236-
237184 try {
238185 const directory = path . dirname ( safe_path )
239186 if ( ! fs . existsSync ( directory ) ) {
@@ -270,61 +217,30 @@ export const handle_conflict_markers = async (
270217 const document = await vscode . workspace . openTextDocument ( safe_path )
271218 const original_content = document . getText ( )
272219
273- if ( file . content . trim ( ) == '' ) {
274- const tabs_to_close : vscode . Tab [ ] = [ ]
275- for ( const tab_group of vscode . window . tabGroups . all ) {
276- tabs_to_close . push (
277- ...tab_group . tabs . filter ( ( tab ) => {
278- const tab_uri = ( tab . input as any ) ?. uri as
279- | vscode . Uri
280- | undefined
281- return tab_uri && tab_uri . fsPath === safe_path
282- } )
283- )
284- }
285-
286- if ( tabs_to_close . length > 0 ) {
287- await vscode . window . tabGroups . close ( tabs_to_close )
288- }
289-
290- await vscode . workspace . fs . delete ( vscode . Uri . file ( safe_path ) )
291- await remove_directory_if_empty ( {
292- dir_path : path . dirname ( safe_path ) ,
293- workspace_root
294- } )
295-
296- original_states . push ( {
297- file_path : file . file_path ,
298- content : original_content ,
299- workspace_name : file . workspace_name ,
300- file_state : 'deleted'
301- } )
302- } else {
303- const editor = await vscode . window . showTextDocument ( document )
304- let final_content = file . content
305- if (
306- original_content . endsWith ( '\n' ) &&
307- ! final_content . endsWith ( '\n' )
308- ) {
309- final_content += '\n'
310- }
311- await editor . edit ( ( edit ) => {
312- edit . replace (
313- new vscode . Range (
314- document . positionAt ( 0 ) ,
315- document . positionAt ( document . getText ( ) . length )
316- ) ,
317- final_content
318- )
319- } )
320- await document . save ( )
321-
322- original_states . push ( {
323- file_path : file . file_path ,
324- content : original_content ,
325- workspace_name : file . workspace_name
326- } )
220+ const editor = await vscode . window . showTextDocument ( document )
221+ let final_content = file . content
222+ if (
223+ original_content . endsWith ( '\n' ) &&
224+ ! final_content . endsWith ( '\n' )
225+ ) {
226+ final_content += '\n'
327227 }
228+ await editor . edit ( ( edit ) => {
229+ edit . replace (
230+ new vscode . Range (
231+ document . positionAt ( 0 ) ,
232+ document . positionAt ( document . getText ( ) . length )
233+ ) ,
234+ final_content
235+ )
236+ } )
237+ await document . save ( )
238+
239+ original_states . push ( {
240+ file_path : file . file_path ,
241+ content : original_content ,
242+ workspace_name : file . workspace_name
243+ } )
328244 } catch ( error : any ) {
329245 Logger . error ( {
330246 function_name : 'handle_conflict_markers' ,
0 commit comments