← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:forked-repo-owner-default into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:forked-repo-owner-default into launchpad:master.

Commit message:
Setting forked repo as owner-default if no other repo is set that way.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/392381
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:forked-repo-owner-default into launchpad:master.
diff --git a/lib/lp/code/xmlrpc/git.py b/lib/lp/code/xmlrpc/git.py
index 0ebcde0..ae95c44 100644
--- a/lib/lp/code/xmlrpc/git.py
+++ b/lib/lp/code/xmlrpc/git.py
@@ -35,6 +35,7 @@ from lp.code.enums import (
     GitRepositoryType,
     )
 from lp.code.errors import (
+    GitDefaultConflict,
     GitRepositoryCreationException,
     GitRepositoryCreationFault,
     GitRepositoryCreationForbidden,
@@ -660,6 +661,13 @@ class GitAPI(LaunchpadXMLRPCView):
             requester, naked_repo, auth_params)
         naked_repo.rescan()
         naked_repo.status = GitRepositoryStatus.AVAILABLE
+        try:
+            # Try to set the new repo as owner-default.
+            naked_repo.setOwnerDefault(True)
+        except GitDefaultConflict:
+            # If there is already a owner-default for this owner/target,
+            # just move on.
+            pass
 
     def confirmRepoCreation(self, translated_path, auth_params):
         """See `IGitAPI`."""
diff --git a/lib/lp/code/xmlrpc/tests/test_git.py b/lib/lp/code/xmlrpc/tests/test_git.py
index dcbcee6..d042807 100644
--- a/lib/lp/code/xmlrpc/tests/test_git.py
+++ b/lib/lp/code/xmlrpc/tests/test_git.py
@@ -291,8 +291,9 @@ class TestGitAPIMixin:
              "writable": writable, "trailing": trailing, "private": private},
             translation)
 
-    def assertConfirmsRepoCreation(self, requester, git_repository,
-                                   can_authenticate=True, macaroon_raw=None):
+    def assertConfirmsRepoCreation(
+            self, requester, git_repository, can_authenticate=True,
+            macaroon_raw=None, is_owner_default=True):
         # Puts some refs in git hosting, to make sure we scanned them.
         sha1 = lambda x: hashlib.sha1(x).hexdigest()
         self.hosting_fixture = self.useFixture(
@@ -325,6 +326,7 @@ class TestGitAPIMixin:
         self.assertIsNone(result)
         Store.of(git_repository).invalidate(git_repository)
         self.assertEqual(GitRepositoryStatus.AVAILABLE, git_repository.status)
+        self.assertEqual(is_owner_default, git_repository.owner_default)
         # Should have checked the refs at some point.
         excluded_prefixes = config.codehosting.git_exclude_ref_prefixes
         self.assertEqual(
@@ -355,6 +357,7 @@ class TestGitAPIMixin:
         if store:
             store.invalidate(git_repository)
         self.assertEqual(original_status, git_repository.status)
+        self.assertFalse(git_repository.owner_default)
 
     def assertConfirmRepoCreationUnauthorized(
             self, requester, git_repository, can_authenticate=True,
@@ -821,6 +824,16 @@ class TestGitAPI(TestGitAPIMixin, TestCaseWithFactory):
         repo.status = GitRepositoryStatus.CREATING
         self.assertConfirmsRepoCreation(owner, repo)
 
+    def test_confirm_git_repository_creation_not_owner_default(self):
+        owner = self.factory.makePerson()
+        # Create a repository that is already a owner_default.
+        first_repo = self.factory.makeGitRepository(owner=owner)
+        first_repo.setOwnerDefault(True)
+        repo = removeSecurityProxy(self.factory.makeGitRepository(
+            owner=owner, target=first_repo.target))
+        repo.status = GitRepositoryStatus.CREATING
+        self.assertConfirmsRepoCreation(owner, repo, is_owner_default=False)
+
     def test_launchpad_service_confirm_git_repository_creation(self):
         owner = self.factory.makePerson()
         repo = removeSecurityProxy(self.factory.makeGitRepository(owner=owner))