GithubHelp home page GithubHelp logo

thisconnect / nodegit-kit Goto Github PK

View Code? Open in Web Editor NEW
61.0 4.0 13.0 882 KB

Complementary NodeGit helpers returning native Promises, helps with git commands such as init, add, commit, status, diff

License: MIT License

JavaScript 94.76% Shell 5.24%
nodegit diff log commit status

nodegit-kit's Introduction

NodeGit-Kit

Build Status Build Status Coverage Status MIT NPM Version

Promises for git commands such as git init, git status, git add *, git diff, git log and git commit -am"commit message".

Comments are welcome at nodegit-kit/issues

Install

npm i --save nodegit-kit

Usage

var git = require('nodegit-kit');

git.open('../repo-path/new/or/existing')
.then(repo => {

     // git diff
    return git.diff(repo)
    .then(diff => {
        console.log(diff);

        // git commit -am"commit message"
        return git.commit(repo, {
            'message': 'commit message'
        });
    })
    .then(() => {
        // git log
        return git.log(repo);
    })
    .then(log => {
        console.log(log);
    });
})
.catch(error => {
    console.error(error);
});

API

open (path[, options])

Returns repository, if no repo is found, tries to create the directory and initializes the repository. Initializing is using init internally.

  • path String
  • options Object
    • init Boolean whether to create a first commit, defaults to true
git.open('../repo-path/new/or/existing', {
    'init': false
})
.then(repo => {
    // NodeGit repository instance
})
.catch(err => {
    // no repo here
});

commit (repo[, options])

Checks if status has pending changes, commits, returns Oid else returns null.

  • repo NodeGit repository instance
  • options
    • message String defaults to 'update'
git.open('../repo-path/new/or/existing')
.then(repo => {
    // git commit -am"a new commit"
    return git.commit(repo, {
        'message': 'a new commit'
    })
    .then(oid => {
        console.log(oid);
    });
});

status (repo)

Returns an Array of changed files and their status.

  • repo NodeGit repository instance
git.open('../repo-path/new/or/existing')
.then(repo => {
    // git status
    return git.status(repo)
    .then(status => {
        console.log(status);
    });
});

log (repo[, options])

Returns an Array of all commits.

  • repo NodeGit repository instance
  • options
    • branch String name of a branch, defaults to 'master'
    • sort String can be 'none', 'topological', 'time' or 'reverse'
    • abbrev-commit Boolean if true shortens checksum, defaults to false
    • abbrev Number to specify a custom number of digits in combination with abbrev-commit, otherwise uses 'core.abbrev' config
    • max-count Max number of commits to traverse
git.open('../repo-path/new/or/existing')
.then(repo => {
    // git log
    return git.log(repo)
    .then(log => {
        console.log(log);
    });
});

diff (repo[, commit[, commit]][, options])

Returns an Array of modified files and their diffs.

  • repo NodeGit repository instance
  • options
    • name-only Boolean return only filenames, defaults to false
git.open('../repo-path/new/or/existing')
.then(repo => {
    // git diff
    return git.diff(repo, { 'name-only': true })
    .then(filenames => {
        console.log(filenames);
    });
});

Get a diff of a commit

git.open('../repo-path/new/or/existing')
.then(repo => {
    return git.log(repo)
    .then(history => {
        return history[0].commit;
    })
    .then(commit => {
        // git diff <commit>
        return git.diff(repo, commit);
    })
    .then(diff => {
        console.log(diff);
    });
});

Get a diff between 2 commits

Breaking API change in 0.12.0 Changed order of from and to to be aligned with git-cli.

git.open('../repo-path/new/or/existing')
.then(repo => {
    return git.log(repo, { sort: 'reverse' })
    .then(history => {
        var commit1 = history[0].commit;
        var commit2 = history[2].commit;
        // git diff <from> <to>
        return git.diff(repo, commit1, commit2);
    })
    .then(diff => {
        console.log(diff);
    });
});

config

Allows to write/read global and local git config values. Local values are stored in the Git directory ./git/config and overrule global configurations. Note: Git locks the config when changing configurations, therefore writing multiple configs can not be done in parallel. e.g. Promise.all multiple individual git.config.set calls will throw a "Failed to lock file for writing" error, nodegit/issues/757.

See also 8.1 Customizing Git - Git Configuration (Git SCM Documentation)

config.set (repo, options)

Example setting user.name and user.email for a specific repository

Set user name and email similar to cd repo then git config user.name "John Doe" and git config user.email [email protected].

git.open('my/repository')
.then(repo => {
    return git.config.set(repo, {
        'user.name': 'John Doe',
        'user.email': '[email protected]'
    });
});

config.get (repo, options)

Example reading user.name and user.email

