npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fab1o/git

v1.4.0

Published

A wrapper for command line git with promises

Downloads

4

Readme

@fab1o/git

A wrapper for command line git with promises

npm install @fab1o/git

How to use it

This is a wrapper for command line Git so, you must have git installed in your linux / mac machine (it has not been tested in windows yet).

  • Common sintax is:
var { Git, GitSync } = require('@fab1o/git');

var git = new Git('/tmp/gitTemp');
var gitSync = new GitSync('/tmp/gitTemp');

//You can also create it only with Git() and set the working path later
git.[git command]([string parameters], [options])
   .then(function(res){
     // Then
   }).
   fail(function(err){
     // Fail
   });

// or calling it synchronously 
try {
   const res = gitSync.[git command]([string parameters], [options]);
}
catch(err) {
  // Fail
}

=======

Some examples

  • To Git init /tmp/git folder, add all files on it, commit, add a new remote and push master to it
var { Git } = require('@fab1o/git');

//Variables
var gitFolder = '/tmp/gitTemp';
var remoteName = 'origin';
var remoteUrl = 'https://example.remote.repo';

//Create a new Git object
var git = new Git(gitFolder);

//Execute the chain
git
  .init()

  .then(function (res) {
    return git.add("*", { cwd: "/tmp/git" });
  })
  .then(function (res) {
    return git.commit('-m "My commit"');
  })
  .then(function (res) {
    return git.remote("add " + remoteName + " " + remoteUrl);
  })
  .then(function (res) {
    return git.push("-u " + remoteName + " master");
  })
  .then(function (res) {
    console.log("Success: ", res);
  })
  .fail(function (err) {
    console.error(err);
  });
  • To commit staged files with message "My commit" on the last working folder if any or current one
git.commit('-m "My commit"')
  .then(function(msg){
    console.log(msg)
}).fail(function(err){
    console.log(err);
});

=======

API

Initially, following commands are available:

  • add Add file contents to the index
  • bisect Find by binary search the change that introduced a bug
  • branch List, create, or delete branches
  • checkout Checkout a branch or paths to the working tree
  • clone Clone a repository into a new directory
  • commit Record changes to the repository
  • diff Show changes between commits, commit and working tree, etc
  • direct Allows the direct execution of a git command that is not available in the API yet
  • fetch Download objects and refs from another repository
  • grep Print lines matching a pattern
  • init Create an empty git repository or reinitialize an existing one
  • log Show commit logs
  • merge Join two or more development histories together
  • mv Move or rename a file, a directory, or a symlink
  • pull Fetch from and integrate with another repository or a local branch
  • pullRequest Creates a Pull Request
  • push Update remote refs along with associated objects
  • rebase Forward-port local commits to the updated upstream head
  • remote Manage set of tracked repositories
  • reset Reset current HEAD to the specified state
  • rm Remove files from the working tree and from the index
  • show Show various types of objects
  • status Show the working tree status
  • tag Create, list, delete or verify a tag object signed with GPG

Options parameter is to tweak the 'exec' command as described in: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback

There is a special situation. Once you stablish cwd in the options param, it will be maintained through the rest of the commands

Direct

git.direct(command,options);

Git direct allows the direct execution of a git command that is not available in the API yet

  • Examples
    var myGitRepo = '/tmp/gitTemp';     //This is where the command will be executed
    var git = new Git(myGitRepo);
    
    git.direct('init')
      .then(function(res){      //Equivalent to 'git init'
        git.direct('add *');                      //Equivalent to 'git add *'
    }).then(function(err){
        console.error(err)
    });

Add

git.add(command, options)

Same as 'git add [command]'

  • To add all files in /tmp/git and the commit them
git.add('*', {cwd:'/tmp/git'}).then(function(msg){
    return git.commit('-m "My commit"');
}).then(function(res){
    console.log(res);
}.fail(function(err){
    console.error(err);
});

Bisect

git.bisect(command, options);

Same as 'git bisect [command]'

Branch

git.branch(command, options);

Same as 'git branch [command]'

  • To get current branch
    git.branch().then(function(res){
        console.log(res)            // master
    }).catch(function(err){
        console.log(err();
    });

Checkout

git.checkout(command, options);

Same as 'git checkout [command]'

  • To change to branch test
    git.checkout('test').then(function(res){
        console.log(res);
    }).catch(function(err){
        console.error(err);
    });

Clone

git.clone(command, options);

Same as 'git clone [command]'

  • To clone a git repo on current folder
    git.clone('https://github.com/sayden/git-command-line.git').then(function(res){
        console.log(res);
    }).catch(function(err){
        console.error(err);
    });
  • To clone a git repo on /tmp
    git.clone('https://github.com/sayden/git-command-line.git /tmp').then(function(res){
        console.log(res);
    }).catch(function(err){
        console.error(err);
    });

Commit

git.commit(command, options);

Same as 'git commit [command]'

  • Examples
    var myGitRepo = '/tmp/gitTemp';     //This is where the command will be executed
    var git = new Git(myGitRepo);
    
    git.commit('-m "My commit"', {cwd:myGitRepo})       //Equivalent to 'git commit -m "My commit"'
      .then(function(msg){
        console.log(msg)
      }).fail(function(err){
        console.log(err);
      });

Diff

git.diff(command, options);

Same as 'git diff [command]'

Fetch

git.fetch(command, options);

Same as 'git fetch [command]'

Grep

git.grep(command, options);

Same as 'git grep [command]'

Init

git.init(command, options);

Same as 'git init [command]'

Log

git.log(command, options);

Same as 'git log [command]'

Merge

git.merge(command, options);

Same as 'git merge [command]'

MV

git.mv(command, options);

Same as 'git mv [command]'

Pull

git.pull(command, options);

Same as 'git pull [command]'

Push

git.push(command, options);

Same as 'git push [command]'

Rebase

git.rebase(command, options);

Same as 'git rebase [command]'

Remote

git.remote(command, options);

Same as 'git remote [command]'

Reset

git.reset(command, options);

Same as 'git reset [command]'

RM

git.rm(command, options);

Same as 'git rm [command]'

Show

git.show(command, options);

Same as 'git show [command]' or simple 'git show' if no param specified

Status

git.status(command, options);

Same as 'git status [command]' or simply 'git status' if no param specified

  • Examples
    git.status()
    .then(function(res){
      console.log(res);
    }).fail(function(err){
      console.log(err);
    });

    //Or...

    git.status('-h')
    .then(function(res){
      console.log(res);
    }).fail(function(err){
      console.log(err);
    });

Tag

git.tag(command, options);

Same as 'git tag [command]'

  • Examples
git.tag('0.1.0').then(function(res){
    console.log(res);

git.cwd = newPath

Sets the working path for the following git commands

git.logging = boolean

Sets the logging of the git command line responses