forked from mozilla-firefox/firefox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_try_commit.py
More file actions
39 lines (29 loc) · 1.23 KB
/
test_try_commit.py
File metadata and controls
39 lines (29 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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
from mozversioncontrol.errors import MissingVCSExtension
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.
try:
with vcs.try_commit(commit_message, {"try_task_config.json": "{}"}) as head:
if vcs.name != "src":
assert vcs.get_changed_files(rev=head) == ["try_task_config.json"]
except MissingVCSExtension:
pytest.xfail("Requires the Mercurial evolve extension.")
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()