== Steps to Reproduce ==
1. With hosted Mercurial repository, ensure local clone is in matching state (local `master` bookmark points to same changeset upstream)
2. Ensure `master` bookmark is active (`hg up master`)
3. Modify some file, commit
4. Attempt to push the changeset upstream using the SSH protocol
```lang=console,name=ssh-push-exception,counterexample,lines=10
cspeckrun@specktop ~/P/n/hgtest> hg pus
pushing to ssh://phab-devel.code/diffusion/HGTEST/hgtest/
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
remote: [2015-10-26 22:49:01] EXCEPTION: (CommandException) Command failed with error #255!
remote: COMMAND
remote: hg log --template '{node}' --rev 'ancestor('\''e924773ad453bceb5122c5ac67f1fd5859f3e609'\'', '\''fb1da8a86b9ca51cb9f201b52edd0470ee808eda'\'')'
remote:
remote: STDOUT
remote: (empty)
remote:
remote: STDERR
remote: abort: unknown revision 'fb1da8a86b9ca51cb9f201b52edd0470ee808eda'!
remote: at [<phutil>/src/future/exec/ExecFuture.php:416]
remote: arcanist(head=master, ref.master=3308da5f8fbe), phabricator(head=master, ref.master=cea633f698da), phutil(head=master, ref.master=d5b4421792e5)
remote: #0 ExecFuture::resolvex() called at [<phabricator>/src/applications/repository/storage/PhabricatorRepository.php:346]
remote: #1 PhabricatorRepository::execxLocalCommand(string, string, string) called at [<phabricator>/src/applications/diffusion/engine/DiffusionCommitHookEngine.php:968]
remote: #2 DiffusionCommitHookEngine::findMercurialPushKeyRefUpdates() called at [<phabricator>/src/applications/diffusion/engine/DiffusionCommitHookEngine.php:693]
remote: #3 DiffusionCommitHookEngine::findMercurialRefUpdates() called at [<phabricator>/src/applications/diffusion/engine/DiffusionCommitHookEngine.php:222]
remote: #4 DiffusionCommitHookEngine::findRefUpdates() called at [<phabricator>/src/applications/diffusion/engine/DiffusionCommitHookEngine.php:124]
remote: #5 DiffusionCommitHookEngine::execute() called at [<phabricator>/scripts/repository/commit_hook.php:133]
remote: pushkey-abort: prepushkey.phabricator hook exited with status 255
remote: transaction abort!
remote: rollback completed
abort: updating bookmark master failed!
```
According to the output, the two arguments passed into the `ancestor` revset are
1. `e924773ad453bceb5122c5ac67f1fd5859f3e609` is the current `master` upstream, prior to any updates
2. `fb1da8a86b9ca51cb9f201b52edd0470ee808eda` is the new changeset being pushed.
It looks like the `prepushkey` Mercurial hook might be running prior to the commit/changeset being applied, but from what I can tell this execution path is the first thing it does when the hook is executed, and hasn't changed recently.
As a precaution to the recent `bundle2` changes, I tried commenting out these lines (and restarting services) - however that did not seem to affect anything:
https://secure.phabricator.com/diffusion/P/browse/master/src/applications/diffusion/ssh/DiffusionMercurialServeSSHWorkflow.php;cea633f698daad27d5e2b781124198d9f0767878$112-113
|**phabricator**|cea633f698daad27d5e2b781124198d9f0767878|
|**arcanist**|3308da5f8fbe9de8c9c2a25646a5704eca323851|
|**libphutil**|d5b4421792e5829b7a760c55dbf9adbc70669455|
|**server hg**|Mercurial Distributed SCM (version 3.5.1)|
|**client hg**|Mercurial Distributed SCM (version 3.5.2)|
== Workaround ==
1. Align the `master` bookmark with server: `hg book -r xxx master -f`
2. Push outgoing commits: `hg pus`
3. Update `master` to now-public changeset: `hg book -r tip master`
4. Push just the bookmark: `hg pus -r master`
What's weird is that pushing over http seems to work fine:
```lang=console,name=http-push,lines=10
cspeckrun@specktop ~/P/n/hgtest> hg pus http
pushing to http://Administrator:***@192.168.0.133/diffusion/HGTEST/hgtest
searching for changes
remote: adding changesets
remote: adding manifests
remote: adding file changes
remote: added 1 changesets with 1 changes to 1 files
updating bookmark master
```
== Testing on rHGTEST ==
This is reproducible on rHGTEST using hg 3.6.3 - the error output is a little different from above, which was done using an earlier version of hg on the client.
```lang=console,name=rHGTEST push exception,counterexample,lines=10
cspeckrun@specktop ~/P/p/hg-test> hg pus --debug --traceback -v
no terminfo entry for sitm
no terminfo entry for dim
pushing to ssh://dweller@secure.phabricator.com/diffusion/HGTEST/hg-test/
running ssh dweller@secure.phabricator.com 'hg -R diffusion/HGTEST/hg-test/ serve --stdio'
sending hello command
sending between command
remote: 145
remote: capabilities: lookup changegroupsubset branchmap pushkey known getbundle unbundlehash batch stream unbundle=HG10GZ,HG10BZ,HG10UN httpheader=1024
remote: 1
query 1; heads
sending batch command
searching for changes
all remote heads known locally
preparing listkeys for "phases"
sending listkeys command
received listkey for "phases": 15 bytes
checking for updated bookmarks
preparing listkeys for "bookmarks"
sending listkeys command
received listkey for "bookmarks": 47 bytes
sending branchmap command
sending branchmap command
preparing listkeys for "bookmarks"
sending listkeys command
received listkey for "bookmarks": 47 bytes
1 changesets found
list of changesets:
2a4fde99cf721d394a19f75208ff6c3b6d94e4bd
sending unbundle command
remote: abort: stream ended unexpectedly (got 0 bytes, expected 6)
Traceback (most recent call last):
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/dispatch.py", line 187, in _runcatch
return _dispatch(req)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/dispatch.py", line 920, in _dispatch
cmdpats, cmdoptions)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/dispatch.py", line 679, in runcommand
ret = _runcommand(ui, options, cmd, d)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/extensions.py", line 183, in closure
return func(*(args + a), **kw)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/hgext/pager.py", line 139, in pagecmd
return orig(ui, options, cmd, cmdfunc)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/extensions.py", line 183, in closure
return func(*(args + a), **kw)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/hgext/color.py", line 525, in colorcmd
return orig(ui_, opts, cmd, cmdfunc)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/dispatch.py", line 1051, in _runcommand
return checkargs()
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/dispatch.py", line 1011, in checkargs
return cmdfunc()
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/dispatch.py", line 917, in <lambda>
d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/util.py", line 801, in check
return func(*args, **kwargs)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/extensions.py", line 183, in closure
return func(*(args + a), **kw)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/util.py", line 801, in check
return func(*args, **kwargs)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/hgext/mq.py", line 3528, in mqcommand
return orig(ui, repo, *args, **kwargs)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/util.py", line 801, in check
return func(*args, **kwargs)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/commands.py", line 5428, in push
opargs=opts.get('opargs'))
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/exchange.py", line 373, in push
_pushchangeset(pushop)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/exchange.py", line 854, in _pushchangeset
pushop.repo.url())
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/wireproto.py", line 351, in unbundle
ret, output = self._callpush("unbundle", cg, heads=heads)
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/sshpeer.py", line 271, in _callpush
r = self._recv()
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/sshpeer.py", line 299, in _recv
self._abort(error.ResponseError(_("unexpected response:"), l))
File "/usr/local/Cellar/mercurial/3.6.3/lib/python2.7/site-packages/mercurial/sshpeer.py", line 212, in _abort
raise exception
ResponseError: ('unexpected response:', '')
abort: unexpected response: empty string
```