def test_detect_git_repository(tmpdir):
    """Ensure that it is possible to detect that a directory is not a Git repository."""
    # create a Git repository using GitPython
    _ = Repo.init(str(tmpdir))
    # since the repository was created in the tmpdir
    # the check for the existence of a repository should be True
    detected_git_repository = repository.is_git_repository(str(tmpdir))
    assert detected_git_repository is True
def test_one_commit_in_new_repository(tmpdir):
    """Ensure that it is possible to detect one commit in a new Git repository."""
    temp_file = tmpdir.mkdir("sub").join("hello.txt")
    temp_file.write("content")
    assert temp_file.read() == "content"
    assert len(tmpdir.listdir()) == 1
    testing_repository = Repo.init(tmpdir)
    # create an empty file and perform a commit on it
    testing_repository.index.add([str(temp_file)])
    testing_repository.index.commit("Add the hello.txt file.")
    # since the repository was created in the tmpdir
    # the check for the existence of a repository should be True
    detected_git_repository = repository.is_git_repository(str(tmpdir))
    assert detected_git_repository is True
    # since an empty file was committed, the count should be 1
    commits = repository.get_commits(str(tmpdir))
    assert len(commits) == 1
def test_detect_not_git_repository(tmpdir):
    """Ensure that it is possible to detect that a directory is not a Git repository."""
    # by default, the tmpdir is not a Git repository
    # the check for the existence of a repository should be False
    detected_git_repository = repository.is_git_repository(str(tmpdir))
    assert detected_git_repository is False