From 509b1985807a308e31bdff595c939503b6d26a40 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Tue, 4 Nov 2014 12:56:53 +0000 Subject: Only search for repository root in GitDirectory constructor if told to The GitDirectory() constructor, if passed a 'dirname' that doesn't contain a '.git' subdirectory, can search upwards to find the real root of the repository. This is used by the `add-binary`, `push`, and `pull` commands. This causes very confusing behaviour in the case that 'dirname' points to a directory that should be a Git repository, but isn't, and that directory is a path inside the working tree of another Git repository. Rather than raising an error, in this case the GitDirectory class would perform operations on a different repository to the one the caller expected. This 'search_for_root' behaviour is now opt-in, to avoid confusion. --- morphlib/gitdir_tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'morphlib/gitdir_tests.py') diff --git a/morphlib/gitdir_tests.py b/morphlib/gitdir_tests.py index 456e3716..42118fe2 100644 --- a/morphlib/gitdir_tests.py +++ b/morphlib/gitdir_tests.py @@ -43,6 +43,16 @@ class GitDirectoryTests(unittest.TestCase): gitdir = morphlib.gitdir.GitDirectory(self.dirname) self.assertEqual(gitdir.dirname, self.dirname) + def test_can_search_for_top_directory(self): + self.fake_git_clone() + + path_inside_working_tree = os.path.join(self.dirname, 'a', 'b', 'c') + os.makedirs(path_inside_working_tree) + + gitdir = morphlib.gitdir.GitDirectory( + path_inside_working_tree, search_for_root=True) + self.assertEqual(gitdir.dirname, self.dirname) + def test_runs_command_in_right_directory(self): self.fake_git_clone() gitdir = morphlib.gitdir.GitDirectory(self.dirname) -- cgit v1.2.1