Get the path of the git root directory of the caller's file
    Raises a RuntimeError if a git repository cannot be found
334561
def get_git_root(index=3):  # type: (int) -> str
    
    path = get_current_path(index=index)
    while True:
        git_path = os.path.join(path, '.git')
        if os.path.isdir(git_path):
            return path
        if os.path.dirname(path) == path:
            raise RuntimeError("Cannot find git root")
        path = os.path.split(path)[0]
578901
def git_root(self):
        
        if not getattr(self, "_git_folder", None):
            root_folder = os.path.abspath(self.parent_dir)
            while not os.path.exists(os.path.join(root_folder, '.git')):
                if root_folder == '/':
                    raise HarpoonError("Couldn't find a .git folder", start_at=self.parent_dir)
                root_folder = os.path.dirname(root_folder)
            self._git_folder = root_folder
        return self._git_folder
968615
def git_root_till_home
      Pathname.new(Dir.pwd).ascend do |dir_pathname|
        return dir_pathname if File.directory?("#{dir_pathname}/.git")
        return nil if dir_pathname.to_s == home_dir
      end
    end
488802
def get_root_dir(self):
        
        if os.path.isdir(self.root_path):
            return self.root_path
        else:
            return os.path.dirname(self.root_path)
896321
def get_repo_relpath(repo, relpath):
    
    from os import path
    if relpath[0:2] == "./":
        return path.join(repo, relpath[2::])
    else:
        from os import chdir, getcwd
        cd = getcwd()
        chdir(path.expanduser(repo))
        result = path.abspath(relpath)
        chdir(cd)
        return result
117872
def git_repo():
    
    try:
        reldir = subprocess.check_output(
            ["git", "rev-parse", "--git-dir"])
        reldir = reldir.decode("utf-8")
        return os.path.basename(os.path.dirname(os.path.abspath(reldir)))
    except subprocess.CalledProcessError:
        return None
238660
def path(cls, ref):
        
        return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path))
1341242
def find_file(path, tgt_env='base', **kwargs):  # pylint: disable=W0613
    '''
    
    '''
    return _gitfs().find_file(path, tgt_env=tgt_env, **kwargs)
918764
function findRepos(callback) {
  var cwd = process.cwd(),
      tasks = [];

  fs.readdir(cwd, function(err, files) {
    if (err) return callback(err);

    var repos = [];
    files.forEach(function(file) {
      if (fs.existsSync(path.join(cwd, file, '.git'))) {
        repos.push(path.join(cwd, file));
      }
    });

    if (repos.length === 0) {
      return callback(new Error('No repositories found'));
    }

    repos.forEach(function(dir) {
      tasks.push(function(done) {
        done(err, git(dir));
      });
    });

    async.series(tasks, function(err, results) {
      callback(err, results);
    });
  });
}
755980
def current_git_dir():
    """"""
    path = os.path.abspath(os.curdir)
    while path != '/':
        if os.path.isdir(os.path.join(path, '.git')):
            return os.path.join(path, '.git')
        path = os.path.dirname(path)
    return None
980986
def extract_repo(path, destination, reference)
      fail 'Git not installed' unless Utils.command? 'git'
      Dir.chdir path do
        system "git archive #{reference} | tar -x -C #{destination}"
      end
    end
1010797
def get_root_path():
    """"""
    return os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir))
1196527
def get_env(path, ignore_git_branch=False):
    """"""
    if 'DEPLOY_ENVIRONMENT' in os.environ:
        return os.environ['DEPLOY_ENVIRONMENT']

    if ignore_git_branch:
        LOGGER.info('Skipping environment lookup from current git branch '
                    '("ignore_git_branch" is set to true in the runway '
                    'config)')
    else:
        # These are not located with the top imports because they throw an
        # error if git isn't installed
        from git import Repo as GitRepo
        from git.exc import InvalidGitRepositoryError

        try:
            b_name = GitRepo(
                path,
                search_parent_directories=True
            ).active_branch.name
            LOGGER.info('Deriving environment name from git branch %s...',
                        b_name)
            return get_env_from_branch(b_name)
        except InvalidGitRepositoryError:
            pass
    LOGGER.info('Deriving environment name from directory %s...', path)
    return get_env_from_directory(os.path.basename(path))
948899
def _to_relative_path(cls, parent_repo, path):
        """"""
        path = to_native_path_linux(path)
        if path.endswith('/'):
            path = path[:-1]
        # END handle trailing slash

        if osp.isabs(path):
            working_tree_linux = to_native_path_linux(parent_repo.working_tree_dir)
            if not path.startswith(working_tree_linux):
                raise ValueError("Submodule checkout path '%s' needs to be within the parents repository at '%s'"
                                 % (working_tree_linux, path))
            path = path[len(working_tree_linux.rstrip('/')) + 1:]
            if not path:
                raise ValueError("Absolute submodule path '%s' didn't yield a valid relative path" % path)
            # end verify converted relative path makes sense
        # end convert to a relative path

        return path
1224317
def get_src_path(self, obj, append_base=True):
        
        path = getsourcefile(obj)
        if self.src_root not in path:
            # this can happen with e.g.
            # inlinefunc-wrapped functions
            if hasattr(obj, "__module__"):
                path = "%s.%s" % (obj.__module__, obj.__name__)
            else:
                path = obj.__name__
            path = path.replace(".", "/")
        pre, post = path.rsplit(self.src_root + "/", 1)

        lineno = self.get_line_no(obj)
        lineno = "" if lineno is None else "#L{}".format(lineno)

        path = self.src_root + "/" + post + lineno
        if append_base:
            path = os.path.join(self.github_link, path)
        return path
742
def find_git_repository(self, path):
        
        while path is not None:
            git_path = os.path.join(path,'.git')
            if os.path.exists(git_path) and os.path.isdir(git_path):
                return path
            path = os.path.dirname(path)
        return None
514902
def repo_root
      return git_directory_path if inside_bare_repo?
      
      if inside_git_directory?
        File.expand_path('..', git_directory_path)
      elsif inside_work_tree?
        execute(git_cmd('rev-parse', '--show-toplevel'))
      else
        raise 'not in git directory or work tree!?'
      end
    end