def test_unpushed_commits(tmpdir): tmpdir.chdir() tmpdir.mkdir("hello_world") subprocess.call(["git", "init"], cwd="hello_world") subprocess.call(["git", "config", "user.email", '"*****@*****.**"'], cwd="hello_world") subprocess.call(["git", "config", "user.name", '"My Name"'], cwd="hello_world") q = GitProject("hello_world") with open("hello_world/committed", "w") as f: f.write("foobar") subprocess.call(["git", "add", "committed"], cwd="hello_world") subprocess.call(["git", "commit", "-m", "Initial commit."], cwd="hello_world") assert len(q.get_commits_not_pushed_to_existing_remotes()) == 1 success = q.check_unpushed_commits()[0] assert not success tmpdir.mkdir("the_remote") subprocess.call(["git", "init", "--bare"], cwd="the_remote") subprocess.call(["git", "remote", "add", "jrandomremote", str(tmpdir.join("the_remote"))], cwd="hello_world") assert len(q.get_commits_not_pushed_to_existing_remotes()) == 1 success = q.check_unpushed_commits()[0] assert not success subprocess.call(["git", "push", "jrandomremote", "master"], cwd="hello_world") assert len(q.get_commits_not_pushed_to_existing_remotes()) == 0 success = q.check_unpushed_commits()[0] assert success
def test_unpushed_commit_error(tmpdir): tmpdir.chdir() tmpdir.mkdir("hello_world") subprocess.call(["git", "init"], cwd="hello_world") subprocess.call(["git", "config", "user.email", '"*****@*****.**"'], cwd="hello_world") subprocess.call(["git", "config", "user.name", '"My Name"'], cwd="hello_world") q = GitProject("hello_world") with open("hello_world/committed", "w") as f: f.write("foobar") subprocess.call(["git", "add", "committed"], cwd="hello_world") subprocess.call(["git", "commit", "-m", "Initial commit."], cwd="hello_world") assert len(q.get_commits_not_pushed_to_existing_remotes()) == 1