Debian Codegraph @

python/mozversioncontrol/test/test_update.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 from subprocess import CalledProcessError
6
7 import mozunit
8 import pytest
9
10 from mozversioncontrol import get_repository_object
11
12 STEPS = {
13 "hg": [
14 """
15 echo "bar" >> bar
16 echo "baz" > foo
17 hg commit -m "second commit"
18 """,
19 """
20 echo "foobar" > foo
21 """,
22 ],
23 "git": [
24 """
25 echo "bar" >> bar
26 echo "baz" > foo
27 git add *
28 git commit -m "second commit"
29 """,
30 """
31 echo "foobar" > foo
32 """,
33 ],
34 "jj": [
35 """
36 echo "bar" >> bar
37 echo "baz" > foo
38 jj commit -m "second commit"
39 """,
40 """
41 echo "foobar" > foo
42 """,
43 ],
44 }
45
46
47 def test_update(repo):
48 vcs = get_repository_object(repo.dir)
49 rev0 = vcs.head_ref
50
51 # Create a commit with modified `foo` and `bar`.
52 repo.execute_next_step()
53 rev1 = vcs.head_ref
54 assert rev0 != rev1
55
56 if repo.vcs == "hg":
57 vcs.update(".~1")
58 elif repo.vcs == "git":
59 vcs.update("HEAD~1")
60 elif repo.vcs == "jj":
61 vcs.edit("@-")
62 assert vcs.head_ref == rev0
63
64 if repo.vcs != "jj":
65 vcs.update(rev1)
66 else:
67 vcs.update(rev0)
68 rev1 = vcs.head_ref
69 assert vcs.head_ref == rev1
70
71 # Modify `foo` and update. Should fail with dirty working directory.
72 repo.execute_next_step()
73 if repo.vcs != "jj":
74 with pytest.raises(CalledProcessError):
75 vcs.update(rev0)
76 assert vcs.head_ref == rev1
77 else:
78 # jj doesn't have a "dirty working directory".
79 pass
80
81
82 if __name__ == "__main__":
83 mozunit.main()