sapling/tests/test-unbundlereplay.t
Stanislau Hlebik dee75aa345 pushrebase: support deletion of a bookmark in sendunbundlereplay
Summary:
Previously one couldn't use `sendunbundlereplay` to replay a bundle that just
deletes a bookmark i.e. sends only pushkey part. The problem was in that
`bundleoperation.gettransaction` method wasn't called and so a few hook
arguments weren't set.

In order to fix it this diff just calls this method before calling pushkey. The
solution is not clean, but I don't see much better alternatives.

Another smaller change that this diff is doing is changing sendunbundlereplay
command to require `--deleted` flag. This is just for convenience.

Reviewed By: quark-zju

Differential Revision: D14185380

fbshipit-source-id: f511dc0b9906520b7877501b37639d89ada6fc45
2019-02-25 13:08:00 -08:00

358 lines
13 KiB
Perl

$ . "$TESTDIR/hgsql/library.sh"
#testcases respondlightly respondfully
Do some initial setup
$ CACHEDIR=`pwd`/hgcache
$ cat >> $HGRCPATH <<CONFIG
> [ui]
> ssh = python "$RUNTESTDIR/dummyssh"
> username = nobody <no.reply@fb.com>
> [extensions]
> sendunbundlereplay=
> smartlog=
> treemanifest=
> fastmanifest=
> remotefilelog=
> pushrebase=
> [remotefilelog]
> reponame=testrepo
> cachepath=$CACHEDIR
> CONFIG
Setup helpers
$ log() {
> hg sl -T "{desc} [{phase};rev={rev};{node|short}] {bookmarks}" "$@"
> }
Implement a basic verification hook
$ cat >>$TESTTMP/replayverification.py <<EOF
> import os, sys
> expected_book = os.environ["HG_EXPECTED_ONTOBOOK"]
> expected_head = os.environ["HG_EXPECTED_REBASEDHEAD"]
> actual_book = os.environ["HG_KEY"]
> actual_head = os.environ["HG_NEW"]
> if expected_book == actual_book:
> if ((expected_head is None and actual_head is None) or
> (expected_head == actual_head)):
> print "[ReplayVerification] Everything seems in order"
> sys.exit(0)
> print "[ReplayVerification] Expected: (%s, %s). Actual: (%s, %s)" % (expected_book, expected_head, actual_book, actual_head)
> sys.exit(1)
> EOF
Setup a server repo
$ hg init server
$ cd server
$ cat >> .hg/hgrc <<CONFIG
> [treemanifest]
> server = True
> [remotefilelog]
> server = True
> shallowtrees = True
> CONFIG
$ hg debugdrawdag <<EOF
> C
> |
> B
> |
> A
> EOF
$ hg bookmark master_bookmark -r tip
$ hg phase -r "all()" --public
$ log -r "all()"
o C [public;rev=2;26805aba1e60] master_bookmark
|
o B [public;rev=1;112478962961]
|
o A [public;rev=0;426bada5c675]
$ cat >>.hg/hgrc <<CONFIG
> [hooks]
> prepushkey = python "$TESTTMP/replayverification.py"
> CONFIG
$ cat >>$TESTTMP/goodcommitdates <<EOF
> a0c9c57910584da709d7f4ed9852d66693a45ba7=0
> EOF
$ cat >>$TESTTMP/badcommitdates <<EOF
> a0c9c57910584da709d7f4ed9852d66693a45ba7=1
> EOF
Send unbundlereplay with incorrect expected hash
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server --debug -r d2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server serve --stdio' (glob)
sending hello command
sending between command
remote: 527
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Expected: (master_bookmark, d2e526aacb5100b7c1ddb9b711d2e012e6c69cda). Actual: (master_bookmark, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda)
remote: pushkey-abort: prepushkey hook exited with status 1
remote: transaction abort!
remote: rollback completed
error:pushkey
[1]
Send unbundlereplay with incorrect expected bookmark
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server --debug -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark_2 <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server serve --stdio' (glob)
sending hello command
sending between command
remote: 527
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Expected: (master_bookmark_2, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda). Actual: (master_bookmark, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda)
remote: pushkey-abort: prepushkey hook exited with status 1
remote: transaction abort!
remote: rollback completed
error:pushkey
[1]
Send unbundlereplay with incorrect commit timestamp
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server --debug -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark <$TESTTMP/badcommitdates
running * 'user@dummy' 'hg -R server serve --stdio' (glob)
sending hello command
sending between command
remote: 527
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Expected: (master_bookmark, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda). Actual: (master_bookmark, 893d83f11bf81ce2b895a93d51638d4049d56ce2)
remote: pushkey-abort: prepushkey hook exited with status 1
remote: transaction abort!
remote: rollback completed
error:pushkey
[1]
Send Unbundlereplay
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server --debug -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server serve --stdio' (glob)
sending hello command
sending between command
remote: 527
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Everything seems in order
Send Unbundlereplay to delete a bookmark
$ hg book newbook -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda
$ hg book
master_bookmark 3:c2e526aacb51
newbook 3:c2e526aacb51
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle_delete_bookmark.test.hg --path ssh://user@dummy/server -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda --deleted -b newbook --debug
abort: can't use `--rebasedhead` and `--deleted`
[255]
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle_delete_bookmark.test.hg --path ssh://user@dummy/server --deleted -b newbook --debug
running * 'user@dummy' 'hg -R server serve --stdio' (glob)
sending hello command
sending between command
remote: 527
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: [ReplayVerification] Everything seems in order
$ hg book
master_bookmark 3:c2e526aacb51
What is the new server state?
$ log -r "all()"
o 1 [public;rev=3;c2e526aacb51] master_bookmark
|
o C [public;rev=2;26805aba1e60]
|
o B [public;rev=1;112478962961]
|
o A [public;rev=0;426bada5c675]
Let us set up another servevr repo, this time hgsql
$ cd ..
$ initserver server-hgsql server
$ cd server-hgsql
$ cat >> .hg/hgrc <<CONFIG
> [treemanifest]
> server = True
> [remotefilelog]
> server = True
> shallowtrees = True
> CONFIG
$ DBGD=1 hg backfilltree
-- let's populate the hgsql server with some initial commits by pushing
$ cd ..
$ hg init hgsql-client && cd hgsql-client
$ cat >>.hg/hgrc <<CONFIG
> [paths]
> default=ssh://user@dummy/server-hgsql
> [extensions]
> remotenames=
> CONFIG
$ hg debugdrawdag <<EOF
> C
> |
> B
> |
> A
> EOF
$ hg push --to master_bookmark --create -r tip -q
$ cd ../server-hgsql
$ log -r "all()"
o C [public;rev=2;26805aba1e60] master_bookmark
|
o B [public;rev=1;112478962961]
|
o A [public;rev=0;426bada5c675]
-- let's set up the hook again
$ cat >>.hg/hgrc <<CONFIG
> [hooks]
> prepushkey = python "$TESTTMP/replayverification.py"
> CONFIG
Send unbundlereplay with incorrect expected hash to hgsql server
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server-hgsql --debug -r d2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server-hgsql serve --stdio' (glob)
sending hello command
sending between command
remote: 544
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Expected: (master_bookmark, d2e526aacb5100b7c1ddb9b711d2e012e6c69cda). Actual: (master_bookmark, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda)
remote: pushkey-abort: prepushkey hook exited with status 1
remote: transaction abort!
remote: rollback completed
error:pushkey
[1]
Send unbundlereplay with incorrect expected bookmark to hgsql server
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server-hgsql --debug -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark_2 <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server-hgsql serve --stdio' (glob)
sending hello command
sending between command
remote: 544
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Expected: (master_bookmark_2, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda). Actual: (master_bookmark, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda)
remote: pushkey-abort: prepushkey hook exited with status 1
remote: transaction abort!
remote: rollback completed
error:pushkey
[1]
Send unbundlereplay with incorrect commit timestamp to hgsql server
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg --path ssh://user@dummy/server-hgsql --debug -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark <$TESTTMP/badcommitdates
running * 'user@dummy' 'hg -R server-hgsql serve --stdio' (glob)
sending hello command
sending between command
remote: 544
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Expected: (master_bookmark, c2e526aacb5100b7c1ddb9b711d2e012e6c69cda). Actual: (master_bookmark, 893d83f11bf81ce2b895a93d51638d4049d56ce2)
remote: pushkey-abort: prepushkey hook exited with status 1
remote: transaction abort!
remote: rollback completed
error:pushkey
[1]
#if respondlightly
Send correct unbundlereplay to hgsql server
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg \
> --path ssh://user@dummy/server-hgsql --debug --traceback \
> -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark \
> --config devel.bundle2.debug=on <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server-hgsql serve --stdio' (glob)
sending hello command
sending between command
remote: 544
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: [ReplayVerification] Everything seems in order
bundle2-input: start processing of HG20 stream
bundle2-input: reading bundle2 stream parameters
bundle2-input: start extraction of bundle2 parts
bundle2-input: part header size: 43
bundle2-input: part type: "REPLY:PUSHKEY"
bundle2-input: part id: "0"
bundle2-input: part parameters: 2
bundle2-input: payload chunk size: 0
bundle2-input: part header size: 0
bundle2-input: end of bundle2 stream
#endif
#if respondfully
Send correct unbundlereplay to hgsql server
$ hg sendunbundlereplay --file $TESTDIR/bundles/sendunbundle.test.hg \
> --path ssh://user@dummy/server-hgsql --debug --traceback \
> -r c2e526aacb5100b7c1ddb9b711d2e012e6c69cda -b master_bookmark \
> --config devel.bundle2.debug=on \
> --config sendunbundlereplay.respondlightly=off <$TESTTMP/goodcommitdates
running * 'user@dummy' 'hg -R server-hgsql serve --stdio' (glob)
sending hello command
sending between command
remote: 544
remote: capabilities:* unbundlereplay* (glob)
remote: 1
sending unbundlereplay command
remote: pushing 1 changeset:
remote: a0c9c5791058 1
remote: 1 new changeset from the server will be downloaded
remote: [ReplayVerification] Everything seems in order
bundle2-input: start processing of HG20 stream
bundle2-input: reading bundle2 stream parameters
bundle2-input: start extraction of bundle2 parts
bundle2-input: part header size: 29
bundle2-input: part type: "CHANGEGROUP"
bundle2-input: part id: "0"
bundle2-input: part parameters: 1
bundle2-input: payload chunk size: 309
bundle2-input: payload chunk size: 0
bundle2-input-part: total payload size 309
bundle2-input: part header size: 17
bundle2-input: part type: "OBSMARKERS"
bundle2-input: part id: "1"
bundle2-input: part parameters: 0
bundle2-input: payload chunk size: 85
bundle2-input: payload chunk size: 0
bundle2-input-part: total payload size 85
bundle2-input: part header size: 43
bundle2-input: part type: "REPLY:PUSHKEY"
bundle2-input: part id: "2"
bundle2-input: part parameters: 2
bundle2-input: payload chunk size: 0
bundle2-input: part header size: 0
bundle2-input: end of bundle2 stream
#endif
What is the new hgsql server state?
$ log -r "all()"
o 1 [public;rev=3;c2e526aacb51] master_bookmark
|
o C [public;rev=2;26805aba1e60]
|
o B [public;rev=1;112478962961]
|
o A [public;rev=0;426bada5c675]