--- a/tests/test-rewind.t Sun Jun 17 02:03:03 2018 +0200
+++ b/tests/test-rewind.t Sun Jun 17 02:22:28 2018 +0200
@@ -640,3 +640,160 @@
date: Thu Jan 01 00:00:00 1970 +0000
summary: c_ROOT
+ $ cd ..
+
+Test rewinding stack
+====================
+
+ $ hg clone rewind-testing-base rewind-testing-stack
+ updating to branch default
+ 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+ $ cd rewind-testing-stack
+
+Rewinding the top of the stack only
+-----------------------------------
+
+setup
+`````
+
+ $ hg up 'desc("c_A0")'
+ 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+ $ echo AA >> A
+ $ hg amend -m 'c_A1'
+ 1 new orphan changesets
+ $ hg evolve --all
+ move:[2] c_B0
+ atop:[3] c_A1
+ working directory is now at a65fceb2324a
+ $ hg debugobsolete
+ 579f120ba91885449adc92eedf48ef3569742cee d952d1794ff657f5c2a82225d2e6307ed930b32f 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '9', 'operation': 'amend', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 a65fceb2324ae1eb1231610193d24a5fa02c7c0e 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '4', 'operation': 'evolve', 'user': 'test'}
+ $ hg obslog -r 'desc("c_A1")::'
+ @ a65fceb2324a (4) c_B0
+ |
+ | o d952d1794ff6 (3) c_A1
+ | |
+ | x 579f120ba918 (1) c_A0
+ | rewritten(description, content) as d952d1794ff6 using amend by test (Thu Jan 01 00:00:03 1970 +0000)
+ |
+ x 7e594302a05d (2) c_B0
+ rewritten(parent) as a65fceb2324a using evolve by test (Thu Jan 01 00:00:03 1970 +0000)
+
+ $ hg log -G
+ @ changeset: 4:a65fceb2324a
+ | tag: tip
+ | user: test
+ | date: Thu Jan 01 00:00:00 1970 +0000
+ | summary: c_B0
+ |
+ o changeset: 3:d952d1794ff6
+ | parent: 0:eba9c2249fe7
+ | user: test
+ | date: Thu Jan 01 00:00:00 1970 +0000
+ | summary: c_A1
+ |
+ o changeset: 0:eba9c2249fe7
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: c_ROOT
+
+
+Actual rewind
+`````````````
+
+ $ hg rewind --hidden --to 'min(desc(c_B0))'
+ 1 new orphan changesets
+ rewinded to 1 changesets
+ (1 changesets obsoleted)
+ working directory is now at 96622b0702dd
+ $ hg debugobsolete
+ 579f120ba91885449adc92eedf48ef3569742cee d952d1794ff657f5c2a82225d2e6307ed930b32f 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '9', 'operation': 'amend', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 a65fceb2324ae1eb1231610193d24a5fa02c7c0e 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '4', 'operation': 'evolve', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 96622b0702dd86e3a702b0235b420da41f072efe 4 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+ a65fceb2324ae1eb1231610193d24a5fa02c7c0e 96622b0702dd86e3a702b0235b420da41f072efe 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ $ hg obslog
+ @ 96622b0702dd (5) c_B0
+ |\
+ | x a65fceb2324a (4) c_B0
+ |/ rewritten(meta, date, parent) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
+ |
+ x 7e594302a05d (2) c_B0
+ rewritten(meta, date) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
+ rewritten(parent) as a65fceb2324a using evolve by test (Thu Jan 01 00:00:03 1970 +0000)
+
+ $ hg log -G
+ @ changeset: 5:96622b0702dd
+ | tag: tip
+ | parent: 1:579f120ba918
+ | user: test
+ | date: Thu Jan 01 00:00:03 1970 +0000
+ | instability: orphan
+ | summary: c_B0
+ |
+ | o changeset: 3:d952d1794ff6
+ | | parent: 0:eba9c2249fe7
+ | | user: test
+ | | date: Thu Jan 01 00:00:00 1970 +0000
+ | | summary: c_A1
+ | |
+ x | changeset: 1:579f120ba918
+ |/ user: test
+ | date: Thu Jan 01 00:00:00 1970 +0000
+ | obsolete: rewritten using amend as 3:d952d1794ff6
+ | summary: c_A0
+ |
+ o changeset: 0:eba9c2249fe7
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: c_ROOT
+
+
+cleanup
+```````
+
+ $ echo 'default-date = 4 0' >> $HGRCPATH
+ $ hg rewind --hidden --to 'max(precursors(.))'
+ rewinded to 1 changesets
+ (1 changesets obsoleted)
+ working directory is now at 7b1440274cc3
+ $ echo 'default-date = 5 0' >> $HGRCPATH
+ $ hg log -G
+ @ changeset: 6:7b1440274cc3
+ | tag: tip
+ | parent: 3:d952d1794ff6
+ | user: test
+ | date: Thu Jan 01 00:00:04 1970 +0000
+ | summary: c_B0
+ |
+ o changeset: 3:d952d1794ff6
+ | parent: 0:eba9c2249fe7
+ | user: test
+ | date: Thu Jan 01 00:00:00 1970 +0000
+ | summary: c_A1
+ |
+ o changeset: 0:eba9c2249fe7
+ user: test
+ date: Thu Jan 01 00:00:00 1970 +0000
+ summary: c_ROOT
+
+ $ hg debugobsolete
+ 579f120ba91885449adc92eedf48ef3569742cee d952d1794ff657f5c2a82225d2e6307ed930b32f 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '9', 'operation': 'amend', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 a65fceb2324ae1eb1231610193d24a5fa02c7c0e 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '4', 'operation': 'evolve', 'user': 'test'}
+ 7e594302a05d3769b27be88fc3cdfd39d7498498 96622b0702dd86e3a702b0235b420da41f072efe 4 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+ a65fceb2324ae1eb1231610193d24a5fa02c7c0e 96622b0702dd86e3a702b0235b420da41f072efe 0 (Thu Jan 01 00:00:03 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ a65fceb2324ae1eb1231610193d24a5fa02c7c0e 7b1440274cc3b3f8bfcffc891172a7d2d7e9140c 4 (Thu Jan 01 00:00:04 1970 +0000) {'ef1': '34', 'operation': 'rewind', 'user': 'test'}
+ 96622b0702dd86e3a702b0235b420da41f072efe 7b1440274cc3b3f8bfcffc891172a7d2d7e9140c 0 (Thu Jan 01 00:00:04 1970 +0000) {'ef1': '38', 'operation': 'rewind', 'user': 'test'}
+ $ hg obslog
+ @ 7b1440274cc3 (6) c_B0
+ |\
+ x | 96622b0702dd (5) c_B0
+ |\| rewritten(meta, date, parent) as 7b1440274cc3 using rewind by test (Thu Jan 01 00:00:04 1970 +0000)
+ | |
+ | x a65fceb2324a (4) c_B0
+ |/ rewritten(meta, date) as 7b1440274cc3 using rewind by test (Thu Jan 01 00:00:04 1970 +0000)
+ | rewritten(meta, date, parent) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
+ |
+ x 7e594302a05d (2) c_B0
+ rewritten(meta, date) as 96622b0702dd using rewind by test (Thu Jan 01 00:00:03 1970 +0000)
+ rewritten(parent) as a65fceb2324a using evolve by test (Thu Jan 01 00:00:03 1970 +0000)
+