Skip to content

Commit 0651f09

Browse files
committed
lots of little fixes. Corrected problem with creating bare repo. Added Repo.create alias.
1 parent 062aafa commit 0651f09

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CHANGES
66
=====
77
Corrected problem with Tree.__div__ not working with zero length files.
88
Removed __len__ override and replaced with size instead. Also made size cache
9-
properly.
9+
properly. This is a breaking change.
1010

1111
0.1.1
1212
=====

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2008, Michael Trier
1+
Copyright (c) 2008, Michael Trier and contributors
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ In the above example, the directory ``/Users/mtrier/Development/git-python``
5959
is my working repository and contains the ``.git`` directory. You can also
6060
initialize GitPython with a bare repository.
6161

62-
>>> repo = Repo.init_bare("/var/git/git-python.git")
62+
>>> repo = Repo.create("/var/git/git-python.git")
6363

6464
Getting a list of commits
6565
*************************

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.1
1+
0.1.2

lib/git_python/git.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def execute(self, command):
2626
``command``
2727
The command to execute
2828
"""
29+
print command
2930
proc = subprocess.Popen(command,
3031
shell=True,
3132
stdout=subprocess.PIPE

lib/git_python/repo.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,17 @@ def commit_diff(self, commit):
250250
return Commit.diff(self, commit)
251251

252252
@classmethod
253-
def init_bare(self, path, **kwargs):
253+
def init_bare(self, path, mkdir=True, **kwargs):
254254
"""
255255
Initialize a bare git repository at the given path
256256
257257
``path``
258258
is the full path to the repo (traditionally ends with /<name>.git)
259259
260+
``mkdir``
261+
if specified will create the repository directory if it doesn't
262+
already exists. Creates the directory with a mode=0755.
263+
260264
``kwargs``
261265
is any additional options to the git init command
262266
@@ -267,9 +271,19 @@ def init_bare(self, path, **kwargs):
267271
Returns
268272
``GitPython.Repo`` (the newly created repo)
269273
"""
270-
git = Git(path)
271-
git.init(**kwargs)
274+
split = os.path.split(path)
275+
if split[-1] == '.git' or os.path.split(split[0])[-1] == '.git':
276+
gitpath = path
277+
else:
278+
gitpath = os.path.join(path, '.git')
279+
280+
if mkdir and not os.path.exists(gitpath):
281+
os.makedirs(gitpath, 0755)
282+
283+
git = Git(gitpath)
284+
output = git.init(**kwargs)
272285
return Repo(path)
286+
create = init_bare
273287

274288
def fork_bare(self, path, **kwargs):
275289
"""
@@ -284,7 +298,7 @@ def fork_bare(self, path, **kwargs):
284298
Returns
285299
``GitPython.Repo`` (the newly forked repo)
286300
"""
287-
options = {'bare': True, 'shared': False}
301+
options = {'bare': True}
288302
options.update(kwargs)
289303
self.git.clone(self.path, path, **options)
290304
return Repo(path)

test/git/test_tree.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_content_from_string_tree_should_return_commit(self):
4949
def test_content_from_string_invalid_type_should_raise(self):
5050
self.tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test")
5151

52-
@patch(Blob, '__len__')
52+
@patch(Blob, 'size')
5353
@patch(Git, 'method_missing')
5454
def test_slash(self, blob, git):
5555
git.return_value = fixture('ls_tree_a')
@@ -63,6 +63,20 @@ def test_slash(self, blob, git):
6363
assert_true(git.called)
6464
assert_equal(git.call_args, (('ls_tree', 'master'), {}))
6565

66+
@patch(Blob, 'size')
67+
@patch(Git, 'method_missing')
68+
def test_slash_with_zero_length_file(self, blob, git):
69+
git.return_value = fixture('ls_tree_a')
70+
blob.return_value = 0
71+
72+
tree = self.repo.tree('master')
73+
74+
assert_not_none(tree/'README.txt')
75+
assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id)
76+
77+
assert_true(git.called)
78+
assert_equal(git.call_args, (('ls_tree', 'master'), {}))
79+
6680
@patch(Git, 'method_missing')
6781
def test_slash_with_commits(self, git):
6882
git.return_value = fixture('ls_tree_commit')

0 commit comments

Comments
 (0)