From 24efe4d19696dcd781db29920760f22e8e1eb18b Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Nov 30 2020 14:12:00 +0000 Subject: Allow deleting the master branch when it is not the default branch Fixes https://pagure.io/pagure/issue/5050 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 06afb71..4660a86 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -2694,9 +2694,15 @@ def delete_branch(repo, branchname, username=None, namespace=None): if six.PY2: branchname = branchname.encode("utf-8") - if branchname == "master": + default_branchname = "master" + if not repo_obj.is_empty and not repo_obj.head_is_unborn: + default_branchname = repo_obj.head.shorthand + + if branchname == default_branchname: flask.abort( - 403, description="You are not allowed to delete the master branch" + 403, + description="You are not allowed to delete the default " + "branch: %s" % default_branchname, ) if branchname not in repo_obj.listall_branches(): diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index e816e7f..109c7cf 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -5770,7 +5770,7 @@ index 0000000..fb7093d self.assertEqual(output.status_code, 403) output_text = output.get_data(as_text=True) self.assertIn( - "

You are not allowed to delete the master branch

", + "

You are not allowed to delete the default branch: master

", output_text, ) @@ -5864,6 +5864,49 @@ index 0000000..fb7093d output_text = output.get_data(as_text=True) self.assertNotIn('