summaryrefslogtreecommitdiff
path: root/git/repo/fun.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/repo/fun.py')
-rw-r--r--git/repo/fun.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/git/repo/fun.py b/git/repo/fun.py
index 39e55880..6aefd9d6 100644
--- a/git/repo/fun.py
+++ b/git/repo/fun.py
@@ -1,5 +1,6 @@
"""Package with general repository related functions"""
import os
+import stat
from string import digits
from git.compat import xrange
@@ -17,7 +18,7 @@ from git.cmd import Git
__all__ = ('rev_parse', 'is_git_dir', 'touch', 'find_submodule_git_dir', 'name_to_object', 'short_to_long', 'deref_tag',
- 'to_commit')
+ 'to_commit', 'find_worktree_git_dir')
def touch(filename):
@@ -47,6 +48,25 @@ def is_git_dir(d):
return False
+def find_worktree_git_dir(dotgit):
+ """Search for a gitdir for this worktree."""
+ try:
+ statbuf = os.stat(dotgit)
+ except OSError:
+ return None
+ if not stat.S_ISREG(statbuf.st_mode):
+ return None
+
+ try:
+ lines = open(dotgit, 'r').readlines()
+ for key, value in [line.strip().split(': ') for line in lines]:
+ if key == 'gitdir':
+ return value
+ except ValueError:
+ pass
+ return None
+
+
def find_submodule_git_dir(d):
"""Search for a submodule repo."""
if is_git_dir(d):