@@ -15,68 +15,13 @@ class Git(MethodMissingMixin):
15
15
"""
16
16
The Git class manages communication with the Git binary
17
17
"""
18
- def __init__ (self , git_dir = None , bare_repo = False ):
18
+ def __init__ (self , git_dir ):
19
19
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
76
21
77
22
@property
78
23
def get_dir (self ):
79
- return self ._git_dir
24
+ return self .git_dir
80
25
81
26
def execute (self , command ,
82
27
istream = None ,
@@ -118,10 +63,10 @@ def execute(self, command,
118
63
print ' ' .join (command )
119
64
120
65
# Allow the user to have the command executed in their working dir.
121
- if with_keep_cwd :
66
+ if with_keep_cwd or self . git_dir is None :
122
67
cwd = os .getcwd ()
123
68
else :
124
- cwd = self ._cwd
69
+ cwd = self .git_dir
125
70
126
71
# Start the process
127
72
proc = subprocess .Popen (command ,
0 commit comments