diff options
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | VERSION | 2 | ||||
-rw-r--r-- | lib/git_python/git.py | 1 | ||||
-rw-r--r-- | lib/git_python/repo.py | 22 | ||||
-rw-r--r-- | test/git/test_tree.py | 16 |
7 files changed, 38 insertions, 9 deletions
@@ -6,7 +6,7 @@ CHANGES ===== Corrected problem with Tree.__div__ not working with zero length files. Removed __len__ override and replaced with size instead. Also made size cache -properly. +properly. This is a breaking change. 0.1.1 ===== @@ -1,4 +1,4 @@ -Copyright (c) 2008, Michael Trier +Copyright (c) 2008, Michael Trier and contributors All rights reserved. Redistribution and use in source and binary forms, with or without @@ -59,7 +59,7 @@ In the above example, the directory ``/Users/mtrier/Development/git-python`` is my working repository and contains the ``.git`` directory. You can also initialize GitPython with a bare repository. - >>> repo = Repo.init_bare("/var/git/git-python.git") + >>> repo = Repo.create("/var/git/git-python.git") Getting a list of commits ************************* @@ -1 +1 @@ -0.1.1 +0.1.2 diff --git a/lib/git_python/git.py b/lib/git_python/git.py index ad08bb20..ee256356 100644 --- a/lib/git_python/git.py +++ b/lib/git_python/git.py @@ -26,6 +26,7 @@ class Git(MethodMissingMixin): ``command`` The command to execute """ + print command proc = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE diff --git a/lib/git_python/repo.py b/lib/git_python/repo.py index f04ba19c..dc9fa729 100644 --- a/lib/git_python/repo.py +++ b/lib/git_python/repo.py @@ -250,13 +250,17 @@ class Repo(object): return Commit.diff(self, commit) @classmethod - def init_bare(self, path, **kwargs): + def init_bare(self, path, mkdir=True, **kwargs): """ Initialize a bare git repository at the given path ``path`` is the full path to the repo (traditionally ends with /<name>.git) + ``mkdir`` + if specified will create the repository directory if it doesn't + already exists. Creates the directory with a mode=0755. + ``kwargs`` is any additional options to the git init command @@ -267,9 +271,19 @@ class Repo(object): Returns ``GitPython.Repo`` (the newly created repo) """ - git = Git(path) - git.init(**kwargs) + split = os.path.split(path) + if split[-1] == '.git' or os.path.split(split[0])[-1] == '.git': + gitpath = path + else: + gitpath = os.path.join(path, '.git') + + if mkdir and not os.path.exists(gitpath): + os.makedirs(gitpath, 0755) + + git = Git(gitpath) + output = git.init(**kwargs) return Repo(path) + create = init_bare def fork_bare(self, path, **kwargs): """ @@ -284,7 +298,7 @@ class Repo(object): Returns ``GitPython.Repo`` (the newly forked repo) """ - options = {'bare': True, 'shared': False} + options = {'bare': True} options.update(kwargs) self.git.clone(self.path, path, **options) return Repo(path) diff --git a/test/git/test_tree.py b/test/git/test_tree.py index 5d8dea67..0550e410 100644 --- a/test/git/test_tree.py +++ b/test/git/test_tree.py @@ -49,7 +49,7 @@ class TestTree(object): def test_content_from_string_invalid_type_should_raise(self): self.tree.content_from_string(None, "040000 bogus 650fa3f0c17f1edb4ae53d8dcca4ac59d86e6c44 test") - @patch(Blob, '__len__') + @patch(Blob, 'size') @patch(Git, 'method_missing') def test_slash(self, blob, git): git.return_value = fixture('ls_tree_a') @@ -63,6 +63,20 @@ class TestTree(object): assert_true(git.called) assert_equal(git.call_args, (('ls_tree', 'master'), {})) + @patch(Blob, 'size') + @patch(Git, 'method_missing') + def test_slash_with_zero_length_file(self, blob, git): + git.return_value = fixture('ls_tree_a') + blob.return_value = 0 + + tree = self.repo.tree('master') + + assert_not_none(tree/'README.txt') + assert_equal('8b1e02c0fb554eed2ce2ef737a68bb369d7527df', (tree/'README.txt').id) + + assert_true(git.called) + assert_equal(git.call_args, (('ls_tree', 'master'), {})) + @patch(Git, 'method_missing') def test_slash_with_commits(self, git): git.return_value = fixture('ls_tree_commit') |