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

Proposed by Colin Watson on 2016-01-12
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 2016-01-12 Approve on 2016-01-14
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.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branch.py'
2--- lib/lp/code/model/branch.py 2015-10-19 10:48:28 +0000
3+++ lib/lp/code/model/branch.py 2016-01-14 20:27:26 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2015 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 __metaclass__ = type
10@@ -860,7 +860,8 @@
11 alteration_operations.extend(
12 map(ClearOfficialPackageBranch, series_set.findForBranch(self)))
13 deletion_operations.extend(
14- DeletionCallable.forSourcePackageRecipe(recipe)
15+ DeletionCallable(
16+ recipe, _('This recipe uses this branch.'), recipe.destroySelf)
17 for recipe in self.recipes)
18 if not getUtility(ISnapSet).findByBranch(self).is_empty():
19 alteration_operations.append(DeletionCallable(
20@@ -1498,11 +1499,6 @@
21 def __call__(self):
22 self.func(*self.args, **self.kwargs)
23
24- @classmethod
25- def forSourcePackageRecipe(cls, recipe):
26- return cls(
27- recipe, _('This recipe uses this branch.'), recipe.destroySelf)
28-
29
30 class ClearDependentBranch(DeletionOperation):
31 """Delete operation that clears a merge proposal's prerequisite branch."""
32
33=== modified file 'lib/lp/code/model/gitrepository.py'
34--- lib/lp/code/model/gitrepository.py 2016-01-14 20:27:26 +0000
35+++ lib/lp/code/model/gitrepository.py 2016-01-14 20:27:26 +0000
36@@ -1047,6 +1047,11 @@
37 prerequisite_git_repository=self):
38 alteration_operations.append(
39 ClearPrerequisiteRepository(merge_proposal))
40+ deletion_operations.extend(
41+ DeletionCallable(
42+ recipe, msg("This recipe uses this repository."),
43+ recipe.destroySelf)
44+ for recipe in self.recipes)
45 if not getUtility(ISnapSet).findByGitRepository(self).is_empty():
46 alteration_operations.append(DeletionCallable(
47 None, msg("Some snap packages build from this repository."),
48
49=== modified file 'lib/lp/code/model/tests/test_gitrepository.py'
50--- lib/lp/code/model/tests/test_gitrepository.py 2015-12-10 00:05:41 +0000
51+++ lib/lp/code/model/tests/test_gitrepository.py 2016-01-14 20:27:26 +0000
52@@ -1,4 +1,4 @@
53-# Copyright 2015 Canonical Ltd. This software is licensed under the
54+# Copyright 2015-2016 Canonical Ltd. This software is licensed under the
55 # GNU Affero General Public License version 3 (see the file LICENSE).
56
57 """Tests for Git repositories."""
58@@ -452,6 +452,19 @@
59 [ReclaimGitRepositorySpaceJob(job).repository_path
60 for job in jobs])
61
62+ def test_destroySelf_with_SourcePackageRecipe(self):
63+ # If repository is a base_git_repository in a recipe, it is deleted.
64+ recipe = self.factory.makeSourcePackageRecipe(
65+ branches=self.factory.makeGitRefs(owner=self.user))
66+ recipe.base_git_repository.destroySelf(break_references=True)
67+
68+ def test_destroySelf_with_SourcePackageRecipe_as_non_base(self):
69+ # If repository is referred to by a recipe, it is deleted.
70+ [ref1] = self.factory.makeGitRefs(owner=self.user)
71+ [ref2] = self.factory.makeGitRefs(owner=self.user)
72+ self.factory.makeSourcePackageRecipe(branches=[ref1, ref2])
73+ ref2.repository.destroySelf(break_references=True)
74+
75 def test_destroySelf_with_inline_comments_draft(self):
76 # Draft inline comments related to a deleted repository (source or
77 # target MP repository) also get removed.
78@@ -683,6 +696,14 @@
79 self.assertRaises(
80 SQLObjectNotFound, BranchMergeProposal.get, merge_proposal_id)
81
82+ def test_deletionRequirements_with_SourcePackageRecipe(self):
83+ # Recipes are listed as deletion requirements.
84+ recipe = self.factory.makeSourcePackageRecipe(
85+ branches=self.factory.makeGitRefs())
86+ self.assertEqual(
87+ {recipe: ("delete", "This recipe uses this repository.")},
88+ recipe.base_git_repository.getDeletionRequirements())
89+
90
91 class TestGitRepositoryModifications(TestCaseWithFactory):
92 """Tests for Git repository modifications."""