2017-09-07 19 views
2

我目前使用nodegit來運行我的git命令,它除了刪除一個遠程分支以外,一直工作到目前爲止。如果需要,我不介意使用另一個npm軟件包來執行此操作,但我更願意使用nodegit。如何使用Node.js刪除遠程分支?

基本上,我希望有一個功能,可以這樣做,因爲這命令,在終端

$ git push -d <branch_name> 

我希望能夠寫出像下面這樣:

function delete_remote_branch(repo, branch_name, callback) { 
    repo.getRemote('origin').then(function(remote) { 
    repo.getBranch(branch_name).then(function(reference) { 
     // delete the branch 
     repo.push("-d :"+reference, branch_name).then(function(error_code) { 
     if(error_code) { 
      return callback(error_code) 
     } 
     return callback(null) 
     }) 
    }) 
    }) 
} 

的文檔remote.push在這裏:http://www.nodegit.org/api/remote/#push

任何幫助,將不勝感激。謝謝!

+0

刪除引用是通過推空的本地引用它,就像你可以用Git的push命令做完成。因此按[「:refs/heads/branch_name」]會刪除遠程分支。 –

回答

0

將空的src引用推送到原始分支。

remote.push(':refs/heads/my-branch'); 
+0

謝謝,我稍後再試一試,如果它能正常工作,那麼我會將其標記爲正確:) –

+0

是的,測試了一下,結果成功了!非常感謝! –