diff --git a/conftest.py b/conftest.py index 40dafd0ba5..9f148d338d 100644 --- a/conftest.py +++ b/conftest.py @@ -46,7 +46,7 @@ from tests.utils import make_dataset_add_payload IT_PROTECTED_REMOTE_REPO_URL = os.getenv( - "IT_PROTECTED_REMOTE_REPO", "https://dev.renku.ch/gitlab/renku-qa/core-integration-test" + "IT_PROTECTED_REMOTE_REPO", "https://dev.renku.ch/gitlab/renku-qa/core-it-protected.git" ) IT_REMOTE_REPO_URL = os.getenv("IT_REMOTE_REPOSITORY", "https://dev.renku.ch/gitlab/renku-qa/core-integration-test") @@ -976,6 +976,9 @@ def svc_protected_repo(svc_client): response = svc_client.post("/cache.project_clone", data=json.dumps(payload), headers=headers) + project_id = response.json["result"]["project_id"] + _ = svc_client.post("/cache.migrate", data=json.dumps(dict(project_id=project_id)), headers=headers) + yield svc_client, headers, payload, response diff --git a/renku/core/commands/save.py b/renku/core/commands/save.py index 51b6df6c4b..cccb2d697c 100644 --- a/renku/core/commands/save.py +++ b/renku/core/commands/save.py @@ -97,18 +97,19 @@ def repo_sync(repo, message=None, remote=None, paths=None): raise errors.GitError("Cannot commit changes") from e try: - # push local changes to remote branch + # NOTE: Push local changes to remote branch. if origin.refs and repo.active_branch in origin.refs: origin.fetch() origin.pull(repo.active_branch) - origin.push(repo.active_branch) + result = origin.push(repo.active_branch) + if result and "[remote rejected] (pre-receive hook declined)" in result[0].summary: + # NOTE: Push to new remote branch if original one is protected. + pushed_branch = uuid4().hex + repo.create_head(pushed_branch) + repo.remote().push(pushed_branch) + except git.exc.GitCommandError as e: - if "protected branches" not in e.stderr: - raise errors.GitError("Cannot push changes") from e - # push to new remote branch if original one is protected - pushed_branch = uuid4().hex - origin = repo.create_remote(pushed_branch, remote) - origin.push(repo.active_branch) + raise errors.GitError("Cannot push changes") from e return saved_paths, pushed_branch diff --git a/tests/service/views/test_dataset_views.py b/tests/service/views/test_dataset_views.py index bf5bbe5b9b..9d3fa27193 100644 --- a/tests/service/views/test_dataset_views.py +++ b/tests/service/views/test_dataset_views.py @@ -945,7 +945,8 @@ def test_edit_datasets_view(svc_client_with_repo): def test_protected_branch(svc_protected_repo): """Test adding a file to protected branch.""" svc_client, headers, payload, response = svc_protected_repo - assert response + + assert_rpc_response(response) assert {"result"} == set(response.json.keys()) payload = { @@ -954,11 +955,8 @@ def test_protected_branch(svc_protected_repo): } response = svc_client.post("/datasets.create", data=json.dumps(payload), headers=headers,) - assert response - if "error" in response.json.keys() and response.json["error"]["migration_required"]: - # TODO: Fix this test to work with new project versions - return + assert_rpc_response(response) assert {"result"} == set(response.json.keys()) assert "master" != response.json["result"]["remote_branch"]