package com.atlassian.bitbucket.mesh.git.exception;

import com.atlassian.bitbucket.mesh.repository.Repository;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcDetachedHead;
import com.atlassian.bitbucket.mesh.rpc.v1.RpcGitError;
import io.grpc.Status;

import javax.annotation.Nonnull;

import static java.util.Objects.requireNonNull;

public class DetachedHeadException extends AbstractGitException {

    public DetachedHeadException(@Nonnull Repository repository) {
        super("Repository + " + requireNonNull(repository) + " has a detached head, which is not supported",
                Status.FAILED_PRECONDITION);
    }

    @Nonnull
    @Override
    public RpcGitError toError() {
        return RpcGitError.newBuilder()
                .setDetachedHead(RpcDetachedHead.getDefaultInstance())
                .build();
    }
}
