fune/python/mozversioncontrol/test/test_get_mozilla_remote_args.py
Connor Sheehan 529144ec47 Bug 1869733: consider all official remotes when finding base ref and patches r=zeid
A previous patch added parsing `git remote -v`, preferring
`mozilla-unified` as the official upstream remote and falling
back to the first official-looking remote if unified was not
found. We assumed that a developer is either using mozilla-unified,
or is using a single-headed repo like central. This overlooks
the fact that it is possible to clone from central, and then
pull other repos in, creating a repo with multiple official
remotes.

Update the `get_upstream_remote` function to find all official
looking remotes instead of a single official remote, and change
the `get_remote_arg` function to return a list of `--remotes`
arguments to be passed to various Git commands. This allows
Git to take all official remotes into consideration and more
precisely find the commits which are not present on any official
upsteams.

Add a test for `get_mozilla_remote_args` while we are here.

Differential Revision: https://phabricator.services.mozilla.com/D199637
2024-01-25 20:04:09 +00:00

47 lines
1.2 KiB
Python

# 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
from mozversioncontrol import get_repository_object
STEPS = {
"hg": [],
"git": [
"git remote add blah https://example.com/blah",
"""
git remote add unified hg::https://hg.mozilla.org/mozilla-unified
git remote add central hg::https://hg.mozilla.org/central
git remote add try hg::https://hg.mozilla.org/try
""",
],
}
def test_get_upstream_remotes(repo):
# Test is only relevant for Git.
if not repo.vcs == "git":
return
repo.execute_next_step()
vcs = get_repository_object(repo.dir)
remotes = vcs.get_mozilla_remote_args()
assert remotes == [
"--remotes"
], "Default `--remotes` passed without finding official remote."
repo.execute_next_step()
remotes = sorted(vcs.get_mozilla_remote_args())
assert remotes == [
"--remotes=central",
"--remotes=unified",
], "Multiple non-try remote arguments should be found."
if __name__ == "__main__":
mozunit.main()