diff options
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | lib/git/repo.py | 30 | ||||
-rw-r--r-- | test/git/test_repo.py | 26 |
3 files changed, 33 insertions, 30 deletions
@@ -59,7 +59,12 @@ Repo repositories which are likely to have completly different commits. For related repositories, i.e. clones, git-rev-list would be sufficient to find commits that would need to be transferred for example. -* Renamed commits to iter_commits to improve the performance, adjusted signature + - 'create' method which equals the 'init' method's functionality +* Renamed the following methods: + - commits to iter_commits to improve the performance, adjusted signature + - init_bare to init, implying less about the options to be used + - fork_bare to clone, as it was to represent general clone functionality, but implied + a bare clone to be more versatile * 'commits' method has no max-count of returned commits anymore, it now behaves like git-rev-list diff --git a/lib/git/repo.py b/lib/git/repo.py index cfa73c43..39b1cb50 100644 --- a/lib/git/repo.py +++ b/lib/git/repo.py @@ -408,52 +408,52 @@ class Repo(object): return blames @classmethod - def init_bare(self, path, mkdir=True, **kwargs): + def init(cls, path=None, mkdir=True, **kwargs): """ - Initialize a bare git repository at the given path + Initialize a git repository at the given path if specified ``path`` is the full path to the repo (traditionally ends with /<name>.git) + or None in which case the repository will be created in the current + working directory ``mkdir`` if specified will create the repository directory if it doesn't - already exists. Creates the directory with a mode=0755. + already exists. Creates the directory with a mode=0755. + Only effective if a path is explicitly given ``kwargs`` - keyword arguments serving as additional options to the git init command + keyword arguments serving as additional options to the git-init command Examples:: - git.Repo.init_bare('/var/git/myrepo.git') + git.Repo.init('/var/git/myrepo.git',bare=True) Returns ``git.Repo`` (the newly created repo) """ - if mkdir and not os.path.exists(path): + if mkdir and path and not os.path.exists(path): os.makedirs(path, 0755) git = Git(path) - output = git.init('--bare', **kwargs) + output = git.init(path, **kwargs) return Repo(path) - create = init_bare - def fork_bare(self, path, **kwargs): + def clone(self, path, **kwargs): """ - Fork a bare git repository from this repo + Create a clone from this repository. ``path`` is the full path of the new repo (traditionally ends with /<name>.git) ``kwargs`` - keyword arguments to be given to the git clone command + keyword arguments to be given to the git-clone command Returns - ``git.Repo`` (the newly forked repo) + ``git.Repo`` (the newly cloned repo) """ - options = {'bare': True} - options.update(kwargs) - self.git.clone(self.path, path, **options) + self.git.clone(self.path, path, **kwargs) return Repo(path) def archive_tar(self, treeish='master', prefix=None): diff --git a/test/git/test_repo.py b/test/git/test_repo.py index cefd1349..cbfc27c4 100644 --- a/test/git/test_repo.py +++ b/test/git/test_repo.py @@ -67,55 +67,53 @@ class TestRepo(object): @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_init_bare(self, git, repo): + def test_init(self, git, repo): git.return_value = True repo.return_value = None - Repo.init_bare("repos/foo/bar.git") + r = Repo.init("repos/foo/bar.git", bare=True) + assert isinstance(r, Repo) assert_true(git.called) - assert_equal(git.call_args, (('init', '--bare'), {})) assert_true(repo.called) - assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_init_bare_with_options(self, git, repo): + def test_init_with_options(self, git, repo): git.return_value = True repo.return_value = None - Repo.init_bare("repos/foo/bar.git", **{'template': "/baz/sweet"}) + r = Repo.init("repos/foo/bar.git", **{'bare' : True,'template': "/baz/sweet"}) + assert isinstance(r, Repo) assert_true(git.called) - assert_equal(git.call_args, (('init', '--bare'), {'template': '/baz/sweet'})) assert_true(repo.called) - assert_equal(repo.call_args, (('repos/foo/bar.git',), {})) @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_fork_bare(self, git, repo): + def test_clone(self, git, repo): git.return_value = None repo.return_value = None - self.repo.fork_bare("repos/foo/bar.git") + self.repo.clone("repos/foo/bar.git") assert_true(git.called) path = os.path.join(absolute_project_path(), '.git') - assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'), {'bare': True})) + assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'), {})) assert_true(repo.called) @patch_object(Repo, '__init__') @patch_object(Git, '_call_process') - def test_fork_bare_with_options(self, git, repo): + def test_clone_with_options(self, git, repo): git.return_value = None repo.return_value = None - self.repo.fork_bare("repos/foo/bar.git", **{'template': '/awesome'}) + self.repo.clone("repos/foo/bar.git", **{'template': '/awesome'}) assert_true(git.called) path = os.path.join(absolute_project_path(), '.git') assert_equal(git.call_args, (('clone', path, 'repos/foo/bar.git'), - {'bare': True, 'template': '/awesome'})) + { 'template': '/awesome'})) assert_true(repo.called) @patch_object(Git, '_call_process') |