File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1+ use but_core:: sync:: LockScope ;
12use std:: fmt:: Write ;
23
34pub fn handle (
@@ -7,6 +8,12 @@ pub fn handle(
78 prs : bool ,
89 ci : bool ,
910) -> anyhow:: Result < ( ) > {
11+ // Obtain a lock to prevent concurrent background refreshes
12+ let _exclusive_access = but_core:: sync:: try_exclusive_inter_process_access (
13+ & ctx. gitdir ,
14+ LockScope :: BackgroundRefreshOperations ,
15+ ) ?;
16+
1017 if fetch {
1118 out. write_str ( "\n Fetching from remotes..." ) ?;
1219 let fetch_result = but_api:: legacy:: virtual_branches:: fetch_from_remotes (
Original file line number Diff line number Diff line change 11use std:: fmt:: Write ;
22
3+ use but_core:: sync:: LockScope ;
34use but_ctx:: Context ;
45use command_group:: AsyncCommandGroup ;
56
@@ -114,7 +115,15 @@ pub fn init_ctx(
114115 true // Never fetched before, force fetch
115116 } ;
116117
117- if should_fetch {
118+ // Check if there is a process still doing background refreshes
119+ let exclusive_access = but_core:: sync:: try_exclusive_inter_process_access (
120+ & ctx. gitdir ,
121+ LockScope :: BackgroundRefreshOperations ,
122+ )
123+ . ok ( ) ;
124+
125+ if should_fetch && exclusive_access. is_some ( ) {
126+ drop ( exclusive_access) ; // Release the lock immediately so that the new child process can acquire it
118127 let binary_path = std:: env:: current_exe ( ) . unwrap_or_default ( ) ;
119128 let proc = tokio:: process:: Command :: new ( binary_path. clone ( ) )
120129 . arg ( "-C" )
You can’t perform that action at this time.
0 commit comments