package com.atlassian.bitbucket.mesh.git.builder.merge;

import com.atlassian.bitbucket.mesh.process.handler.AbstractLineStdioHandler;

import javax.annotation.Nonnull;
import java.nio.charset.StandardCharsets;

public class FirstMergeBaseStdioHandler extends AbstractLineStdioHandler<String> {

    private String commonAncestor;

    public FirstMergeBaseStdioHandler() {
        super(StandardCharsets.UTF_8);
    }

    @Override
    public String getResult() {
        return commonAncestor;
    }

    @Override
    protected boolean onStdout(@Nonnull String line, boolean truncated) {
        if (commonAncestor == null) {
            commonAncestor = line;
        }

        return true;
    }
}
