nodegit
v0.27.0 (2020-07-28)
節點綁定與libgit2項目。
穩定([email protected]):0.28.3
請訪問Slack.libgit2.org註冊,然後加入#NodeGit。
泰勒·安·瓦尼克(Tyler Ang-Wanek)@Twwanek在大量出色的貢獻者的幫助下!
Tim Branyen @Tbranyen,John Haley @Johnhaley81,Max Korp @maxkorp,Steve Smith @orderedlist,Michael Robinson @codeofinterest和Nick Kallen @NK
http://www.nodegit.org/
Nodegit將在大多數開箱即用,而無需任何本機依賴。
npm install nodegit如果您收到有關libstdc ++的錯誤,這些錯誤通常是在Travis-CI上構建時經歷的,則可以通過升級到最新的LIBSTDC ++ -4.9來解決此問題。
在Ubuntu:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install libstdc++-4.9-dev在特拉維斯:
addons :
apt :
sources :
- ubuntu-toolchain-r-test
packages :
- libstdc++-4.9-dev在Circleci:
dependencies :
pre :
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update
- sudo apt-get install -y libstdc++-4.9-dev如果您收到有關LifeCycleScript的錯誤,請啟動/安裝,您可能會錯過Ubuntu中的Libssl-Dev :
sudo apt-get install libssl-dev
您需要在Linux機上安裝以下庫:
在本地構建時,您還需要Kerberos和PCRE的開發包,因此機器上必須存在這兩個公用事業:
如果您在安裝時仍遇到問題,則應從源說明中嘗試建築物。
var Git = require ( "nodegit" ) ;
// Clone a given repository into the `./tmp` folder.
Git . Clone ( "https://github.com/nodegit/nodegit" , "./tmp" )
// Look up this known commit.
. then ( function ( repo ) {
// Use a known commit sha from this repository.
return repo . getCommit ( "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5" ) ;
} )
// Look up a specific file within that commit.
. then ( function ( commit ) {
return commit . getEntry ( "README.md" ) ;
} )
// Get the blob contents from the file.
. then ( function ( entry ) {
// Patch the blob to contain a reference to the entry.
return entry . getBlob ( ) . then ( function ( blob ) {
blob . entry = entry ;
return blob ;
} ) ;
} )
// Display information about the blob.
. then ( function ( blob ) {
// Show the path, sha, and filesize in bytes.
console . log ( blob . entry . path ( ) + blob . entry . sha ( ) + blob . rawsize ( ) + "b" ) ;
// Show a spacer.
console . log ( Array ( 72 ) . join ( "=" ) + "nn" ) ;
// Show the entire file.
console . log ( String ( blob ) ) ;
} )
. catch ( function ( err ) { console . log ( err ) ; } ) ; var Git = require ( "nodegit" ) ;
// Open the repository directory.
Git . Repository . open ( "tmp" )
// Open the master branch.
. then ( function ( repo ) {
return repo . getMasterCommit ( ) ;
} )
// Display information about commits on master.
. then ( function ( firstCommitOnMaster ) {
// Create a new history event emitter.
var history = firstCommitOnMaster . history ( ) ;
// Create a counter to only show up to 9 entries.
var count = 0 ;
// Listen for commit events from the history.
history . on ( "commit" , function ( commit ) {
// Disregard commits past 9.
if ( ++ count >= 9 ) {
return ;
}
// Show the commit sha.
console . log ( "commit " + commit . sha ( ) ) ;
// Store the author object.
var author = commit . author ( ) ;
// Display author information.
console . log ( "Author:t" + author . name ( ) + " <" + author . email ( ) + ">" ) ;
// Show the commit date.
console . log ( "Date:t" + commit . date ( ) ) ;
// Give some space and show the message.
console . log ( "n " + commit . message ( ) ) ;
} ) ;
// Start emitting events.
history . start ( ) ;
} ) ;有關更多示例,請檢查examples/文件夾。
在進行測試之前,您需要在本地建立。見上文。
npm test