| 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 mozunit |
| 6 |
|
| 7 |
from mozversioncontrol import get_repository_object |
| 8 |
|
| 9 |
STEPS = { |
| 10 |
"hg": [ |
| 11 |
""" |
| 12 |
echo bar >> bar |
| 13 |
hg commit -m "FIRST PATCH" |
| 14 |
""", |
| 15 |
""" |
| 16 |
printf "baz\\r\\nqux" > baz |
| 17 |
hg add baz |
| 18 |
hg commit -m "SECOND PATCH" |
| 19 |
""", |
| 20 |
], |
| 21 |
"git": [ |
| 22 |
""" |
| 23 |
echo bar >> bar |
| 24 |
git add bar |
| 25 |
git commit -m "FIRST PATCH" |
| 26 |
""", |
| 27 |
""" |
| 28 |
printf "baz\\r\\nqux" > baz |
| 29 |
git -c core.autocrlf=false add baz |
| 30 |
git commit -m "SECOND PATCH" |
| 31 |
""", |
| 32 |
], |
| 33 |
"jj": [ |
| 34 |
""" |
| 35 |
jj new -m "FIRST PATCH" |
| 36 |
echo bar >> bar |
| 37 |
""", |
| 38 |
""" |
| 39 |
jj new -m "SECOND PATCH" |
| 40 |
printf "baz\\r\\nqux" > baz |
| 41 |
jj log -n0 # snapshot, since bug 1962245 suppresses automatic ones |
| 42 |
""", |
| 43 |
], |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
def test_get_commit_patches(repo): |
| 48 |
vcs = get_repository_object(repo.dir) |
| 49 |
nodes = [] |
| 50 |
|
| 51 |
# Create some commits and note the SHAs. |
| 52 |
repo.execute_next_step() |
| 53 |
nodes.append(vcs.head_ref) |
| 54 |
|
| 55 |
repo.execute_next_step() |
| 56 |
nodes.append(vcs.head_ref) |
| 57 |
|
| 58 |
patches = vcs.get_commit_patches(nodes) |
| 59 |
|
| 60 |
assert len(patches) == 2 |
| 61 |
# Assert the patches are returned in the correct order. |
| 62 |
assert b"FIRST PATCH" in patches[0] |
| 63 |
assert b"SECOND PATCH" in patches[1] |
| 64 |
# Assert the CRLF are correctly preserved. |
| 65 |
assert b"baz\r\n" in patches[1] |
| 66 |
|
| 67 |
|
| 68 |
if __name__ == "__main__": |
| 69 |
mozunit.main() |