summaryrefslogtreecommitdiff
path: root/git/test/test_repo.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-08 17:07:01 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-08 17:08:02 +0100
commitb08651e5ae2bffef5e4fb44fbdd7d467715e3b73 (patch)
tree2f507920b8c63a6b0074eb2938fb3b033467b612 /git/test/test_repo.py
parentfc94b89dabd9df49631cbf6b18800325f3521864 (diff)
downloadgitpython-b08651e5ae2bffef5e4fb44fbdd7d467715e3b73.tar.gz
Improved handling of name-resolution, which will not mangle names anymore.
Previously, an unresolvable ref name like HEAD would end up as HEX and was presented as BadObject error, even though that exception is for invalid shas only. Now BadName is thrown, which converts into a more useful error message. Improves #105
Diffstat (limited to 'git/test/test_repo.py')
-rw-r--r--git/test/test_repo.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/git/test/test_repo.py b/git/test/test_repo.py
index 9d9f727f..1b3f3ed4 100644
--- a/git/test/test_repo.py
+++ b/git/test/test_repo.py
@@ -26,8 +26,10 @@ from git import (
GitDB,
Submodule,
GitCmdObjectDB,
- Remote
+ Remote,
+ BadName
)
+from git.repo.fun import touch
from git.util import join_path_native
from git.exc import BadObject
from gitdb.util import bin_to_hex
@@ -35,6 +37,7 @@ from git.compat import (
string_types,
defenc
)
+from gitdb.test.lib import with_rw_directory
import os
import sys
@@ -682,3 +685,25 @@ class TestRepo(TestBase):
def test_remote_method(self):
self.failUnlessRaises(ValueError, self.rorepo.remote, 'foo-blue')
assert isinstance(self.rorepo.remote(name='origin'), Remote)
+
+ @with_rw_directory
+ def test_empty_repo(self, rw_dir):
+ """Assure we can handle empty repositories"""
+ r = Repo.init(rw_dir, mkdir=False)
+ # It's ok not to be able to iterate a commit, as there is none
+ self.failUnlessRaises(ValueError, r.iter_commits)
+ assert r.active_branch.name == 'master'
+ assert not r.active_branch.is_valid(), "Branch is yet to be born"
+
+ # actually, when trying to create a new branch without a commit, git itself fails
+ # We should, however, not fail ungracefully
+ self.failUnlessRaises(BadName, r.create_head, 'foo')
+
+ new_file_path = os.path.join(rw_dir, "new_file.ext")
+ touch(new_file_path)
+ r.index.add([new_file_path])
+ r.index.commit("initial commit")
+
+ # Now a branch should be creatable
+ nb = r.create_head('foo')
+ assert nb.is_valid()