Similar to cd repo thengit config user.name returns config for a repository if there any or else the global Git configuration.

git.open('my/repository')
.then(repo => {
    return git.config.get(repo, ['user.name', 'user.email']);
})
.then(configs => {
    // [ 'John Doe', '[email protected]' ]
});

global git configuration

config.get (options)

When no repo is given, setting and getting config will operate in --global mode and read and write to ~/.gitconfig (or ~/.config/git/config).

git.config.get(['user.name', 'user.email'])
.then(config => {
    // [ 'John Doe', '[email protected]' ]
});

config.set (options)

// WARNING: this will change your global git config
git.config.set({
    'user.name': 'John Doe',
    'user.email': '[email protected]'
});

init (path[, options])

Ensures directory exists, initializes, creates a first commit and returns repo. This is optional and only useful to control the first commit.

  • path String
  • options Object
    • bare Number defaults to 0
    • commit Boolean defaults to true
    • message String defaults to 'initial commit'
git.init('../repo-path/new/or/existing', {
    'bare': 0,
    'commit': true,
    'message': 'my first commit'
})
.then(repo => {
    // NodeGit repository instance
});

init.commit (repo[, options])

Can be used to in combination with suppressing commit on init.

  • repo NodeGit Repository instance
  • options
    • message String defaults to 'initial commit'
git.open('../path/to/repo', {
    'init': false
})
.catch(err => {
    return git.init('../path/to/repo', {
        'commit': false
    })
    .then(repo => {
        // do something before first commit
        return repo;
    })
    .then(repo => {
        git.init.commit(repo, {
            'message': 'initialize repository'
        });
    });
})
.then(repo => {
    // NodeGit repository instance
});

Test

npm install

npm test

# debug nodegit-kit
DEBUG=kit* npm test

# debug all
DEBUG=* npm test

nodegit-kit's People

Contributors

adamstone avatar dependabot-preview[bot] avatar dependabot[bot] avatar greenkeeper[bot] avatar jeznag avatar robertdudaa avatar snyk-bot avatar thisconnect avatar z-hao-wang avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

nodegit-kit's Issues

An in-range update of debug is breaking the build 🚨

Version 2.6.3 of debug just got published.

Branch Build failing 🚨
Dependency debug
Current Version 2.6.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As debug is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ coverage/coveralls Coverage pending from Coveralls.io Details

  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 3 commits .

  • 9dc30f8 release 2.6.3
  • 0fb8ea4 LocalStorage returns undefined for any key not present (#431)
  • ce4d93e changelog fix

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

NodeGit on travis Error: Cannot find module '../build/Debug/nodegit.node'

travis build Error: Cannot find module '../build/Debug/nodegit.node'

module.js:327
    throw err;
    ^
Error: Cannot find module '../build/Debug/nodegit.node'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/travis/build/thisconnect/nodegit-kit/node_modules/nodegit/dist/nodegit.js:18:12)
    at Module._compile (module.js:409:26)
    at Module._extensions..js (module.js:416:10)
    at extensions.(anonymous function) (/home/travis/build/thisconnect/nodegit-kit/node_modules/ava/node_modules/require-precompiled/index.js:16:3)
    at Object.require.extensions.(anonymous function) [as .js] (/home/travis/build/thisconnect/nodegit-kit/node_modules/ava/lib/test-worker.js:89:3)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/travis/build/thisconnect/nodegit-kit/lib/config.js:3:11)
    at Module._compile (module.js:409:26)
    at Module._extensions..js (module.js:416:10)

does it support authentication?

Does it support following? I don't see anywhere in the code that supports multiple user authentications. If not are you planning to do one? We can create a PR if you could guide us.

{
    // SSH:
    'passphrase': "...",
    'refuseUnknownHost': true, // Default is false

    // HTTPS:
    'username': "...",
    'password': "..."
}

Loop through array of elements and their promises

How can I handle an array of commits that each have their own .then() handler, and possibly loop each of the child elements with again their own then() handlers?
I tried with recursive functions but my problem is multiple nested loops like displaying all commits in a repo then all the diffs in each commit.

An in-range update of coveralls is breaking the build 🚨

Version 2.12.0 of coveralls just got published.

Branch Build failing 🚨
Dependency coveralls
Current Version 2.11.16
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As coveralls is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • βœ… coverage/coveralls First build on greenkeeper/coveralls-2.12.0 at 87.887% Details

  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

Release Notes Branch coverage support

Adds branch coverage data to Coveralls API post.

Commits

The new version differs by 2 commits .

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of codecov is breaking the build 🚨

Version 2.3.1 of codecov was just published.

Branch Build failing 🚨
Dependency codecov
Current Version 2.3.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

codecov is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… continuous-integration/appveyor/branch AppVeyor build succeeded Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 3 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of debug is breaking the build 🚨

The dependency debug was updated from 4.1.0 to 4.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

debug is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • ❌ ci/circleci: node-10: Your tests failed on CircleCI (Details).
  • ❌ ci/circleci: node-8: Your tests failed on CircleCI (Details).
  • ❌ continuous-integration/travis-ci/push: The Travis CI build is in progress (Details).
  • βœ… continuous-integration/appveyor/branch: AppVeyor build succeeded (Details).

Commits

The new version differs by 4 commits.

  • 68b4dc8 4.1.1
  • 7571608 remove .coveralls.yaml
  • 57ef085 copy custom logger to namespace extension (fixes #646)
  • d0e498f test: only run coveralls on travis

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

nodegit 0.5.0 on travis fails on Node 4.x

Note: Node.js 5.0.0 is fine

Related:

https://travis-ci.org/thisconnect/nodegit-kit/builds/89676720

> [email protected] test /home/travis/build/thisconnect/nodegit-kit
> tape ./test/test.js | tap-spec
/home/travis/build/thisconnect/nodegit-kit/node_modules/nodegit/lib/nodegit.js:13
    throw ex;
    ^
Error: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.17' not found (required by /home/travis/build/thisconnect/nodegit-kit/node_modules/nodegit/build/Release/nodegit.node)
    at Error (native)
    at Object.Module._extensions..node (module.js:460:18)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:311:12)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (/home/travis/build/thisconnect/nodegit-kit/node_modules/nodegit/lib/nodegit.js:8:12)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
  βœ– No tests found
npm ERR! Test failed.  See above for more details.
The command "npm test" exited with 1.
Done. Your build exited with 1.

An in-range update of nyc is breaking the build 🚨

The devDependency nyc was updated from 13.2.0 to 13.3.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

nyc is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • βœ… ci/circleci: node-10: Your tests passed on CircleCI! (Details).
  • βœ… ci/circleci: node-8: Your tests passed on CircleCI! (Details).
  • ❌ continuous-integration/appveyor/branch: AppVeyor build failed (Details).
  • βœ… continuous-integration/travis-ci/push: The Travis CI build passed (Details).

Commits

The new version differs by 4 commits.

  • 747a6c1 chore(release): 13.3.0
  • e8cc59b fix: update dependendencies due to vulnerabilities (#992)
  • 8a5e222 chore: Modernize lib/instrumenters. (#985)
  • dd48410 feat: Support nyc report --check-coverage (#984)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of debug is breaking the build 🚨

Version 2.6.4 of debug just got published.

Branch Build failing 🚨
Dependency debug
Current Version 2.6.3
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

As debug is a direct dependency of this project this is very likely breaking your project right now. If other packages depend on you it’s very likely also breaking them.
I recommend you give this issue a very high priority. I’m sure you can resolve this πŸ’ͺ


Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details

  • βœ… coverage/coveralls First build on greenkeeper/debug-2.6.4 at 94.298% Details

Commits

The new version differs by 6 commits .

  • f311b10 release 2.6.4
  • 1f01b70 Fix bug that would occure if process.env.DEBUG is a non-string value. (#444)
  • 2f3ebf4 Update CHANGELOG.md
  • f5ae332 Update CHANGELOG.md
  • 9742c5f chore(): ignore bower.json in npm installations. (#437)
  • 27d93a3 update "debug" to v0.7.3

See the full diff.

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected πŸ€–


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

merge question.

I have a merge question.
e.g.

remote/master modify A.txt
master modify A.txt

merge.merge('master','remote/master')

A.txt is a conflict file.

I want to auto merge,and use the lastest file.

so how to do ?

thanks!

An in-range update of nyc is breaking the build 🚨

Version 10.3.0 of nyc just got published.

Branch Build failing 🚨
Dependency nyc
Current Version 10.2.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As nyc is β€œonly” a devDependency of this project it might not break production or downstream projects, but β€œonly” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this πŸ’ͺ

Status Details - βœ… **coverage/coveralls** First build on greenkeeper/nyc-10.3.0 at 94.298% [Details](https://coveralls.io/builds/11301071),- ❌ **continuous-integration/travis-ci/push** The Travis CI build failed [Details](https://travis-ci.org/thisconnect/nodegit-kit/builds/227079378?utm_source=github_status&utm_medium=notification)

Commits

The new version differs by 4 commits ahead by 4, behind by 2.

  • 55e826d chore(release): 10.3.0
  • 89dc7a6 chore: explicit update of istanbul dependnecies (#562)
  • 1887d1c feat: add support for --no-clean, to disable deleting raw coverage output (#558)
  • ff73b18 fix: source-maps were not being cached in the parent process when --all was being used (#556)

false

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

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.