Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: always set GIT_CEILING_DIRECTORIES #636

Merged
merged 4 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion asv/plugins/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ def _run_git(self, args, cwd=True, **kwargs):
if cwd is True:
cwd = self._path
kwargs['cwd'] = cwd
return util.check_output([self._git] + args, **kwargs)
env = dict(kwargs.pop('env', os.environ))
if cwd is not None:
prev = env.get('GIT_CEILING_DIRECTORIES')
env['GIT_CEILING_DIRECTORIES'] = os.pathsep.join(
[os.path.join(os.path.abspath(cwd), os.pardir)]
+ ([prev] if prev is not None else []))
return util.check_output([self._git] + args, env=env, **kwargs)

def get_new_range_spec(self, latest_result, branch=None):
return '{0}..{1}'.format(latest_result, self.get_branch_name(branch))
Expand Down
6 changes: 6 additions & 0 deletions asv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,12 @@ def get_content(header=None):

log.debug("Running '{0}'".format(' '.join(args)))

if env and WIN and sys.version_info < (3,):
# Environment keys and values cannot be unicode
def _fix_env(s):
return s.encode('mbcs') if isinstance(s, unicode) else s
env = {_fix_env(k): _fix_env(v) for k, v in env.items()}

kwargs = dict(shell=shell, env=env, cwd=cwd,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if WIN:
Expand Down
37 changes: 37 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,40 @@ def test_git_submodule(tmpdir):
r.checkout(checkout_dir, commit_hash_5)
assert os.path.isfile(join(checkout_dir, 'README'))
assert not os.path.isdir(join(checkout_dir, 'sub1'))


@pytest.mark.parametrize('dvcs_type', [
"git",
pytest.mark.skipif(hglib is None, reason="needs hglib")("hg")
])
def test_root_ceiling(dvcs_type, tmpdir):
# Check that git/hg does not try to look for repository in parent
# directories.
tmpdir = six.text_type(tmpdir)
dvcs1 = tools.generate_repo_from_ops(tmpdir, dvcs_type, [("commit", 1)])
dvcs2 = tools.generate_repo_from_ops(tmpdir, dvcs_type, [("commit", 2)])
commit1 = dvcs1.get_branch_hashes()[0]
commit2 = dvcs2.get_branch_hashes()[0]

conf = config.Config()
conf.branches = []
conf.dvcs = dvcs_type
conf.project = join(tmpdir, "repo")
conf.repo = dvcs1.path

r = repo.get_repo(conf)

# Checkout into a subdir inside another repository
workcopy_dir = join(dvcs2.path, "workcopy")
r.checkout(workcopy_dir, commit1)

# Corrupt the checkout
for pth in ['.hg', '.git']:
pth = os.path.join(workcopy_dir, pth)
if os.path.isdir(pth):
shutil.rmtree(pth)

# Operation must fail (commit2 is not in dvcs1), not use the
# parent repository
with pytest.raises(Exception):
r.checkout(workcopy_dir, commit2)
15 changes: 15 additions & 0 deletions test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import os
import sys
import time

Expand Down Expand Up @@ -104,6 +105,20 @@ def test_output_timeout():
assert False, "Expected exception"


def test_env():
code = r"""
import os
print(os.environ['TEST_ASV_FOO'])
print(os.environ['TEST_ASV_BAR'])
"""
env = os.environ.copy()
env['TEST_ASV_FOO'] = 'foo'
# Force unicode string on Python 2
env['TEST_ASV_BAR'] = u'bar'
output = util.check_output([sys.executable, "-c", code], env=env)
assert output.splitlines() == ['foo', 'bar']


# This *does* seem to work, only seems untestable somehow...
# def test_dots(capsys):
# code = r"""
Expand Down