diff --git a/abcclassroom/git.py b/abcclassroom/git.py index bfaec74..184f8ca 100644 --- a/abcclassroom/git.py +++ b/abcclassroom/git.py @@ -208,7 +208,7 @@ def init_and_commit(directory, custom_message=False): # Running git init on an existing repo is safe, so no need # to check anything first git_init(directory) - print("running init", directory) + print("Initializing", directory, "directory for you now.") _master_branch_to_main(directory) if repo_changed(directory): message = "Initial commit" diff --git a/abcclassroom/tests/test_git.py b/abcclassroom/tests/test_git.py index 6058b37..840cb36 100644 --- a/abcclassroom/tests/test_git.py +++ b/abcclassroom/tests/test_git.py @@ -46,6 +46,21 @@ def example_student_repo(tmpdir): return repo_dir +@pytest.fixture() +def example_student_repo_git(tmpdir, example_student_repo): + """A fixture with an initialized git repo""" + + import contextlib + + # Create the repo dir + repo_path = example_student_repo + with open(os.devnull, "w") as f, contextlib.redirect_stdout(f): + # This just suppresses print messages so we aren't getting extra + # stdout to weed through + abcgit.init_and_commit(repo_path) + return repo_path + + # TODO: add an actual check here for the standard out def test_check_git_ssh_pass(): """When ssh is setup correctly, the check should run and pass with no @@ -177,6 +192,46 @@ def test_clone_repo_bad_repo( ) +# TODO: I'm not sure there is any point of failure here because this doesn't +# check +# that the remote is valid in the function. is that ok? +def test_add_remote(tmpdir, example_student_repo_git): + """Function that tests the add remote correctly adds a new remote to a + git repo""" + + repo_path = example_student_repo_git + abcgit.add_remote( + directory=repo_path, + organization="demo-org", + remote_repo="student-repo", + ) + # Now check that setting the remote worked + ret = abcgit._call_git("remote", "-v", directory=repo_path) + assert ret.stdout.startswith( + "origin\tgit@github.com:demo-org/student-repo.git (fetch)" + ) + + +# Test repo changed +def test_repo_changed(tmpdir, example_student_repo_git): + """Should return True if the repo is dirty""" + repo_path = example_student_repo_git + # Make that puppy dirty / change stuff + a_file = Path(repo_path, "README.md") + a_file.write_text("Some new text in the readme") + ret = abcgit.repo_changed(directory=repo_path) + assert ret + + +# TODO this test and the above could be in the same test fun. not sure what +# best practice is here +def test_repo_clean(tmpdir, example_student_repo_git): + """Should return True if the repo is dirty""" + repo_path = example_student_repo_git + ret = abcgit.repo_changed(directory=repo_path) + assert ret is False + + # TODO here we are calling git and it works. This makes me think that call # git doesn't need to be mocked at all and we can assume that the user has # git setup.