Skip to content

Commit

Permalink
git: always set GIT_CEILING_DIRECTORIES
Browse files Browse the repository at this point in the history
By default when git don't find a repository in current working dir, it
search for git repository in parent directories.

This may lead to unwanted behavior when the benchmarked repository is
nested inside other repo since in `checkout()` we expect to given path
to be the repository and re-clone it if it's not. When the given path is
not a repository we may run git commands (like a checkout) on unrelated
repo.

This bug occur in appveyor tests where `--basetemp` is set to a
directory inside asv checkout, and `test_repo.test_repo_git()` run a
checkout() after `rm -rf .git` causing tests to run a `git checkout -f
master` on asv repo.

Always set GIT_CEILING_DIRECTORIES to parent directory of the repo path
to avoid git looking at parent directories.

We don't have similar issue with hglib since it use the `-R` option to
explicitly set the repository root.
  • Loading branch information
philpep committed Apr 30, 2018
1 parent 4e8d882 commit 0196448
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion asv/plugins/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ 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:
env['GIT_CEILING_DIRECTORIES'] = ':'.join([
os.path.join(cwd, os.pardir),
env.get('GIT_CEILING_DIRECTORIES', '')])
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

0 comments on commit 0196448

Please sign in to comment.