Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent deletion of default branch #1827

Merged
merged 5 commits into from Oct 19, 2021

Conversation

pfeuffer
Copy link
Member

Proposed changes

Adds a pre receive repository hook that prevents the deletion of the default branch.

Mirrored repositories will change their default branches to another branch, when it is deleted.

Your checklist for this pull request

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Contributor:

  • PR is well described and the description can be used as a commit message on squash
  • New code is covered with unit tests
  • Changelog entry file created in gradle/changelog or CHANGELOG.md is updated for plugins

Reviewer:

  • The clean code principles are respected (CleanCode)
  • All new code/logic is implemented on the right spot / "Should this be done here?"
  • UI changes fits into the layout
  • The UI views / components are responsive (mobile views)
  • Correct translations are available

Checklist for branch merge request (not required for forks)

@@ -0,0 +1,2 @@
- type: Changed
description: The default branch of a repository cannot be deleted ([#1827](https://github.com/scm-manager/scm-manager/pull/1827))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: The default branch of a repository cannot be deleted ([#1827](https://github.com/scm-manager/scm-manager/pull/1827))
description: The default branch of a git repository cannot be deleted ([#1827](https://github.com/scm-manager/scm-manager/pull/1827))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work for hg, too (though currently it doesn't)

}

gitHeadModifier.ensure(repository, newDefaultBranch);
storeProvider.get(repository).get().setDefaultBranch(newDefaultBranch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the reference of the config does not persist the changes nor triggers update events. You have to call the set method of the store.

@sonarcloud
Copy link

sonarcloud bot commented Oct 18, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

90.6% 90.6% Coverage
0.0% 0.0% Duplication

@sdorra sdorra merged commit 39e367b into develop Oct 19, 2021
@sdorra sdorra deleted the feature/prevent_default_branch_from_deletion branch October 19, 2021 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants