Commit 990d1fe06e8c2db48a895aaa7e5e5eda8b330a5c

fixed http://groups.google.com/group/git-python/browse_thread/thread/b8f3580abf31f9db?hl=en# and passed Git a working_tree again (sort of).

Commit diff

lib/git/cmd.py

 
1515 """
1616 The Git class manages communication with the Git binary
1717 """
18 def __init__(self, git_dir=None, bare_repo=False):
18 def __init__(self, git_dir):
1919 super(Git, self).__init__()
20 if git_dir:
21 self._location = os.path.abspath(git_dir)
22 else:
23 self._location = os.getcwd()
24 self._is_bare_repo = bare_repo
25 self.refresh()
26
27 def refresh(self):
28 self._git_dir = None
29 self._is_in_repo = not not self.get_git_dir()
30 self._work_tree = None
31 self._cwd = self._git_dir
32 if self._git_dir and not self._is_bare_repo:
33 self._cwd = self.get_work_tree()
34
35 def _is_git_dir(self, d):
36 """ This is taken from the git setup.c:is_git_directory
37 function."""
38
39 if os.path.isdir(d) and \
40 os.path.isdir(os.path.join(d, 'objects')) and \
41 os.path.isdir(os.path.join(d, 'refs')):
42 headref = os.path.join(d, 'HEAD')
43 return os.path.isfile(headref) or \
44 (os.path.islink(headref) and
45 os.readlink(headref).startswith('refs'))
46 return False
47
48 def get_git_dir(self):
49 if not self._git_dir:
50 self._git_dir = os.getenv('GIT_DIR')
51 if self._git_dir and self._is_git_dir(self._git_dir):
52 return self._git_dir
53 curpath = self._location
54 while curpath:
55 if self._is_git_dir(curpath):
56 self._git_dir = curpath
57 break
58 gitpath = os.path.join(curpath, '.git')
59 if self._is_git_dir(gitpath):
60 self._git_dir = gitpath
61 break
62 curpath, dummy = os.path.split(curpath)
63 if not dummy:
64 break
65 return self._git_dir
66
67 def get_work_tree(self):
68 if self._is_bare_repo:
69 return None
70 if not self._work_tree:
71 self._work_tree = os.getenv('GIT_WORK_TREE')
72 if not self._work_tree or not os.path.isdir(self._work_tree):
73 self._work_tree = os.path.abspath(
74 os.path.join(self._git_dir, '..'))
75 return self._work_tree
20 self.git_dir = git_dir
7621
7722 @property
7823 def get_dir(self):
79 return self._git_dir
24 return self.git_dir
8025
8126 def execute(self, command,
8227 istream=None,
6363 print ' '.join(command)
6464
6565 # Allow the user to have the command executed in their working dir.
66 if with_keep_cwd:
66 if with_keep_cwd or self.git_dir is None:
6767 cwd = os.getcwd()
6868 else:
69 cwd=self._cwd
69 cwd=self.git_dir
7070
7171 # Start the process
7272 proc = subprocess.Popen(command,
toggle raw diff

lib/git/repo.py

 
11import os
22import re
33from errors import InvalidGitRepositoryError, NoSuchPathError
4from utils import touch
4from utils import touch, is_git_dir
55from cmd import Git
66from head import Head
77from blob import Blob
2727 Returns
2828 ``GitPython.Repo``
2929 """
30 path = os.path.expanduser(path)
31 if not os.path.exists(path):
32 raise NoSuchPathError(path)
33
34 self.git = Git(path)
35 self.path = self.git.get_git_dir()
36 if not self.path:
37 raise InvalidGitRepositoryError(path)
38 epath = self.git.get_work_tree()
39
40 if os.path.exists(os.path.join(epath, '.git')):
41 self.bare = False
42 elif os.path.exists(epath) and epath.endswith('.git'):
43 self.bare = True
44 elif os.path.exists(epath):
45 raise InvalidGitRepositoryError(epath)
46 else:
30
31 epath = os.path.abspath(os.path.expanduser(path or os.getcwd()))
32
33 if not os.path.exists(epath):
4734 raise NoSuchPathError(epath)
4835
36 self.path = None
37 curpath = epath
38 while curpath:
39 if is_git_dir(curpath):
40 self.bare = True
41 self.path, self.wd = curpath
42 break
43 gitpath = os.path.join(curpath, '.git')
44 if is_git_dir(gitpath):
45 self.bare = False
46 self.path = gitpath
47 self.wd = curpath
48 break
49 curpath, dummy = os.path.split(curpath)
50 if not dummy:
51 break
52
53 if self.path is None:
54 raise InvalidGitRepositoryError(epath)
55
56 self.git = Git(self.wd)
4957
5058 @property
5159 def description(self):
289289 if mkdir and not os.path.exists(path):
290290 os.makedirs(path, 0755)
291291
292 git = Git(path, bare_repo=True)
292 git = Git(path)
293293 output = git.init(**kwargs)
294294 return Repo(path)
295295 create = init_bare
378378 Returns
379379 None
380380 """
381 if self.bare:
382 touch(os.path.join(self.path, DAEMON_EXPORT_FILE))
383 else:
384 touch(os.path.join(self.path, '.git', DAEMON_EXPORT_FILE))
381 touch(os.path.join(self.path, DAEMON_EXPORT_FILE))
385382
386383 def disable_daemon_serve(self):
387384 """
388388 Returns
389389 None
390390 """
391 if self.bare:
392 return os.remove(os.path.join(self.path, DAEMON_EXPORT_FILE))
393 else:
394 return os.remove(os.path.join(self.path, '.git', DAEMON_EXPORT_FILE))
391 return os.remove(os.path.join(self.path, DAEMON_EXPORT_FILE))
395392
396393 def _get_alternates(self):
397394 """
toggle raw diff

lib/git/stats.py

 
99 hsh = {'total': {'insertions': 0, 'deletions': 0, 'lines': 0, 'files': 0}, 'files': {}}
1010 for line in text.splitlines():
1111 (insertions, deletions, filename) = line.split("\t")
12 hsh['total']['insertions'] += int(insertions)
13 hsh['total']['deletions'] += int(deletions)
12 hsh['total']['insertions'] += insertions != '-' and int(insertions) or 0
13 hsh['total']['deletions'] += deleteions != '-' and int(deletions) or 0
1414 hsh['total']['lines'] = (hsh['total']['deletions'] + hsh['total']['insertions'])
1515 hsh['total']['files'] += 1
1616 hsh['files'][filename.strip()] = {'insertions': int(insertions), 'deletions': int(deletions)}
toggle raw diff

lib/git/utils.py

 
1import os
2
13def dashify(string):
24 return string.replace('_', '-')
35
46def touch(filename):
5 open(filename, "a").close()
7 os.utime(filename)
8
9def is_git_dir(d):
10 """ This is taken from the git setup.c:is_git_directory
11 function."""
12
13 if os.path.isdir(d) and \
14 os.path.isdir(os.path.join(d, 'objects')) and \
15 os.path.isdir(os.path.join(d, 'refs')):
16 headref = os.path.join(d, 'HEAD')
17 return os.path.isfile(headref) or \
18 (os.path.islink(headref) and
19 os.readlink(headref).startswith('refs'))
20 return False
toggle raw diff