diff options
author | Giel van Schijndel <giel@mortis.eu> | 2021-04-22 10:29:38 +0200 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2021-04-23 07:23:07 +0800 |
commit | e0a7824253ae412cf7cc27348ee98c919d382cf2 (patch) | |
tree | 6e551467597da18bc5bc6528796ebf9cddc2eeef /test/test_clone.py | |
parent | 36440f79bddc2c1aa4a7a3dd8c2557dca3926639 (diff) | |
download | gitpython-e0a7824253ae412cf7cc27348ee98c919d382cf2.tar.gz |
test(clone): verify stderr for a failing clone into a non-empty dir
Addresses #1221, #1223
Diffstat (limited to 'test/test_clone.py')
-rw-r--r-- | test/test_clone.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/test_clone.py b/test/test_clone.py new file mode 100644 index 00000000..e4eb9fe1 --- /dev/null +++ b/test/test_clone.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# This module is part of GitPython and is released under +# the BSD License: http://www.opensource.org/licenses/bsd-license.php + +from pathlib import Path +import re + +import git + +from .lib import ( + TestBase, + with_rw_directory, +) + +class TestClone(TestBase): + @with_rw_directory + def test_checkout_in_non_empty_dir(self, rw_dir): + non_empty_dir = Path(rw_dir) + garbage_file = non_empty_dir / 'not-empty' + garbage_file.write_text('Garbage!') + + # Verify that cloning into the non-empty dir fails while complaining about the target directory not being empty/non-existent + try: + self.rorepo.clone(non_empty_dir) + except git.GitCommandError as exc: + self.assertTrue(exc.stderr, "GitCommandError's 'stderr' is unexpectedly empty") + expr = re.compile(r'(?is).*\bfatal:\s+destination\s+path\b.*\bexists\b.*\bnot\b.*\bempty\s+directory\b') + self.assertTrue(expr.search(exc.stderr), '"%s" does not match "%s"' % (expr.pattern, exc.stderr)) + else: + self.fail("GitCommandError not raised") |