protected void addBranchesAsChildren ( Git git , CallSpecification spec , DocumentWriter writer ) throws GitAPIException { Set < String > remoteBranchPrefixes = remoteBranchPrefixes ( ) ; if ( remoteBranchPrefixes . isEmpty ( ) ) { // Generate the child references to the LOCAL branches, which will be sorted by name ... ListBranchCommand command = git . branchList ( ) ; List < Ref > branches = command . call ( ) ; // Reverse the sort of the branch names, since they might be version numbers ... Collections . sort ( branches , REVERSE_REF_COMPARATOR ) ; for ( Ref ref : branches ) { String name = ref . getName ( ) ; name = name . replace ( GitFunction . LOCAL_BRANCH_PREFIX , "" ) ; writer . addChild ( spec . childId ( name ) , name ) ; } return ; } // There is at least one REMOTE branch, so generate the child references to the REMOTE branches, // which will be sorted by name (by the command)... ListBranchCommand command = git . branchList ( ) ; command . setListMode ( ListMode . REMOTE ) ; List < Ref > branches = command . call ( ) ; // Reverse the sort of the branch names, since they might be version numbers ... Collections . sort ( branches , REVERSE_REF_COMPARATOR ) ; Set < String > uniqueNames = new HashSet < String > ( ) ; for ( Ref ref : branches ) { String name = ref . getName ( ) ; if ( uniqueNames . contains ( name ) ) continue ; // We only want the branch if it matches one of the listed remotes ... boolean skip = false ; for ( String remoteBranchPrefix : remoteBranchPrefixes ) { if ( name . startsWith ( remoteBranchPrefix ) ) { // Remove the prefix ... name = name . replaceFirst ( remoteBranchPrefix , "" ) ; break ; } // Otherwise, it's a remote branch from a different remote that we don't want ... skip = true ; } if ( skip ) continue ; if ( uniqueNames . add ( name ) ) writer . addChild ( spec . childId ( name ) , name ) ; } }
Add the names of the branches as children of the current node .