@@ -6329,6 +6329,260 @@ fn test_move_fixup_added_files() -> eyre::Result<()> {
63296329 Ok ( ( ) )
63306330}
63316331
6332+ #[ test]
6333+ fn test_move_reparent ( ) -> eyre:: Result < ( ) > {
6334+ let git = make_git ( ) ?;
6335+ git. init_repo ( ) ?;
6336+
6337+ git. detach_head ( ) ?;
6338+ let _test1_oid = git. commit_file ( "test1" , 1 ) ?;
6339+ let test2_oid = git. commit_file ( "test2_will_also_contain_test1_when_reparented" , 2 ) ?;
6340+ let test3_oid = git. commit_file ( "test3_will_also_contain_test2_when_reparented" , 3 ) ?;
6341+ {
6342+ let stdout = git. smartlog ( ) ?;
6343+ insta:: assert_snapshot!( stdout, @r"
6344+ O f777ecc (master) create initial.txt
6345+ |
6346+ o 62fc20d create test1.txt
6347+ |
6348+ o 06309ac create test2_will_also_contain_test1_when_reparented.txt
6349+ |
6350+ @ f41e0bb create test3_will_also_contain_test2_when_reparented.txt
6351+ " ) ;
6352+ }
6353+
6354+ {
6355+ let ( stdout, _stderr) = git. branchless (
6356+ "move" ,
6357+ & [
6358+ "--source" ,
6359+ & test2_oid. to_string ( ) ,
6360+ "--dest" ,
6361+ "master" ,
6362+ "--reparent" ,
6363+ ] ,
6364+ ) ?;
6365+ insta:: assert_snapshot!( stdout, @r"
6366+ reparenting...
6367+ Attempting rebase in-memory...
6368+ [1/2] Committed as: 40ca381 create test2_will_also_contain_test1_when_reparented.txt
6369+ [2/2] Committed as: e4eeed5 create test3_will_also_contain_test2_when_reparented.txt
6370+ branchless: processing 2 rewritten commits
6371+ branchless: running command: <git-executable> checkout e4eeed5c5bdc5a63228f1ac956cd58df0af1b670
6372+ O f777ecc (master) create initial.txt
6373+ |\
6374+ | o 62fc20d create test1.txt
6375+ |
6376+ o 40ca381 create test2_will_also_contain_test1_when_reparented.txt
6377+ |
6378+ @ e4eeed5 create test3_will_also_contain_test2_when_reparented.txt
6379+ In-memory rebase succeeded.
6380+ " ) ;
6381+ }
6382+
6383+ git. branchless ( "prev" , & [ ] ) ?;
6384+ {
6385+ let ( stdout, _stderr) = git. run ( & [ "show" ] ) ?;
6386+ insta:: assert_snapshot!( stdout, @r"
6387+ commit 40ca3815e2167cd8a464493414ea4340d65230a7
6388+ Author: Testy McTestface <test@example.com>
6389+ Date: Thu Oct 29 12:34:56 2020 -0200
6390+
6391+ create test2_will_also_contain_test1_when_reparented.txt
6392+
6393+ diff --git a/test1.txt b/test1.txt
6394+ new file mode 100644
6395+ index 0000000..7432a8f
6396+ --- /dev/null
6397+ +++ b/test1.txt
6398+ @@ -0,0 +1 @@
6399+ +test1 contents
6400+ diff --git a/test2_will_also_contain_test1_when_reparented.txt b/test2_will_also_contain_test1_when_reparented.txt
6401+ new file mode 100644
6402+ index 0000000..1619c31
6403+ --- /dev/null
6404+ +++ b/test2_will_also_contain_test1_when_reparented.txt
6405+ @@ -0,0 +1 @@
6406+ +test2_will_also_contain_test1_when_reparented contents
6407+ " ) ;
6408+ }
6409+
6410+ // test --reparent with --insert
6411+ {
6412+ let ( stdout, _stderr) = git. branchless (
6413+ "move" ,
6414+ & [
6415+ "--source" ,
6416+ & test3_oid. to_string ( ) ,
6417+ "--dest" ,
6418+ "master" ,
6419+ "--reparent" ,
6420+ "--insert" ,
6421+ ] ,
6422+ ) ?;
6423+ insta:: assert_snapshot!( stdout, @r"
6424+ reparenting...
6425+ Attempting rebase in-memory...
6426+ [1/4] Committed as: 3f0558d create test3_will_also_contain_test2_when_reparented.txt
6427+ [2/4] Committed as: e1e0b99 create test2_will_also_contain_test1_when_reparented.txt
6428+ [3/4] Committed as: 4b5cd3e create test3_will_also_contain_test2_when_reparented.txt
6429+ [4/4] Committed as: fee6ba0 create test1.txt
6430+ branchless: processing 4 rewritten commits
6431+ branchless: running command: <git-executable> checkout e1e0b9952583334793f781ef25a6ce8d861cf85f
6432+ O f777ecc (master) create initial.txt
6433+ |
6434+ o 3f0558d create test3_will_also_contain_test2_when_reparented.txt
6435+ |\
6436+ | o fee6ba0 create test1.txt
6437+ |
6438+ @ e1e0b99 create test2_will_also_contain_test1_when_reparented.txt
6439+ |
6440+ o 4b5cd3e create test3_will_also_contain_test2_when_reparented.txt
6441+ In-memory rebase succeeded.
6442+ " ) ;
6443+ }
6444+
6445+ // the reparented test3 contains everything, including test1 and test2
6446+ git. branchless ( "prev" , & [ ] ) ?;
6447+ {
6448+ let ( stdout, _stderr) = git. run ( & [ "show" ] ) ?;
6449+ insta:: assert_snapshot!( stdout, @r"
6450+ commit 3f0558d435e63ebdfd1e81f5dbd3ddfaca387864
6451+ Author: Testy McTestface <test@example.com>
6452+ Date: Thu Oct 29 12:34:56 2020 -0300
6453+
6454+ create test3_will_also_contain_test2_when_reparented.txt
6455+
6456+ diff --git a/test1.txt b/test1.txt
6457+ new file mode 100644
6458+ index 0000000..7432a8f
6459+ --- /dev/null
6460+ +++ b/test1.txt
6461+ @@ -0,0 +1 @@
6462+ +test1 contents
6463+ diff --git a/test2_will_also_contain_test1_when_reparented.txt b/test2_will_also_contain_test1_when_reparented.txt
6464+ new file mode 100644
6465+ index 0000000..1619c31
6466+ --- /dev/null
6467+ +++ b/test2_will_also_contain_test1_when_reparented.txt
6468+ @@ -0,0 +1 @@
6469+ +test2_will_also_contain_test1_when_reparented contents
6470+ diff --git a/test3_will_also_contain_test2_when_reparented.txt b/test3_will_also_contain_test2_when_reparented.txt
6471+ new file mode 100644
6472+ index 0000000..0829100
6473+ --- /dev/null
6474+ +++ b/test3_will_also_contain_test2_when_reparented.txt
6475+ @@ -0,0 +1 @@
6476+ +test3_will_also_contain_test2_when_reparented contents
6477+ " ) ;
6478+ }
6479+
6480+ // the descendant test2 should come without test3 like before
6481+ {
6482+ let ( stdout, _stderr) = git. run ( & [ "show" , "e1e0b99" ] ) ?;
6483+ insta:: assert_snapshot!( stdout, @r"
6484+ commit e1e0b9952583334793f781ef25a6ce8d861cf85f
6485+ Author: Testy McTestface <test@example.com>
6486+ Date: Thu Oct 29 12:34:56 2020 -0200
6487+
6488+ create test2_will_also_contain_test1_when_reparented.txt
6489+
6490+ diff --git a/test3_will_also_contain_test2_when_reparented.txt b/test3_will_also_contain_test2_when_reparented.txt
6491+ deleted file mode 100644
6492+ index 0829100..0000000
6493+ --- a/test3_will_also_contain_test2_when_reparented.txt
6494+ +++ /dev/null
6495+ @@ -1 +0,0 @@
6496+ -test3_will_also_contain_test2_when_reparented contents
6497+ " ) ;
6498+ }
6499+
6500+ // similarly the descendant test1 should come without test1 and test2
6501+ {
6502+ let ( stdout, _stderr) = git. run ( & [ "show" , "fee6ba0" ] ) ?;
6503+ insta:: assert_snapshot!( stdout, @r"
6504+ commit fee6ba034168cd7e83a93784c6c62cd9fb682d5a
6505+ Author: Testy McTestface <test@example.com>
6506+ Date: Thu Oct 29 12:34:56 2020 -0100
6507+
6508+ create test1.txt
6509+
6510+ diff --git a/test2_will_also_contain_test1_when_reparented.txt b/test2_will_also_contain_test1_when_reparented.txt
6511+ deleted file mode 100644
6512+ index 1619c31..0000000
6513+ --- a/test2_will_also_contain_test1_when_reparented.txt
6514+ +++ /dev/null
6515+ @@ -1 +0,0 @@
6516+ -test2_will_also_contain_test1_when_reparented contents
6517+ diff --git a/test3_will_also_contain_test2_when_reparented.txt b/test3_will_also_contain_test2_when_reparented.txt
6518+ deleted file mode 100644
6519+ index 0829100..0000000
6520+ --- a/test3_will_also_contain_test2_when_reparented.txt
6521+ +++ /dev/null
6522+ @@ -1 +0,0 @@
6523+ -test3_will_also_contain_test2_when_reparented contents
6524+ " ) ;
6525+ }
6526+
6527+ // the final descendant test3 should be identical with the inserted test3
6528+ git. branchless ( "switch" , & [ "4b5cd3e" ] ) ?;
6529+ {
6530+ let ( stdout, _stderr) = git. run ( & [ "diff" , "3f0558d" ] ) ?;
6531+ insta:: assert_snapshot!( stdout, @"" ) ;
6532+ }
6533+
6534+ // test --reparent with --exact
6535+ {
6536+ let ( stdout, _stderr) = git. branchless (
6537+ "move" ,
6538+ & [ "--exact" , "e1e0b99" , "--dest" , "master" , "--reparent" ] ,
6539+ ) ?;
6540+ insta:: assert_snapshot!( stdout, @r"
6541+ Attempting rebase in-memory...
6542+ [1/2] Skipped now-empty commit: 5cdb6f1 create test3_will_also_contain_test2_when_reparented.txt
6543+ [2/2] Committed as: 40ca381 create test2_will_also_contain_test1_when_reparented.txt
6544+ branchless: processing 2 rewritten commits
6545+ branchless: running command: <git-executable> checkout 3f0558d435e63ebdfd1e81f5dbd3ddfaca387864
6546+ O f777ecc (master) create initial.txt
6547+ |\
6548+ | o 40ca381 create test2_will_also_contain_test1_when_reparented.txt
6549+ |
6550+ @ 3f0558d create test3_will_also_contain_test2_when_reparented.txt
6551+ |
6552+ o fee6ba0 create test1.txt
6553+ In-memory rebase succeeded.
6554+ " ) ;
6555+ }
6556+
6557+ {
6558+ let ( stdout, _stderr) = git. run ( & [ "show" , "40ca381" ] ) ?;
6559+ insta:: assert_snapshot!( stdout, @r"
6560+ commit 40ca3815e2167cd8a464493414ea4340d65230a7
6561+ Author: Testy McTestface <test@example.com>
6562+ Date: Thu Oct 29 12:34:56 2020 -0200
6563+
6564+ create test2_will_also_contain_test1_when_reparented.txt
6565+
6566+ diff --git a/test1.txt b/test1.txt
6567+ new file mode 100644
6568+ index 0000000..7432a8f
6569+ --- /dev/null
6570+ +++ b/test1.txt
6571+ @@ -0,0 +1 @@
6572+ +test1 contents
6573+ diff --git a/test2_will_also_contain_test1_when_reparented.txt b/test2_will_also_contain_test1_when_reparented.txt
6574+ new file mode 100644
6575+ index 0000000..1619c31
6576+ --- /dev/null
6577+ +++ b/test2_will_also_contain_test1_when_reparented.txt
6578+ @@ -0,0 +1 @@
6579+ +test2_will_also_contain_test1_when_reparented contents
6580+ " ) ;
6581+ }
6582+
6583+ Ok ( ( ) )
6584+ }
6585+
63326586#[ test]
63336587fn test_worktree_rebase_in_memory ( ) -> eyre:: Result < ( ) > {
63346588 let git = make_git ( ) ?;
0 commit comments