Debian Codegraph @

python/mozversioncontrol/test/test_workdir_outgoing.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 import os
6
7 import mozunit
8
9 from mozversioncontrol import get_repository_object
10
11 STEPS = {
12 "hg": [
13 """
14 echo "bar" >> bar
15 echo "baz" > baz
16 hg add baz
17 hg rm foo
18 """,
19 """
20 hg commit -m "Remove foo; modify bar; add baz"
21 """,
22 """
23 echo ooka >> baz
24 echo newborn > baby
25 hg add baby
26 """,
27 """
28 hg commit -m "Modify baz; add baby"
29 """,
30 ],
31 "git": [
32 """
33 echo "bar" >> bar
34 echo "baz" > baz
35 git add baz
36 git rm foo
37 """,
38 """
39 git commit -am "Remove foo; modify bar; add baz"
40 """,
41 """
42 echo ooka >> baz
43 echo newborn > baby
44 git add baz baby
45 """,
46 """
47 git commit -m "Modify baz; add baby"
48 """,
49 ],
50 "jj": [
51 """
52 echo "bar" >> bar
53 echo "baz" > baz
54 rm foo
55 jj log -n0 # snapshot, since bug 1962245 suppresses automatic ones
56 """,
57 """
58 jj commit -m "Remove foo; modify bar; add baz"
59 """,
60 """
61 echo ooka >> baz
62 echo newborn > baby
63 jj log -n0 # snapshot, since bug 1962245 suppresses automatic ones
64 """,
65 """
66 jj describe -m "Modify baz; add baby"
67 """,
68 ],
69 }
70
71
72 def assert_files(actual, expected):
73 assert set(map(os.path.basename, actual)) == set(expected)
74
75
76 def test_workdir_outgoing(repo):
77 vcs = get_repository_object(repo.dir)
78 assert vcs.path == str(repo.dir)
79
80 remote_path = {
81 "hg": "../remoterepo",
82 "git": "upstream/master",
83 "jj": "master@upstream",
84 }[repo.vcs]
85
86 # Mutate files.
87 repo.execute_next_step()
88
89 assert_files(vcs.get_changed_files("A", "all"), ["baz"])
90 assert_files(vcs.get_changed_files("AM", "all"), ["bar", "baz"])
91 assert_files(vcs.get_changed_files("D", "all"), ["foo"])
92 if repo.vcs == "git":
93 assert_files(vcs.get_changed_files("AM", mode="staged"), ["baz"])
94 else:
95 # Mercurial and jj do not use a staging area (and ignore the mode
96 # parameter.)
97 assert_files(vcs.get_changed_files("AM", "unstaged"), ["bar", "baz"])
98 if repo.vcs != "jj":
99 # Everything is already committed in jj, and therefore outgoing.
100 assert_files(vcs.get_outgoing_files("AMD"), [])
101 assert_files(vcs.get_outgoing_files("AMD", remote_path), [])
102
103 # Create a commit.
104 repo.execute_next_step()
105
106 assert_files(vcs.get_changed_files("AMD", "all"), [])
107 assert_files(vcs.get_changed_files("AMD", "staged"), [])
108 assert_files(vcs.get_outgoing_files("AMD"), ["bar", "baz", "foo"])
109 assert_files(vcs.get_outgoing_files("AMD", remote_path), ["bar", "baz", "foo"])
110
111 # Mutate again.
112 repo.execute_next_step()
113
114 assert_files(vcs.get_changed_files("A", "all"), ["baby"])
115 assert_files(vcs.get_changed_files("AM", "all"), ["baby", "baz"])
116 assert_files(vcs.get_changed_files("D", "all"), [])
117
118 # Create a second commit.
119 repo.execute_next_step()
120
121 assert_files(vcs.get_outgoing_files("AM"), ["bar", "baz", "baby"])
122 assert_files(vcs.get_outgoing_files("AM", remote_path), ["bar", "baz", "baby"])
123 if repo.vcs == "git":
124 assert_files(vcs.get_changed_files("AM", rev="HEAD~1"), ["bar", "baz"])
125 assert_files(vcs.get_changed_files("AM", rev="HEAD"), ["baby", "baz"])
126 elif repo.vcs == "hg":
127 assert_files(vcs.get_changed_files("AM", rev=".^"), ["bar", "baz"])
128 assert_files(vcs.get_changed_files("AM", rev="."), ["baby", "baz"])
129 assert_files(vcs.get_changed_files("AM", rev=".^::"), ["bar", "baz", "baby"])
130 assert_files(vcs.get_changed_files("AM", rev="modifies(baz)"), ["baz", "baby"])
131 elif repo.vcs == "jj":
132 assert_files(vcs.get_changed_files("AM", rev="@-"), ["bar", "baz"])
133 assert_files(vcs.get_changed_files("AM", rev="@"), ["baby", "baz"])
134 assert_files(vcs.get_changed_files("AM", rev="@-::"), ["bar", "baz", "baby"])
135 # Currently no direct equivalent of `modifies(baz)`. `files(baz)` will
136 # also select changes that added or deleted baz, and the diff_filter
137 # will applied be too late.
138 assert_files(
139 vcs.get_changed_files("AMD", rev="files(baz)"),
140 ["foo", "baz", "baby", "bar"],
141 )
142
143
144 if __name__ == "__main__":
145 mozunit.main()