2016-06-28 9 views
0

서버에있는 git repo의 로컬 브랜치 목록을 사용자에게 보내야하는 노드 API 서버를 작성 중입니다. 장소의 많은 NodeGit에서 Repository#getReferenceNames을 사용하는 것이 좋습니다 이것은 내가 할 것입니다 :NodeGit 로컬 지점 목록을 얻으려면 어떻게해야합니까?

exports.getBranches = function (req, res) { 
    NodeGit.Repository.open(config.database).then(function(repo) { 
     return repo.getReferenceNames(NodeGit.Reference.TYPE.LISTALL); 
    }).then(function (arrayString) { 
     res.status(200).json({message: "OK", data: arrayString}); 
    }).catch(function (err) { 
     res.status(500).json({message: err, data: []}); 
    }).done(function() { 
     console.log("finish"); 
    }); 
}; 

그러나,이 기능은 모든 지점을 반환합니다. 거기에 명령 줄처럼 로컬 지점을 얻을 수있는 방법이 있습니까 git branch합니까?

답변

2

물론 있습니다! 원격 지사가 앞에 둔 심판/리모트 동안 지역 지점은 다음과 같이, 심판/머리를 접두어 :

enter image description here

행운을 빕니다!

편집 :

심지어 더 나은 방법이있다. 반환 된 참조를 반환하기 전에이를 트래버스하고 reference.isRemote()를 사용하여 원격을 제거 할 수 있습니다.