def test_sync_ahead(synced_repo_and_workspace): """If repository is ahead origin sync should stop""" data = synced_repo_and_workspace # Commit file in workspace helpers.write_and_commit(data["dest_repo"], "output.txt") result = CliRunner().invoke(metarepo.cli.cli, ["sync"]) assert result.exit_code == 1
def test_fetch_behind(test_repo_and_workspace): """If updates are made on the remote, we will be behind locally""" data = test_repo_and_workspace repo = RepoTool(data["workspace"] / "repo", expected_origin=data["source_repo"].git_dir, allow_create=True) # Fetch and checkout to make sure we have a local head fetch_result = repo.fetch("master") repo.checkout("origin/master", "master") # We are currently up to date assert fetch_result.ahead == [] assert fetch_result.behind == [] new_commit = helpers.write_and_commit(data["source_repo"], "new_file_on_remote") # Fetch the new commit fetch_result = repo.fetch("master") # We are now behind assert fetch_result.ahead == [] assert fetch_result.behind == [new_commit]
def test_sync_basic(test_repo_and_workspace): """Sync nonexistant repository""" data = test_repo_and_workspace runner = CliRunner() result = runner.invoke(metarepo.cli.cli, ["sync"]) assert "Checked out master" in result.output assert result.exit_code == 0 # Repo is created and is in sync dest_repo = git.Repo(data["workspace"] / "test") assert dest_repo.head.commit == data["source_repo"].head.commit # Add additional commits new_commit = helpers.write_and_commit(data["source_repo"], "newfile.txt") # Repo no longer in sync previous_commit = dest_repo.head.commit assert previous_commit != new_commit # Sync result = runner.invoke(metarepo.cli.cli, ["sync"]) assert result.exit_code == 0 # Current commit has been updated assert dest_repo.head.commit == new_commit # Output mentions the updated commit assert str(previous_commit)[0:7] in result.output assert str(new_commit)[0:7] in result.output
def fixture_test_repo_and_workspace_behind(test_repo_and_workspace): """ Builds upon 'test_repo_and_workspace' and ensures that the local repo is checked out but with commits still left to fetch :param test_repo_and_workspace: :return: Dict with information """ data = test_repo_and_workspace # Clone repo to workspace repo = git.Repo.init(data["workspace"]) repo.create_remote("origin", data["source_repo"].git_dir) repo.remote("origin").fetch("master") repo.create_head("master", "origin/master") repo.heads["master"].checkout() data["missing_commit"] = helpers.write_and_commit(data["source_repo"], "new_file") return data
def test_checkout(test_repo_and_workspace): data = test_repo_and_workspace repo = RepoTool(data["workspace"] / "repo", expected_origin=data["source_repo"].git_dir, allow_create=True) repo.fetch("master") repo.checkout("origin/master", "master") new_commit = helpers.write_and_commit(data["source_repo"], "new_file_on_remote") # Fetch the new commit repo.fetch("master") repo.checkout("origin/master", "master") status = repo.get_status() assert status.untracked_files == [] assert not status.is_dirty assert status.head == new_commit