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

orderedlist/nodegit

 
 

Repository files navigation

Node bindings to thelibgit2 project.

LinuxOS XWindowsDependencies

Stable: 0.2.7

Have a problem? Come chat with us!

[Gitter](https://gitter.im/nodegit/nodegit)

Maintained by

Tim Branyen@tbranyen,John Haley@johnhaley81,Max Korp@maxkorp, andSteve Smith@orderedlist with help from tons ofawesome contributors!

Alumni Maintainers

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 encounter problems while installing, you should try the Building fromsource instructions below.

Building from source.

If you wish to help contribute to NodeGit it is useful to build locally.

# Fetch this project.git clone git://github.com/nodegit/nodegit.git# Enter the repository.cd nodegit# Install all dependencies, run the code generation scripts, and build.npm install

If you encounter errors, you most likely have not configured the dependencies correctly.

Installing dependencies:

Mac OS X

Linux

Using APT in Ubuntu:

sudo apt-get install build-essential

Using Pacman in Arch Linux:

sudo pacman -S base-devel

Note that GCC/G++ 4.7+ are required, as the library makes use of some c++11 std calls.

Windows

You may have to add a build flag to the installation process to successfully install.
Try first without, if the build fails, try again with the flag.

Allegedly the order in which you install Visual Studio could trigger this error.

npm install nodegit --msvs_version=2013# Or whatever version you've installed.
A note on environment variables in Windows

In many of the npm scripts (and examples above), things are run likeBUILD_ONLY=true npm install. This sets theBUILD_ONLY environment variableto true for the duration of that command. This doesn't work in windows, howeverthere is a solution. You can use cmd to call a command inside of cmd (very meta)with the variable set, and it only lasts for the duration of the inner call to cmd.So for the above example, you would runcmd /C "set BUILD_ONLY=true && npm install".See here for more details:SuperUser.

Debug build:

In order to track down possible bugs, you will need a debug buid so youcan get a backtrace withgdb orlldb.

If you're building for the first time, runnpm run installDebug (orBUILD_ONLY=true npm link)

Note that you should runrm -rf build/Release (orrd /s /q build/Release in Windows) to make sure a release build doesn't get loaded instead of the debug build.

If you're doing a subsequent rebuild of NodeGit in debug, the clean function will cause a lot of extraneous recompilation of things you probably didn't change (like the vendor dependencies). If you need to regenerate the C++ files and recompile you can runnpm run rebuildDebug, ornpm run recompileDebug if you've manually updated the C++ files and don't want them to regenerate.

API examples.

Cloning a repository and reading a file:

varclone=require("./").Clone.clone;// Clone a given repository into a specific folder.clone("https://github.com/nodegit/nodegit","tmp",null)// 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 name, sha, and filesize in byes.console.log(blob.entry.name()+blob.entry.sha()+blob.size()+"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:

varopen=require("nodegit").Repository.open;// Open the repository directory.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

Migrating from old versions.

The bump from 0.1.4 to 0.2.0 was a big one. Many things changed, see here:https://github.com/nodegit/nodegit/compare/refs/tags/0.1.4...0.2.0

This update is wholly and entirely a breaking one, and older versions won't bemaintained. For the purpose of migration, perhaps the biggest point to makeis that async methods can now use promises, rather than just taking callbacks.Additionally, lots of method and property names have changed.

nw.js (Node-Webkit)

Native compilation for nw.js

A common issue is with NodeGit not functioning properly inside ofnw.js applications. Because NodeGitis a native module, it has to be rebuilt for node-webkit usingnw-gyp. By default, NodeGit will lookin the root package's package.json for anengines property, and within lookfor anw.js property (or anode-webkit if the prior isn't found) that holdsa specific version of nw.js. The value of this property is what will get passedas the--target argument tonw-gyp configure.

Version incompatibility

Prior to version 0.2.6, NodeGit usednan v1.4.3.As of 0.2.6, NodeGit uses nan v1.5.1 to provide support for io.js. Unfortunately,this breaks some nw.js compatibility. With nw.js 0.12+, the name was changed tonw.js from node-webkit. The alpha currently still breaks with NodeGit due to thenan update, but should be fixed in the final v0.12.0 release. Åpplications usingprevious versions of node webkit have 2 options:

  1. Use an older version (v0.2.4 or earlier) of NodeGit
  2. Usenpm shrinkwrap to force NodeGit touse nan v1.4.3. Since the binary always recompiles when being used with nw.js, youshouldn't have to do anything else to make sure it works. As of NodeGit v0.2.6,the change to nan v1.4.3 doesn't cause any problems.

Currently, support for nw.js is limited, although we intend to support it betterin the future.

About

Native Node bindings to Git.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript79.8%
  • C++19.3%
  • Other0.9%

[8]ページ先頭

©2009-2025 Movatter.jp