Skip to content

test(clone): verify stderr for a failing clone into a non-empty dir #1225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(clone): verify stderr for a failing clone into a non-empty dir
Addresses #1221, #1223
  • Loading branch information
muggenhor committed Apr 22, 2021
commit b2696813717e2bb4a9e7fe87937ffd8ccb76ed33
30 changes: 30 additions & 0 deletions test/test_clone.py
Original file line number Diff line number Diff line change
@@ -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")