Skip to content
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

Support GIT_OBJECT_DIRECTORY environment variable #1000

Closed
acbits opened this issue Mar 27, 2020 · 2 comments
Closed

Support GIT_OBJECT_DIRECTORY environment variable #1000

acbits opened this issue Mar 27, 2020 · 2 comments

Comments

@acbits
Copy link

acbits commented Mar 27, 2020

When using GIT_OBJECT_DIRECTORY to store git objects, a statement like
git.Repo('someproject') fails. This is due to is_git_dir() in git/repo/fun.py making an assumption that there will be a objects directory under .git which isn't the case when GIT_OBJECT_DIRECTORY is defined and being used.

A fix like the attached patch should solve the problem, though there might be more fixes needed in other places. This fix alone solves my particular workflow for now.

diff --git a/git/repo/fun.py b/git/repo/fun.py
index 784a70bf3..e3a7bc57a 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -35,7 +35,8 @@ def is_git_dir(d):
             There is the unlikely danger to throw if we see directories which just look like a worktree dir,
             but are none."""
     if osp.isdir(d):
-        if osp.isdir(osp.join(d, 'objects')) and osp.isdir(osp.join(d, 'refs')):
+        if (osp.isdir(osp.join(d, 'objects')) or os.environ.has_key('GIT_OBJECT_DIRECTORY')) \
+           and osp.isdir(osp.join(d, 'refs')):
             headref = osp.join(d, 'HEAD')
             return osp.isfile(headref) or \
                 (osp.islink(headref) and

Byron added a commit that referenced this issue Apr 11, 2020
…subdirectory

This will work for default git object databases only, which use git as
object database directly.

Related to #1000
@Byron
Copy link
Member

Byron commented Apr 11, 2020

Thanks a lot! You are probably right - the fix won't work in all cases, especially since GitPython has an optional pure-python object database implementation which certainly doesn't pick that up.

However, I believe it's worth having this fix to improve the situation in the most common case.

It looks like the patch fails on CI, but due to travis not being accessible from my current location, I don't really see what it is. Will keep you posted.

Byron added a commit that referenced this issue Apr 11, 2020
…bjects' subdirectory"

This reverts commit eb792ea.

Seems to break CI
Related to #1000
Byron added a commit that referenced this issue Apr 11, 2020
@Byron Byron added this to the v3.1.1 - Bugfixes milestone Apr 11, 2020
@Byron
Copy link
Member

Byron commented Apr 11, 2020

Great, I moved the project to github actions, and now the patch is included.
Today or tomorrow I will create a new release as well.

@Byron Byron closed this as completed Apr 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants