Skip to content

Commit c09ac1a

Browse files
committed
Test InvalidGitRepositoryError in repo subdir
A Repo object can of course be constructed from a path to a directory that is the root of an existing repository, and raises InvalidGitRepositoryError on a directory that is outside of any repository. Tests intended to show both conditions already exist. This adds a test to verify that InvalidGitRepositoryError is also raised when an attempt is made to construct a Repo object from a path to a directory that is not the root of a repository but that is known to be located inside an existing git repository.
1 parent 9277ff5 commit c09ac1a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

test/test_repo.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,20 @@ def tearDown(self):
7777
gc.collect()
7878

7979
def test_new_should_raise_on_invalid_repo_location(self):
80+
# Ideally this tests a directory that is outside of any repository. In the rare
81+
# case tempfile.gettempdir() is inside a repo, this still passes, but tests the
82+
# same scenario as test_new_should_raise_on_invalid_repo_location_within_repo.
8083
with tempfile.TemporaryDirectory() as tdir:
8184
self.assertRaises(InvalidGitRepositoryError, Repo, tdir)
8285

86+
@with_rw_directory
87+
def test_new_should_raise_on_invalid_repo_location_within_repo(self, rw_dir):
88+
repo_dir = osp.join(rw_dir, "repo")
89+
Repo.init(repo_dir)
90+
subdir = osp.join(repo_dir, "subdir")
91+
os.mkdir(subdir)
92+
self.assertRaises(InvalidGitRepositoryError, Repo, subdir)
93+
8394
def test_new_should_raise_on_non_existent_path(self):
8495
with tempfile.TemporaryDirectory() as tdir:
8596
nonexistent = osp.join(tdir, "foobar")
@@ -122,7 +133,7 @@ def test_tree_from_revision(self):
122133
self.assertEqual(tree.type, "tree")
123134
self.assertEqual(self.rorepo.tree(tree), tree)
124135

125-
# try from invalid revision that does not exist
136+
# Try from an invalid revision that does not exist.
126137
self.assertRaises(BadName, self.rorepo.tree, "hello world")
127138

128139
def test_pickleable(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy