2017-06-29 44 views
0

我們如何從git存儲庫獲取標籤並按其相關提交日期對它們進行排序?如何使用nodegit按日期排序標籤?

Tag.list只返回名稱,Tag.lookup需要一個OID,所以我們如何填寫將標籤名稱轉換爲標籤或標籤ID的缺失部分? (!)

回答

0

閱讀... luagit2後的文檔以實際瞭解libgit作品,這裏是一個解決方案:

nodegit.Repository.open(repoPath).then(repo => 
    nodegit.Tag.list(repo) 
    .then(list => 
    Promise.all(
     list.map(tagName => 
     nodegit.Reference.lookup(repo, `refs/tags/${tagName}`) 
     .then(ref => nodegit.Commit.lookup(repo, ref.target())) 
     .then(commit => ({ 
      tag: tagName, 
      date: commit.date().toJSON(), 
     })) 
    ) 
    ) 
) 
    .then(tags => tags.sort((a, b) => (a.date < b.date ? -1 : 1)))