Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Native Node bindings to Git.

License

NotificationsYou must be signed in to change notification settings

nodegit/nodegit

Repository files navigation

Node bindings to thelibgit2 project.

Actions Status

Stable (libgit2@v0.28.3): 0.28.3

Have a problem? Come chat with us!

Visitslack.libgit2.org to sign up, then join us in #nodegit.

Maintained by

Tyler Ang-Wanek@twwanek with help from tons ofawesome contributors!

Alumni Maintainers

Tim Branyen@tbranyen,John Haley@johnhaley81,Max Korp@maxkorp,Steve Smith@orderedlist,Michael Robinson@codeofinterest, andNick Kallen@nk

API Documentation.

http://www.nodegit.org/

Getting started.

NodeGit will work on most systems out-of-the-box without any nativedependencies.

npm install nodegit

If you receive errors about libstdc++, which are commonly experienced whenbuilding on Travis-CI, you can fix this by upgrading to the latestlibstdc++-4.9.

In Ubuntu:

sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt-get updatesudo apt-get install libstdc++-4.9-dev

In Travis:

addons:apt:sources:      -ubuntu-toolchain-r-testpackages:      -libstdc++-4.9-dev

In 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

If you receive errors aboutlifecycleScripts preinstall/install you probably misslibssl-devIn Ubuntu:

sudo apt-get install libssl-dev

You will need the following libraries installed on your linux machine:

  • libpcre
  • libpcreposix
  • libkrb5
  • libk5crypto
  • libcom_err

When building locally, you will also need development packages for kerberos and pcre, so both of these utilities must be present on your machine:

  • pcre-config
  • krb5-config

If you are still encountering problems while installing, you should try theBuilding from sourceinstructions.

API examples.

Cloning a repository and reading a file:

varGit=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.returnrepo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");})// Look up a specific file within that commit..then(function(commit){returncommit.getEntry("README.md");})// Get the blob contents from the file..then(function(entry){// Patch the blob to contain a reference to the entry.returnentry.getBlob().then(function(blob){blob.entry=entry;returnblob;});})// 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("=")+"\n\n");// Show the entire file.console.log(String(blob));}).catch(function(err){console.log(err);});

Emulating git log:

varGit=require("nodegit");// Open the repository directory.Git.Repository.open("tmp")// Open the master branch..then(function(repo){returnrepo.getMasterCommit();})// Display information about commits on master..then(function(firstCommitOnMaster){// Create a new history event emitter.varhistory=firstCommitOnMaster.history();// Create a counter to only show up to 9 entries.varcount=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.varauthor=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();});

For more examples, check theexamples/ folder.

Unit tests.

You will need to build locally before running the tests. See above.

npmtest

[8]ページ先頭

©2009-2025 Movatter.jp