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