@@ -23,93 +23,105 @@ export const create_checkpoint = async (
2323) : Promise < boolean > => {
2424 try {
2525 const timestamp = Date . now ( )
26- await vscode . window . withProgress (
27- {
28- location : vscode . ProgressLocation . Notification ,
29- title : 'Creating checkpoint...' ,
30- cancellable : false
31- } ,
32- async ( ) => {
33- await vscode . workspace . saveAll ( )
34- const checkpoint_dir_path = get_checkpoint_path ( timestamp )
35- const checkpoint_dir_uri = vscode . Uri . file ( checkpoint_dir_path )
36- await vscode . workspace . fs . createDirectory ( checkpoint_dir_uri )
26+ const workspace_folders = vscode . workspace . workspaceFolders !
3727
38- const workspace_folders = vscode . workspace . workspaceFolders !
39- const git_data : Record < string , any > = { }
40- let uses_git = false
28+ const folder_git_statuses = await Promise . all (
29+ workspace_folders . map ( ( folder ) => is_git_repository ( folder ) )
30+ )
31+ const all_folders_use_git = folder_git_statuses . every ( ( status ) => status )
32+
33+ const create_checkpoint_task = async ( ) => {
34+ await vscode . workspace . saveAll ( )
35+ const checkpoint_dir_path = get_checkpoint_path ( timestamp )
36+ const checkpoint_dir_uri = vscode . Uri . file ( checkpoint_dir_path )
37+ await vscode . workspace . fs . createDirectory ( checkpoint_dir_uri )
4138
42- for ( const folder of workspace_folders ) {
43- const has_git = await is_git_repository ( folder )
39+ const git_data : Record < string , any > = { }
40+ let uses_git = false
4441
45- if ( has_git ) {
46- uses_git = true
47- const git_info = await get_git_info ( folder )
48- const diff = await get_git_diff ( folder )
42+ for ( const [ index , folder ] of workspace_folders . entries ( ) ) {
43+ const has_git = folder_git_statuses [ index ]
4944
50- if ( git_info && diff !== null ) {
51- const folder_name = folder . name
52- git_data [ folder_name ] = {
53- branch : git_info . branch ,
54- commit_hash : git_info . commit_hash ,
55- folder_name
56- }
45+ if ( has_git ) {
46+ uses_git = true
47+ const git_info = await get_git_info ( folder )
48+ const diff = await get_git_diff ( folder )
5749
58- const diff_file_path = path . join (
59- checkpoint_dir_path ,
60- `${ folder_name } .diff`
61- )
62- await vscode . workspace . fs . writeFile (
63- vscode . Uri . file ( diff_file_path ) ,
64- Buffer . from ( diff , 'utf8' )
65- )
66- } else {
67- throw new Error (
68- `Failed to get git information for repository in ${ folder . name } .`
69- )
50+ if ( git_info && diff !== null ) {
51+ const folder_name = folder . name
52+ git_data [ folder_name ] = {
53+ branch : git_info . branch ,
54+ commit_hash : git_info . commit_hash ,
55+ folder_name
7056 }
57+
58+ const diff_file_path = path . join (
59+ checkpoint_dir_path ,
60+ `${ folder_name } .diff`
61+ )
62+ await vscode . workspace . fs . writeFile (
63+ vscode . Uri . file ( diff_file_path ) ,
64+ Buffer . from ( diff , 'utf8' )
65+ )
7166 } else {
72- const dest_folder_path =
73- workspace_folders . length > 1
74- ? path . join ( checkpoint_dir_path , folder . name )
75- : checkpoint_dir_path
76- const dest_folder_uri = vscode . Uri . file ( dest_folder_path )
77- if ( workspace_folders . length > 1 ) {
78- await vscode . workspace . fs . createDirectory ( dest_folder_uri )
79- }
67+ throw new Error (
68+ `Failed to get git information for repository in ${ folder . name } .`
69+ )
70+ }
71+ } else {
72+ const dest_folder_path =
73+ workspace_folders . length > 1
74+ ? path . join ( checkpoint_dir_path , folder . name )
75+ : checkpoint_dir_path
76+ const dest_folder_uri = vscode . Uri . file ( dest_folder_path )
77+ if ( workspace_folders . length > 1 ) {
78+ await vscode . workspace . fs . createDirectory ( dest_folder_uri )
79+ }
8080
81- const entries = await vscode . workspace . fs . readDirectory ( folder . uri )
82- for ( const [ name ] of entries ) {
83- await copy_optimised_recursively (
84- vscode . Uri . joinPath ( folder . uri , name ) ,
85- vscode . Uri . joinPath ( dest_folder_uri , name ) ,
86- folder . uri . fsPath ,
87- workspace_provider
88- )
89- }
81+ const entries = await vscode . workspace . fs . readDirectory ( folder . uri )
82+ for ( const [ name ] of entries ) {
83+ await copy_optimised_recursively (
84+ vscode . Uri . joinPath ( folder . uri , name ) ,
85+ vscode . Uri . joinPath ( dest_folder_uri , name ) ,
86+ folder . uri . fsPath ,
87+ workspace_provider
88+ )
9089 }
9190 }
91+ }
9292
93- const checkpoints = await get_checkpoints ( context )
94-
95- const final_description = get_incremented_description (
96- title ,
97- description ,
98- checkpoints
99- )
93+ const checkpoints = await get_checkpoints ( context )
10094
101- const new_checkpoint : Checkpoint = {
102- title,
103- timestamp,
104- description : final_description ,
105- uses_git,
106- git_data : Object . keys ( git_data ) . length > 0 ? git_data : undefined
107- }
95+ const final_description = get_incremented_description (
96+ title ,
97+ description ,
98+ checkpoints
99+ )
108100
109- checkpoints . unshift ( new_checkpoint )
110- await context . workspaceState . update ( CHECKPOINTS_STATE_KEY , checkpoints )
101+ const new_checkpoint : Checkpoint = {
102+ title,
103+ timestamp,
104+ description : final_description ,
105+ uses_git,
106+ git_data : Object . keys ( git_data ) . length > 0 ? git_data : undefined
111107 }
112- )
108+
109+ checkpoints . unshift ( new_checkpoint )
110+ await context . workspaceState . update ( CHECKPOINTS_STATE_KEY , checkpoints )
111+ }
112+
113+ if ( all_folders_use_git ) {
114+ await create_checkpoint_task ( )
115+ } else {
116+ await vscode . window . withProgress (
117+ {
118+ location : vscode . ProgressLocation . Notification ,
119+ title : 'Creating checkpoint...' ,
120+ cancellable : false
121+ } ,
122+ create_checkpoint_task
123+ )
124+ }
113125 return true
114126 } catch ( err : any ) {
115127 vscode . window . showErrorMessage (
0 commit comments