Skip to content

FIX #535: expand also GIT_DIR var on Repo-construction #537

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

Merged
merged 5 commits into from
Oct 22, 2016
Merged
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
repo = Repo("~/Development/git-python.git")
repo = Repo("$REPOSITORIES/Development/git-python.git")

if `None, current-directory is used.
The :envvar:`GIT_DIR` if set and not empty takes precendance over this parameter.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The environment variable taking precedence over the specified path seems error prone and undesirable. For instance, with GIT_DIR set, you can no longer do something like this:

repo_1 = git.Repo('/path/to/repo1')
repo_2 = git.Repo('/path/to/repo2')

I think GIT_DIR as a fallback makes sense (if path is None for instance). However, is there any reason to prefer it if an explicit path is provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion moved to original issue #535

:param odbt:
Object DataBase type - a type which is constructed by providing
the directory containing the database objects, i.e. .git/objects. It will
Expand All @@ -136,17 +138,19 @@ def __init__(self, path=None, odbt=DefaultDBType, search_parent_directories=Fals
:raise InvalidGitRepositoryError:
:raise NoSuchPathError:
:return: git.Repo """
epath = _expand_path(path or os.getcwd())
self.git = None # should be set for __del__ not to fail in case we raise
epath = os.getenv('GIT_DIR')
epath = _expand_path(epath or path or os.getcwd())
if not os.path.exists(epath):
raise NoSuchPathError(epath)

self.working_dir = None
self._working_tree_dir = None
self.git_dir = None
curpath = os.getenv('GIT_DIR', epath)

# walk up the path to find the .git dir
## Walk up the path to find the `.git` dir.
#
curpath = epath
while curpath:
# ABOUT os.path.NORMPATH
# It's important to normalize the paths, as submodules will otherwise initialize their
Expand Down