package com.atlassian.bitbucket.scm.git;

import com.atlassian.bitbucket.i18n.KeyedMessage;

import javax.annotation.Nullable;

/**
 * Exception thrown to indicate the bare clone backing a repository has a detached HEAD, which is an unsupported
 * configuration.
 * <p>
 * Note: The only way the bare clone backing a repository can end up in a detached HEAD state is if it is directly
 * modified on disk. The system will <i>never</i> produce this configuration during normal operation.
 */
public class GitDetachedHeadException extends GitException {
    
    private final String commitId;

    public GitDetachedHeadException(KeyedMessage message, String commitId) {
        super(message);

        this.commitId = commitId;
    }

    /**
     * Retrieves the ID of the commit referenced by the detached head.
     *
     * @return the detached commit ID
     */
    @Nullable
    public String getCommitId() {
        return commitId;
    }
}
