Repository: iterative/dvc

Issue:
tests: fix gc test on mac
```
=================================== FAILURES ===================================

_________________________ TestGCMultipleDvcRepos.test __________________________

[gw0] darwin -- Python 3.7.3 /Users/travis/.pyenv/versions/3.7.3/Python.framework/Versions/3.7/bin/python3.7



self = <tests.func.test_gc.TestGCMultipleDvcRepos testMethod=test>



    def setUp(self):

        super(TestGCMultipleDvcRepos, self).setUp()

        self.additional_path = TestDir.mkdtemp()

        self.additional_git = Repo.init(self.additional_path)

>       self.additional_dvc = DvcRepo.init(self.additional_path)



/Users/travis/build/iterative/dvc/tests/func/test_gc.py:118: 

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

/Users/travis/build/iterative/dvc/dvc/repo/__init__.py:117: in init

    init(root_dir=root_dir, no_scm=no_scm, force=force)

/Users/travis/build/iterative/dvc/dvc/repo/init.py:88: in init

    scm.add([config.config_file])

/Users/travis/build/iterative/dvc/dvc/scm/git/__init__.py:161: in add

    self.git.index.add(paths)

/Users/travis/.pyenv/versions/3.7.3/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/base.py:735: in add

    paths, entries = self._preprocess_add_items(items)

/Users/travis/.pyenv/versions/3.7.3/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/base.py:575: in _preprocess_add_items

    paths.append(self._to_relative_path(item))

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 



self = <git.index.base.IndexFile object at 0x108d6d3b8>

path = '/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/dvc-test.26471.cohcc8c3.7fdb195c-d467-45fc-8b3f-3441166a6328/.dvc/config'



    def _to_relative_path(self, path):

        """:return: Version of path relative to our git directory or raise ValueError

        if it is not within our git direcotory"""

        if not osp.isabs(path):

            return path

        if self.repo.bare:

            raise InvalidGitRepositoryError("require non-bare repository")

        if not path.startswith(self.repo.working_tree_dir):

>           raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))

E           ValueError: Absolute path '/private/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/dvc-test.26471.cohcc8c3.7fdb195c-d467-45fc-8b3f-3441166a6328/.dvc/config' is not in git repository at '/var/folders/my/m6ynh3bn6tq06h7xr3js0z7r0000gn/T/dvc-test.26471.cohcc8c3.7fdb195c-d467-45fc-8b3f-3441166a6328'



/Users/travis/.pyenv/versions/3.7.3/Python.framework/Versions/3.7/lib/python3.7/site-packages/git/index/base.py:565: ValueError

```


Discussion:

Resolving patch:
diff --git a/dvc/repo/init.py b/dvc/repo/init.py
--- a/dvc/repo/init.py
+++ b/dvc/repo/init.py
@@ -59,7 +59,7 @@ def init(root_dir=os.curdir, no_scm=False, force=False):
     Raises:
         KeyError: Raises an exception.
     """
-    root_dir = os.path.abspath(root_dir)
+    root_dir = os.path.realpath(root_dir)
     dvc_dir = os.path.join(root_dir, Repo.DVC_DIR)
     scm = SCM(root_dir)
     if isinstance(scm, NoSCM) and not no_scm:
diff --git a/dvc/scm/git/__init__.py b/dvc/scm/git/__init__.py
--- a/dvc/scm/git/__init__.py
+++ b/dvc/scm/git/__init__.py
@@ -42,10 +42,10 @@ def __init__(self, root_dir=os.curdir, repo=None):
         from git.exc import InvalidGitRepositoryError
 
         try:
-            self.git = git.Repo(root_dir)
+            self.git = git.Repo(self.root_dir)
         except InvalidGitRepositoryError:
             msg = "{} is not a git repository"
-            raise SCMError(msg.format(root_dir))
+            raise SCMError(msg.format(self.root_dir))
 
         # NOTE: fixing LD_LIBRARY_PATH for binary built by PyInstaller.
         # http://pyinstaller.readthedocs.io/en/stable/runtime-information.html


Test patch: