Coder Social home page Coder Social logo

nodegit.github.com's Introduction

NodeGit

Node bindings to the libgit2 project.

Actions Status

Stable ([email protected]): 0.28.3

Have a problem? Come chat with us!

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

Maintained by

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

Alumni Maintainers

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

API Documentation.

http://www.nodegit.org/

Getting started.

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

npm install nodegit

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

In Ubuntu:

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

In Travis:

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - 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 about lifecycleScripts preinstall/install you probably miss libssl-dev In 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 the Building from source instructions.

API examples.

Cloning a repository and reading a file:

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("=") + "\n\n");

    // Show the entire file.
    console.log(String(blob));
  })
  .catch(function(err) { console.log(err); });

Emulating git log:

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();
  });

For more examples, check the examples/ folder.

Unit tests.

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

npm test

nodegit.github.com's People

Contributors

aheuermann avatar chilts avatar dependabot[bot] avatar faceleg avatar implausible avatar isaacdurazo avatar johnhaley81 avatar maxkorp avatar mnquintana avatar novalis avatar orderedlist avatar srajko avatar tad-lispy avatar tbranyen avatar thgaskell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodegit.github.com's Issues

Include callback descriptions in docs

Right now we don't have any callback definitions in the docs which is a pretty big hole and kind of confusing for a new user.

We'll need to decorate the callbacks in nodegit with descriptions as well for this to work.

Listing available branches

I thought this would be simple but I just can't figure how to get a list of available branches.

Ive tried:

nodegit.Repository.open(thisHook.context.vars.req.cookies.gitRepo).then(function (repo) {

    nodegit.Branch.iteratorNew(repo, nodegit.Branch.BRANCH.ALL).then(function(branchIterator) {

     // What to do here?
     // tried branchIterator.forEach(function(item) {});
     // tried Object.keys(branchIterator)

    });

    })
    .catch(function (err) {
    console.log(err);
  }).done(function () {
    console.log('Finished');
  });

What is branchiterator and how do you use it? I noticed in a different issue that the docs for this are still missing (#24).

Could someone please provide a little info on how to list branches?

Thanks, Adam

Homepage

  • Getting started guide (pulled from guides folder?)
  • About our process esp. given our prebuilts (we compile so you don't have to)
  • Brought to you by...
  • Used by...
  • Recent blog posts?

Remove io.js and nw.js from homepage

We aren't supporting io.js anymore and I don't think nw.js has been working for a while. Nobody on the NodeGit maintainer team uses these technologies and we don't have the bandwidth to expand out to support them anymore.

Update github-pages dependency to work with latest Ruby (2.5.1)

After cloning the nodegit.github.io repo onto my system, I kept getting this error when running script/bootstrap ||

$ script/bootstrap
Successfully installed bundler-1.16.5
Parsing documentation for bundler-1.16.5
Done installing documentation for bundler after 3 seconds
1 gem installed
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using RedCloth 4.2.9
Using i18n 0.7.0
Fetching json 1.8.2
Installing json 1.8.2 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/json-1.8.2/ext/json/ext/generator
C:/Ruby25-x64/bin/ruby.exe -r ./siteconf20180923-15396-s6e9th.rb extconf.rb
creating Makefile

current directory:
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/json-1.8.2/ext/json/ext/generator
make "DESTDIR=" clean

current directory:
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/json-1.8.2/ext/json/ext/generator
make "DESTDIR="
generating generator-x64-mingw32.def
compiling generator.c
generator.c: In function 'generate_json':
generator.c:867:25: error: 'rb_cFixnum' undeclared (first use in this function);
did you mean 'mFixnum'?
     } else if (klass == rb_cFixnum) {
                         ^~~~~~~~~~
                         mFixnum
generator.c:867:25: note: each undeclared identifier is reported only once for
each function it appears in
generator.c:869:25: error: 'rb_cBignum' undeclared (first use in this function);
did you mean 'mBignum'?
     } else if (klass == rb_cBignum) {
                         ^~~~~~~~~~
                         mBignum
make: *** [Makefile:242: generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/json-1.8.2 for inspection.
Results logged to
C:/Ruby25-x64/lib/ruby/gems/2.5.0/extensions/x64-mingw32/2.5.0/json-1.8.2/gem_make.out

An error occurred while installing json (1.8.2), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.2' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  github-pages was resolved to 33, which depends on
    jekyll-mentions was resolved to 0.2.1, which depends on
      html-pipeline was resolved to 1.9.0, which depends on
        activesupport was resolved to 4.2.0, which depends on
          json

To fix, I had to bundle update github-pages. Looking through the difs for Gemfile.lock, the dependencies redcarpet and pygments are deleted. So moving to script/server command, I get errors because I'm missing those two dependencies. To fix those errors, I went to the _config.yml and changed it to markdown: kramdown and highlighter: rouge. The command script/server now works and the site is generated. I was curious if you'd like me to submit a PR for these dependency updates.
dependency issue config change

Include method description in page

We have a short description of each method. Shouldn't we put that on the main nodegit docs?

And maybe a link to the libgit2 method that we're wrapping would be helpful for somebody as well.

Guides

I'll start working on the styles and a default template for this. I want to render guides via checked in markdown files. We'll use AJAX to fetch them in and render on the client.

What would be useful are a list of introductory guides new users would like to see upon first using NodeGit.

My list:

  • Installing NodeGit.
  • Creating and opening a repository.
  • Differences between libgit2, C++, and exposed JS properties/methods.
  • Working with NodeGit Promises.

Please add comments with your ideal guides.

Search feature

Having a search feature or a fuzzy finder would be great.

We have a ton of things in our API and that would be a nice way to find things.

docs are wrong about cloneOpts.remoteCallback

referring to http://www.nodegit.org/guides/cloning/gh-two-factor/
The docs tell me that I should use the following options object for cloning with oauth.

cloneOptions.remoteCallbacks = {
  certificateCheck: function() { return 1; },
  credentials: function() {
    return NodeGit.Cred.userpassPlaintextNew(GITHUB_TOKEN, "x-oauth-basic");
  }
};

However that doesn't work and isn't what is in the tests.
I ended up using something like

var cloneOptions = {
    fetchOpts: {
      callbacks: {
        certificateCheck: function() { return 1; },
        credentials: function() {
          console.log(token);
          return nodegit.Cred.userpassPlaintextNew(token, 'x-oauth-basic');
        }
      }
    }
  };

Tree#walk example is missing start() call

I'd make a pull request but it's unclear which parts of this repo are automatically generated and which are manually written. Happy to do so with some guidance. Also, the blobOnly parameter is mis-documented:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.