|
1 | 1 | use lib::testing::{ |
2 | | - extract_hint_command, make_git, make_git_with_remote_repo, remove_rebase_lines, GitInitOptions, |
3 | | - GitRunOptions, GitWrapperWithRemoteRepo, |
| 2 | + extract_hint_command, make_git, make_git_with_remote_repo, make_git_worktree, |
| 3 | + remove_rebase_lines, GitInitOptions, GitRunOptions, GitWorktreeWrapper, |
| 4 | + GitWrapperWithRemoteRepo, |
4 | 5 | }; |
5 | 6 |
|
6 | 7 | #[test] |
@@ -6237,3 +6238,85 @@ fn test_move_fixup_added_files() -> eyre::Result<()> { |
6237 | 6238 |
|
6238 | 6239 | Ok(()) |
6239 | 6240 | } |
| 6241 | + |
| 6242 | +#[test] |
| 6243 | +fn test_worktree_rebase_in_memory() -> eyre::Result<()> { |
| 6244 | + let git = make_git()?; |
| 6245 | + |
| 6246 | + if !git.supports_reference_transactions()? { |
| 6247 | + return Ok(()); |
| 6248 | + } |
| 6249 | + git.init_repo()?; |
| 6250 | + |
| 6251 | + git.commit_file("test1", 1)?; |
| 6252 | + git.detach_head()?; |
| 6253 | + git.commit_file("test2", 2)?; |
| 6254 | + git.commit_file("test3", 3)?; |
| 6255 | + |
| 6256 | + let GitWorktreeWrapper { |
| 6257 | + temp_dir: _temp_dir, |
| 6258 | + worktree, |
| 6259 | + } = make_git_worktree(&git, "new-worktree")?; |
| 6260 | + git.run(&["checkout", "master"])?; |
| 6261 | + { |
| 6262 | + let stdout = worktree.smartlog()?; |
| 6263 | + insta::assert_snapshot!(stdout, @r###" |
| 6264 | + : |
| 6265 | + O 62fc20d (master) create test1.txt |
| 6266 | + | |
| 6267 | + o 96d1c37 create test2.txt |
| 6268 | + | |
| 6269 | + @ 70deb1e create test3.txt |
| 6270 | + "###); |
| 6271 | + } |
| 6272 | + |
| 6273 | + { |
| 6274 | + let (stdout, stderr) = worktree.branchless("move", &["-s", "@", "-d", "master"])?; |
| 6275 | + insta::assert_snapshot!(stderr, @r###" |
| 6276 | + branchless: creating working copy snapshot |
| 6277 | + Previous HEAD position was 70deb1e create test3.txt |
| 6278 | + branchless: processing 1 update: ref HEAD |
| 6279 | + HEAD is now at 4838e49 create test3.txt |
| 6280 | + branchless: processing checkout |
| 6281 | + "###); |
| 6282 | + insta::assert_snapshot!(stdout, @r###" |
| 6283 | + Attempting rebase in-memory... |
| 6284 | + [1/1] Committed as: 4838e49 create test3.txt |
| 6285 | + branchless: processing 1 rewritten commit |
| 6286 | + branchless: running command: <git-executable> checkout 4838e49b08954becdd17c0900c1179c2c654c627 |
| 6287 | + : |
| 6288 | + O 62fc20d (master) create test1.txt |
| 6289 | + |\ |
| 6290 | + | o 96d1c37 create test2.txt |
| 6291 | + | |
| 6292 | + @ 4838e49 create test3.txt |
| 6293 | + In-memory rebase succeeded. |
| 6294 | + "###); |
| 6295 | + } |
| 6296 | + |
| 6297 | + { |
| 6298 | + let stdout = worktree.smartlog()?; |
| 6299 | + insta::assert_snapshot!(stdout, @r###" |
| 6300 | + : |
| 6301 | + O 62fc20d (master) create test1.txt |
| 6302 | + |\ |
| 6303 | + | o 96d1c37 create test2.txt |
| 6304 | + | |
| 6305 | + @ 4838e49 create test3.txt |
| 6306 | + "###); |
| 6307 | + } |
| 6308 | + |
| 6309 | + { |
| 6310 | + let stdout = git.smartlog()?; |
| 6311 | + insta::assert_snapshot!(stdout, @r###" |
| 6312 | + : |
| 6313 | + @ 62fc20d (> master) create test1.txt |
| 6314 | + |\ |
| 6315 | + | o 96d1c37 create test2.txt |
| 6316 | + | |
| 6317 | + o 4838e49 create test3.txt |
| 6318 | + "###); |
| 6319 | + } |
| 6320 | + |
| 6321 | + Ok(()) |
| 6322 | +} |
0 commit comments