# Pre-Receive with no configuration

Here is an example of a pre-receive hook that disables deleting of branches. Note that there isn't any configuration
required; this hook only has to be enabled.
The source is available for download from Bitbucket [here](https://bitbucket.org/atlassian/bitbucket-example-pre-receive-no-config).

## src/main/resources/atlassian-plugin.xml

```xml
<?xml version="1.0" encoding="UTF-8"?>
<atlassian-plugin key="${project.groupId}.${project.artifactId}" name="${project.name}" plugins-version="2">
    <plugin-info>
        <description>A simple repository plugin for rejecting branch deletion</description>
        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
        <version>${project.version}</version>
    </plugin-info>

    <repository-hook key="examplehook" name="Disable Branch Deletion" class="com.mycompany.example.plugin.myhook.MyRepositoryHook">
        <description>Disables deletion of all branches in this repository.</description>
        <icon>icons/example.png</icon>
    </repository-hook>

</atlassian-plugin>
```

## src/main/java/com/mycompany/example/plugin/myhook/MyRepositoryHook.java

```java
package com.mycompany.example.plugin.myhook;

import com.atlassian.bitbucket.hook.*;
import com.atlassian.bitbucket.hook.repository.*;
import com.atlassian.bitbucket.repository.*;

import javax.annotation.Nonnull;
import java.util.Collection;

public class MyRepositoryHook implements PreReceiveRepositoryHook {

    /**
     * Disables deletion of branches
     */
    @Override
    public boolean onReceive(@Nonnull RepositoryHookContext context,
                             @Nonnull Collection<RefChange> refChanges,
                             @Nonnull HookResponse hookResponse) {
        for (RefChange refChange : refChanges) {
            if (refChange.getType() == RefChangeType.DELETE) {
                hookResponse.err().println("The ref '" + refChange.getRefId() + "' cannot be deleted.");
                return false;
            }
        }
        return true;
    }
}
```

The [HookResponse](https://developer.atlassian.com/static/javadoc/bitbucket-server/${project.version}/api/reference/com/atlassian/bitbucket/hook/HookResponse.html)
class has both error and output writers, both of which will be displayed to the client.
