◐ Shell
reader mode source ↗
Skip to content
Merged
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
28 changes: 21 additions & 7 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import os
import re
import sys

from git.cmd import (
Git,
Expand Down Expand Up @@ -50,8 +51,11 @@
__all__ = ('Repo',)


def _expand_path(p):
return osp.normpath(osp.abspath(osp.expandvars(osp.expanduser(p))))


class Repo(object):
Expand Down Expand Up @@ -90,7 +94,7 @@ class Repo(object):
# Subclasses may easily bring in their own custom types by placing a constructor or type here
GitCommandWrapperType = Git

def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=False):
"""Create a new Repo instance

:param path:
Expand All @@ -116,12 +120,17 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
:raise InvalidGitRepositoryError:
:raise NoSuchPathError:
:return: git.Repo """
epath = path or os.getenv('GIT_DIR')
if not epath:
epath = os.getcwd()
if Git.is_cygwin():
epath = decygpath(epath)
epath = _expand_path(epath or path or os.getcwd())
if not os.path.exists(epath):
raise NoSuchPathError(epath)

Expand All @@ -148,7 +157,7 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
sm_gitpath = find_worktree_git_dir(dotgit)

if sm_gitpath is not None:
self.git_dir = _expand_path(sm_gitpath)
self._working_tree_dir = curpath
break

Expand Down Expand Up @@ -844,7 +853,7 @@ def blame(self, rev, file, incremental=False, **kwargs):
return blames

@classmethod
def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
"""Initialize a git repository at the given path if specified

:param path:
Expand All @@ -862,12 +871,17 @@ def init(cls, path=None, mkdir=True, odbt=DefaultDBType, **kwargs):
the directory containing the database objects, i.e. .git/objects.
It will be used to access all object data

:parm kwargs:
keyword arguments serving as additional options to the git-init command

:return: ``git.Repo`` (the newly created repo)"""
if path:
path = _expand_path(path)
if mkdir and path and not osp.exists(path):
os.makedirs(path, 0o755)

Expand Down
Toggle all file notes Toggle all file annotations