mirror of
https://github.com/facebook/sapling.git
synced 2024-10-08 07:49:11 +03:00
ef6f17696e
Summary: Note that the original motivation for this test was to verify `savebackup()` and `restorebackup()` in `eden_dirstate`: D5485950. As singhsrb recently updated Mercurial to remove a redundant commit when doing `hg amend` in upstream Mercurial (https://phab.mercurial-scm.org/D636), I suspect that is responsible for the change in behavior that is necessitates the change in our test. We now use a precommit hook failure to trigger the rollback rather than an editor with a non-zero exit code. As you can see, `transaction abort!\nrollback completed\n` still appears in the error message, so we are still verifying the behavior of interest. Differential Revision: D5826751 fbshipit-source-id: bcbf00042c3f26b6e9aa1a980060a0561725a56c
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
#
|
|
# Copyright (c) 2016-present, Facebook, Inc.
|
|
# All rights reserved.
|
|
#
|
|
# This source code is licensed under the BSD-style license found in the
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
from .lib.hg_extension_test_base import hg_test
|
|
from ..lib import hgrepo
|
|
|
|
|
|
@hg_test
|
|
class RollbackTest:
|
|
def populate_backing_repo(self, repo):
|
|
repo.write_file('first', '')
|
|
self._commit1 = repo.commit('first commit')
|
|
|
|
def test_commit_with_precommit_failure_should_trigger_rollback(self):
|
|
original_commits = self.repo.log()
|
|
|
|
self.repo.write_file('first', 'THIS IS CHANGED')
|
|
self.assert_status({'first': 'M'})
|
|
|
|
with self.assertRaises(hgrepo.HgError) as context:
|
|
self.hg(
|
|
'commit', '-m', 'Precommit hook should fail, causing rollback.',
|
|
'--config', 'hooks.pretxncommit=false'
|
|
)
|
|
expected_msg = (
|
|
b'transaction abort!\nrollback completed\n'
|
|
b'abort: pretxncommit hook exited with status 1\n'
|
|
)
|
|
self.assertIn(expected_msg, context.exception.stderr)
|
|
|
|
self.assertEqual(
|
|
original_commits,
|
|
self.repo.log(),
|
|
msg='Failed precommit hook should abort the change and '
|
|
'leave Hg in the original state.'
|
|
)
|
|
self.assert_status({'first': 'M'})
|