Currently, the caller potentially prepares files, add them to the VCS, and then calls the function to create the commit, does whatever it wants to do with it, then undoes it. With the ultimate goal of not doing local changes to the work tree to act on that try commit (for a push), this change in API makes it so that everything except what do do with the commit is handled by one function, that now takes paths and file contents for the files that were previously created by the caller. Differential Revision: https://phabricator.services.mozilla.com/D214214
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this,
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
import mozunit
|
|
import pytest
|
|
|
|
from mozversioncontrol import get_repository_object
|
|
|
|
|
|
@pytest.mark.xfail(reason="Requires the Mercurial evolve extension.", strict=False)
|
|
def test_try_commit(repo):
|
|
commit_message = "try commit message"
|
|
vcs = get_repository_object(repo.dir)
|
|
initial_head_ref = vcs.head_ref
|
|
|
|
# Create a non-empty commit.
|
|
with vcs.try_commit(commit_message, {"try_task_config.json": "{}"}) as head:
|
|
assert vcs.get_changed_files(rev=head) == ["try_task_config.json"]
|
|
|
|
assert (
|
|
vcs.head_ref == initial_head_ref
|
|
), "We should have reverted to previous head after try_commit"
|
|
|
|
# Create an empty commit.
|
|
with vcs.try_commit(commit_message) as head:
|
|
assert vcs.get_changed_files(rev=head) == []
|
|
|
|
assert (
|
|
vcs.head_ref == initial_head_ref
|
|
), "We should have reverted to previous head after try_commit"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
mozunit.main()
|