Merge lp:~cjwatson/launchpad/git-recipe-delete into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 17895
Proposed branch: lp:~cjwatson/launchpad/git-recipe-delete
Merge into: lp:launchpad
Prerequisite: lp:~cjwatson/launchpad/git-recipe-find
Diff against target: 92 lines (+30/-8)
3 files modified
lib/lp/code/model/branch.py (+3/-7)
lib/lp/code/model/gitrepository.py (+5/-0)
lib/lp/code/model/tests/test_gitrepository.py (+22/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/git-recipe-delete
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+282256@code.launchpad.net

Commit message

Handle recipes when deleting Git repositories.

Description of the change

Handle recipes when deleting Git repositories.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2015-10-19 10:48:28 +0000
+++ lib/lp/code/model/branch.py 2016-01-14 20:27:26 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2015 Canonical Ltd. This software is licensed under the1# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -860,7 +860,8 @@
860 alteration_operations.extend(860 alteration_operations.extend(
861 map(ClearOfficialPackageBranch, series_set.findForBranch(self)))861 map(ClearOfficialPackageBranch, series_set.findForBranch(self)))
862 deletion_operations.extend(862 deletion_operations.extend(
863 DeletionCallable.forSourcePackageRecipe(recipe)863 DeletionCallable(
864 recipe, _('This recipe uses this branch.'), recipe.destroySelf)
864 for recipe in self.recipes)865 for recipe in self.recipes)
865 if not getUtility(ISnapSet).findByBranch(self).is_empty():866 if not getUtility(ISnapSet).findByBranch(self).is_empty():
866 alteration_operations.append(DeletionCallable(867 alteration_operations.append(DeletionCallable(
@@ -1498,11 +1499,6 @@
1498 def __call__(self):1499 def __call__(self):
1499 self.func(*self.args, **self.kwargs)1500 self.func(*self.args, **self.kwargs)
15001501
1501 @classmethod
1502 def forSourcePackageRecipe(cls, recipe):
1503 return cls(
1504 recipe, _('This recipe uses this branch.'), recipe.destroySelf)
1505
15061502
1507class ClearDependentBranch(DeletionOperation):1503class ClearDependentBranch(DeletionOperation):
1508 """Delete operation that clears a merge proposal's prerequisite branch."""1504 """Delete operation that clears a merge proposal's prerequisite branch."""
15091505
=== modified file 'lib/lp/code/model/gitrepository.py'
--- lib/lp/code/model/gitrepository.py 2016-01-14 20:27:26 +0000
+++ lib/lp/code/model/gitrepository.py 2016-01-14 20:27:26 +0000
@@ -1047,6 +1047,11 @@
1047 prerequisite_git_repository=self):1047 prerequisite_git_repository=self):
1048 alteration_operations.append(1048 alteration_operations.append(
1049 ClearPrerequisiteRepository(merge_proposal))1049 ClearPrerequisiteRepository(merge_proposal))
1050 deletion_operations.extend(
1051 DeletionCallable(
1052 recipe, msg("This recipe uses this repository."),
1053 recipe.destroySelf)
1054 for recipe in self.recipes)
1050 if not getUtility(ISnapSet).findByGitRepository(self).is_empty():1055 if not getUtility(ISnapSet).findByGitRepository(self).is_empty():
1051 alteration_operations.append(DeletionCallable(1056 alteration_operations.append(DeletionCallable(
1052 None, msg("Some snap packages build from this repository."),1057 None, msg("Some snap packages build from this repository."),
10531058
=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
--- lib/lp/code/model/tests/test_gitrepository.py 2015-12-10 00:05:41 +0000
+++ lib/lp/code/model/tests/test_gitrepository.py 2016-01-14 20:27:26 +0000
@@ -1,4 +1,4 @@
1# Copyright 2015 Canonical Ltd. This software is licensed under the1# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Tests for Git repositories."""4"""Tests for Git repositories."""
@@ -452,6 +452,19 @@
452 [ReclaimGitRepositorySpaceJob(job).repository_path452 [ReclaimGitRepositorySpaceJob(job).repository_path
453 for job in jobs])453 for job in jobs])
454454
455 def test_destroySelf_with_SourcePackageRecipe(self):
456 # If repository is a base_git_repository in a recipe, it is deleted.
457 recipe = self.factory.makeSourcePackageRecipe(
458 branches=self.factory.makeGitRefs(owner=self.user))
459 recipe.base_git_repository.destroySelf(break_references=True)
460
461 def test_destroySelf_with_SourcePackageRecipe_as_non_base(self):
462 # If repository is referred to by a recipe, it is deleted.
463 [ref1] = self.factory.makeGitRefs(owner=self.user)
464 [ref2] = self.factory.makeGitRefs(owner=self.user)
465 self.factory.makeSourcePackageRecipe(branches=[ref1, ref2])
466 ref2.repository.destroySelf(break_references=True)
467
455 def test_destroySelf_with_inline_comments_draft(self):468 def test_destroySelf_with_inline_comments_draft(self):
456 # Draft inline comments related to a deleted repository (source or469 # Draft inline comments related to a deleted repository (source or
457 # target MP repository) also get removed.470 # target MP repository) also get removed.
@@ -683,6 +696,14 @@
683 self.assertRaises(696 self.assertRaises(
684 SQLObjectNotFound, BranchMergeProposal.get, merge_proposal_id)697 SQLObjectNotFound, BranchMergeProposal.get, merge_proposal_id)
685698
699 def test_deletionRequirements_with_SourcePackageRecipe(self):
700 # Recipes are listed as deletion requirements.
701 recipe = self.factory.makeSourcePackageRecipe(
702 branches=self.factory.makeGitRefs())
703 self.assertEqual(
704 {recipe: ("delete", "This recipe uses this repository.")},
705 recipe.base_git_repository.getDeletionRequirements())
706
686707
687class TestGitRepositoryModifications(TestCaseWithFactory):708class TestGitRepositoryModifications(TestCaseWithFactory):
688 """Tests for Git repository modifications."""709 """Tests for Git repository modifications."""