|
3 | 3 | use eyre::Context;
|
4 | 4 | use rayon::ThreadPoolBuilder;
|
5 | 5 | use std::{
|
6 |
| - collections::HashMap, |
7 | 6 | fmt::Write,
|
8 | 7 | path::Path,
|
9 | 8 | time::{SystemTime, UNIX_EPOCH},
|
@@ -250,34 +249,65 @@ pub fn split(
|
250 | 249 | event_tx_id,
|
251 | 250 | commit_oid: extracted_commit_oid,
|
252 | 251 | }])?;
|
253 |
| - move_branches(effects, git_run_info, &repo, event_tx_id, &{ |
254 |
| - let mut result = HashMap::new(); |
255 |
| - result.insert(commit_to_split_oid, MaybeZeroOid::NonZero(split_commit_oid)); |
256 |
| - result |
257 |
| - })?; |
258 | 252 |
|
259 | 253 | let head_info = repo.get_head_info()?;
|
260 |
| - if let ResolvedReferenceInfo { |
261 |
| - oid: Some(oid), |
262 |
| - reference_name: _, |
263 |
| - } = head_info |
264 |
| - { |
265 |
| - if oid == commit_to_split_oid { |
266 |
| - try_exit_code!(check_out_commit( |
267 |
| - effects, |
268 |
| - git_run_info, |
269 |
| - &repo, |
270 |
| - &event_log_db, |
271 |
| - event_tx_id, |
272 |
| - Some(CheckoutTarget::Oid(split_commit_oid)), |
273 |
| - &CheckOutCommitOptions { |
274 |
| - additional_args: Default::default(), |
275 |
| - force_detach: true, |
276 |
| - reset: false, |
277 |
| - render_smartlog: false, |
278 |
| - }, |
279 |
| - )?); |
280 |
| - } |
| 254 | + let (checkout_target, rewritten_oids) = match head_info { |
| 255 | + // branch @ split commit checked out: extend branch to include extracted |
| 256 | + // commit; branch will stay checked out w/ any explicit checkout |
| 257 | + ResolvedReferenceInfo { |
| 258 | + oid: Some(oid), |
| 259 | + reference_name: Some(_), |
| 260 | + } if oid == commit_to_split_oid => ( |
| 261 | + None, |
| 262 | + vec![( |
| 263 | + commit_to_split_oid, |
| 264 | + MaybeZeroOid::NonZero(extracted_commit_oid), |
| 265 | + )], |
| 266 | + ), |
| 267 | + |
| 268 | + // commit to split checked out as detached HEAD, don't extend any |
| 269 | + // branches, but explicitly check out the newly split commit |
| 270 | + ResolvedReferenceInfo { |
| 271 | + oid: Some(oid), |
| 272 | + reference_name: None, |
| 273 | + } if oid == commit_to_split_oid => ( |
| 274 | + Some(CheckoutTarget::Oid(split_commit_oid)), |
| 275 | + vec![(commit_to_split_oid, MaybeZeroOid::NonZero(split_commit_oid))], |
| 276 | + ), |
| 277 | + |
| 278 | + // some other commit or branch was checked out, default behavior is fine |
| 279 | + ResolvedReferenceInfo { |
| 280 | + oid: _, |
| 281 | + reference_name: _, |
| 282 | + } => ( |
| 283 | + None, |
| 284 | + vec![(commit_to_split_oid, MaybeZeroOid::NonZero(split_commit_oid))], |
| 285 | + ), |
| 286 | + }; |
| 287 | + |
| 288 | + move_branches( |
| 289 | + effects, |
| 290 | + git_run_info, |
| 291 | + &repo, |
| 292 | + event_tx_id, |
| 293 | + &(rewritten_oids.into_iter().collect()), |
| 294 | + )?; |
| 295 | + |
| 296 | + if checkout_target.is_some() { |
| 297 | + try_exit_code!(check_out_commit( |
| 298 | + effects, |
| 299 | + git_run_info, |
| 300 | + &repo, |
| 301 | + &event_log_db, |
| 302 | + event_tx_id, |
| 303 | + Some(CheckoutTarget::Oid(split_commit_oid)), |
| 304 | + &CheckOutCommitOptions { |
| 305 | + additional_args: Default::default(), |
| 306 | + force_detach: true, |
| 307 | + reset: false, |
| 308 | + render_smartlog: false, |
| 309 | + }, |
| 310 | + )?); |
281 | 311 | }
|
282 | 312 |
|
283 | 313 | let mut builder = RebasePlanBuilder::new(&dag, permissions);
|
|
0 commit comments