Skip to content

Commit 4f03eee

Browse files
muggenhorByron
authored andcommitted
test(clone): verify stderr for a failing clone into a non-empty dir
Addresses #1221, #1223
1 parent 3b274b8 commit 4f03eee

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: test/test_clone.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
# This module is part of GitPython and is released under
3+
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
4+
5+
from pathlib import Path
6+
import re
7+
8+
import git
9+
10+
from .lib import (
11+
TestBase,
12+
with_rw_directory,
13+
)
14+
15+
class TestClone(TestBase):
16+
@with_rw_directory
17+
def test_checkout_in_non_empty_dir(self, rw_dir):
18+
non_empty_dir = Path(rw_dir)
19+
garbage_file = non_empty_dir / 'not-empty'
20+
garbage_file.write_text('Garbage!')
21+
22+
# Verify that cloning into the non-empty dir fails while complaining about the target directory not being empty/non-existent
23+
try:
24+
self.rorepo.clone(non_empty_dir)
25+
except git.GitCommandError as exc:
26+
self.assertTrue(exc.stderr, "GitCommandError's 'stderr' is unexpectedly empty")
27+
expr = re.compile(r'(?is).*\bfatal:\s+destination\s+path\b.*\bexists\b.*\bnot\b.*\bempty\s+directory\b')
28+
self.assertTrue(expr.search(exc.stderr), '"%s" does not match "%s"' % (expr.pattern, exc.stderr))
29+
else:
30+
self.fail("GitCommandError not raised")

0 commit comments

Comments
 (0)