Repository: release-depot/git_wrapper

Issue:
Provide support for bare repo cloning.
Add support in the clone method to clone a bare repo.

Discussion:

Patch:
diff --git a/git_wrapper/repo.py b/git_wrapper/repo.py
index 889efed..f3286f3 100644
--- a/git_wrapper/repo.py
+++ b/git_wrapper/repo.py
@@ -77,18 +77,22 @@ class GitRepo(object):
         return self.repo.git
 
     @staticmethod
-    def clone(clone_from, clone_to):
+    def clone(clone_from, clone_to, bare=False):
         """Clone a repository.
 
            :param str clone_from: The url or path to clone the repo from
            :param str clone_to: The local path to clone to
-           :return git.Repo: Returns the newly created repo object
+           :param bool bare: Whether to create a bare repo
+           :return GitRepo: Returns the newly created repo object
         """
         clone_to = os.path.realpath(os.path.expanduser(clone_to))
-        logging.debug("Preparing to clone repository %s into directory %s", clone_from, clone_to)
+        logging.debug("Preparing to clone repository %s into directory %s",
+                      clone_from, clone_to)
 
         try:
-            repo = git.repo.base.Repo.clone_from(clone_from, clone_to)
+            repo = git.repo.base.Repo.clone_from(clone_from,
+                                                 clone_to,
+                                                 bare=bare)
         except git.GitCommandError as ex:
             msg = "Error cloning repository {repo}".format(repo=clone_from)
             raise_from(exceptions.RepoCreationException(msg), ex)


Test patch:
diff --git a/integration_tests/test_clone.py b/integration_tests/test_repo.py
similarity index 93%
rename from integration_tests/test_clone.py
rename to integration_tests/test_repo.py
index d8d83f9..df6f8a8 100644
--- a/integration_tests/test_clone.py
+++ b/integration_tests/test_repo.py
@@ -11,7 +11,7 @@ def test_clone(clone_repo_root, clone_repo_url):
     repo_url = clone_repo_url
 
     # Create a new clone
-    clone = GitRepo.clone(repo_url, repo_root)
+    clone = GitRepo.clone(repo_url, repo_root, bare=True)
 
     # Ensure repo has expected tags, some commits
     assert hasattr(clone, "repo") is True
@@ -22,6 +22,8 @@ def test_clone(clone_repo_root, clone_repo_url):
     tag = clone.repo.commit("0.1.0")
     assert tag.hexsha == "2e6c014bc296be90a7ed04d155ea7d9da2240bbc"
 
+    assert clone.repo.bare is True
+
 
 def test_clone_from_filesystem(clone_repo_root, clone_repo_url, repo_root):
     new_repo_root = clone_repo_root
@@ -35,6 +37,7 @@ def test_clone_from_filesystem(clone_repo_root, clone_repo_url, repo_root):
     clone.repo.commit("f8f7abc4ce87db051f9998c5d4dd153695e35675")
     tag = clone.repo.commit("0.1.0")
     assert tag.hexsha == "2e6c014bc296be90a7ed04d155ea7d9da2240bbc"
+    assert clone.repo.bare is False
 
 
 def test_clone_failed(clone_repo_root, clone_repo_url):
diff --git a/tests/test_repo.py b/tests/test_repo.py
index 71a9dfa..3fa434e 100644
--- a/tests/test_repo.py
+++ b/tests/test_repo.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 """Tests for GitRepo"""
 
-from mock import Mock, patch
+from mock import Mock, patch, ANY
 import shutil
 
 import git
@@ -129,6 +129,17 @@ def test_clone():
         assert isinstance(clone, GitRepo)
 
 
+def test_bare_clone():
+    """
+    GIVEN GitRepo without a path or repo
+    WHEN clone is called with valid parameters and bare set to True
+    THEN Repo.clone_from is called with bare=True
+    """
+    with patch('git.repo.base.Repo.clone_from') as mock_clone:
+        GitRepo.clone('./', './testclone', True)
+        mock_clone.assert_called_with('./', ANY, bare=True)
+
+
 def test_clone_failed():
     """
     GIVEN GitRepo without a path or repo
@@ -157,7 +168,9 @@ def test_destroy_and_reclone(mock_repo, monkeypatch):
     with patch('git.repo.base.Repo.clone_from') as mock_clone:
         clone.destroy_and_reclone()
         assert mock_clone.called is True
-        assert mock_clone.called_with('http://example.com', local_dir)
+        mock_clone.assert_called_with('http://example.com',
+                                      local_dir,
+                                      bare=False)
 
 
 def test_destroy_no_path_no_repo(monkeypatch):
@@ -207,7 +220,9 @@ def test_destroy_no_remote_named_origin(mock_repo, monkeypatch):
     with patch('git.repo.base.Repo.clone_from') as mock_clone:
         clone.destroy_and_reclone()
         assert mock_clone.called is True
-        mock_clone.assert_called_with('http://example.com/another', local_dir)
+        mock_clone.assert_called_with('http://example.com/another',
+                                      local_dir,
+                                      bare=False)
 
 
 def test_destroy_and_multiple_remotes(mock_repo, monkeypatch):
@@ -232,7 +247,9 @@ def test_destroy_and_multiple_remotes(mock_repo, monkeypatch):
         mock_clone.return_value = new_repo_mock
         clone.destroy_and_reclone()
         assert mock_clone.called is True
-        mock_clone.assert_called_with('http://example.com', local_dir)
+        mock_clone.assert_called_with('http://example.com',
+                                      local_dir,
+                                      bare=False)
         new_repo_mock.create_remote.assert_called_with(
             "otherremote",
             "http://example.com/another"