import { AbstractStackBuilder } from '.' ; import { MultiParentError , SiblingBranchError } from '../lib/errors' ; import Branch from './branch' ; export default class GitStackBuilder extends AbstractStackBuilder { protected getBranchParent ( branch ) { return branch . getParentsFromGit ( ) [ 0 ] ; } protected getChildrenForBranch ( branch ) { this . checkSiblingBranches ( branch ) ; return branch . getChildrenFromGit ( ) ; } protected getParentForBranch ( branch ) { this . checkSiblingBranches ( branch ) ; const parents = branch . getParentsFromGit ( ) ; if ( parents . length > 1 ) { throw new MultiParentError ( branch , parents ) ; } return parents [ 0 ] ; } private checkSiblingBranches ( branch ) { const siblingBranches = branch . branchesWithSameCommit ( ) ; if ( siblingBranches . length > 0 ) { throw new SiblingBranchError ( [ branch ] . concat ( siblingBranches ) ) ; } } }