fune/python/mozversioncontrol/test/test_workdir_outgoing.py
Andrew Halberstadt 812d9fb038 Bug 1413922 - [mozversioncontrol] Always use hglib.client if available and fall back to subprocesses if not, r=gps
Most HG commands use subprocesses, even if a context manager (and therefore an
hglib client) has been created. There are only two commands that make use of
the client, but they *only* work inside a context manager. I don't think
there are any technical reason these two commands *need* to use the context
manager.

This patch merges the HgRepository._run_in_client function with
HgRepository._run(). If a client exists, that will be used, otherwise a
subprocess will be used.

Differential Revision: https://phabricator.services.mozilla.com/D1809

--HG--
extra : moz-landing-system : lando
2018-07-10 20:41:49 +00:00

69 lines
1.7 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/.
from __future__ import absolute_import
import os
import mozunit
from mozversioncontrol import get_repository_object
STEPS = {
'hg': [
"""
echo "bar" >> bar
echo "baz" > baz
hg add baz
hg rm foo
""",
"""
hg commit -m "Remove foo; modify bar; add baz"
""",
],
'git': [
"""
echo "bar" >> bar
echo "baz" > baz
git add baz
git rm foo
""",
"""
git commit -am "Remove foo; modify bar; add baz"
"""
]
}
def assert_files(actual, expected):
assert set(map(os.path.basename, actual)) == set(expected)
def test_workdir_outgoing(repo):
vcs = get_repository_object(repo.strpath)
assert vcs.path == repo.strpath
remotepath = '../remoterepo' if repo.vcs == 'hg' else 'upstream/master'
next(repo.step)
assert_files(vcs.get_changed_files('AM', 'all'), ['bar', 'baz'])
if repo.vcs == 'git':
assert_files(vcs.get_changed_files('AM', mode='staged'), ['baz'])
elif repo.vcs == 'hg':
assert_files(vcs.get_changed_files('AM', 'staged'), ['bar', 'baz'])
assert_files(vcs.get_outgoing_files('AM'), [])
assert_files(vcs.get_outgoing_files('AM', remotepath), [])
next(repo.step)
assert_files(vcs.get_changed_files('AM', 'all'), [])
assert_files(vcs.get_changed_files('AM', 'staged'), [])
assert_files(vcs.get_outgoing_files('AM'), ['bar', 'baz'])
assert_files(vcs.get_outgoing_files('AM', remotepath), ['bar', 'baz'])
if __name__ == '__main__':
mozunit.main()