Giter Site home page Giter Site logo

git-js's People

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  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  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

git-js's Issues

simpleGit.pull doesn't detect changes if all changes are deletions

When using git-js to do a pull, it fails to detect if there were changes that were only deletions. If there were no insertions, the "update" parameter returns a response saying that nothing has changed, when in fact I did delete a single line:

{"files":[],"insertions":{},"deletions":{},"summary":{"changes":0,"insertions":0,"deletions":0}}

It appears this is due to this line in git.js: _parsePull:

    var fileUpdateRegex = /^\s*(.+)\s\|\s(\d+)\s([\+]+)/;

The line to capture looks like this:

     src/TestComponent/TestComponent.scss | 1 -

The regular expression will capture if a minus sign is added:

      var fileUpdateRegex = /^\s*(.+)\s\|\s(\d+)\s([\+\-]+)/;

Here is how we are using git-js and then check the results:

 simpleGit.pull('origin', 'staging', function doPull(err, update) {
    try {
      console.log(JSON.stringify(update));
      if (update
        && (Object.keys(update.insertions).length > 0
          || Object.keys(update.deletions).length > 0)) {
      ...

Git checkout hash

I'm trying to checkout a hash tag referencing a commit. Is this functionality included?

Neither of the following APIs seem to work with hash values.

repo.checkout(hash, function(error, data) { ... });

repo.checkoutLocal(hash, function(error, data) { ... });

Support for Promises?

Given that there is a .then method, it seems to imply that a Promise is returned, but that's not actually the case. So if you want a Promise, you have to crudely wrap it:

let promise = new Promise(resolve => {
  simpleGit(dir)
    .add('./*')
    .commit('New')
    .push('origin', 'master')
    .then(resolve);
});

So could support be added for Promises? One big benefit is that consumers could then use .catch for errors.

reset with commitId

can you Give the interface reset a commit id parameter it like: git reset commitId

simple-git in windows machine

I'm trying to use npm simple-git in windows machine. But when I run it with node.js it shows me the following error message.

events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn git ENOENT

Node version: v0.12.2
npm version: 2.7.4

Support git log --merges

Hi Guys,

This is a nice lib, thanks for your work. I ran in to an issue whereby I wanted to look at just merge changes between branches.

I'm going to push a PR for this shortly (it's really simple) - would love some feedback.

Steps to test:

In your config object, set the following:

config.merges: true,
config.branch: qa

Error: spawn git ENOENT

When I create a bare repository prompted the following errors:
Error: spawn git ENOENT
     at exports._errnoException (util.js: 860: 11)
     at Process.ChildProcess._handle.onexit (internal / child_process.js: 178: 32)
     at onErrorNT (internal / child_process.js: 344: 16)
     at doNTCallback2 (node.js: 450: 9)
     at process._tickCallback (node.js: 364: 17)
     at Function.Module.runMain (module.js: 459: 11)
     at startup (node.js: 136: 18)
     at node.js: 972: 3

code:

var simpleGit = require('simple-git');

var bareDir = 'test.git';

simpleGit(bareDir).init(true, function() {
console.log("init bare done");
});

repo.rm([array], cb...) cannot handle multiple files

Tested on git version 2.7.4 and 1.8.3.1
Simple-git version 1.38.0

var repo = require('simple-git')('.');
repo.status(function(err, data) {
  // data.deleted is [ 'asdf', 'qwer' ]
});

repo.rm(['asdf', 'qwer'], function(err) {
  // err is: fatal: pathspec 'asdf,qwer' did not match any files
});

Can I provide a user and password ?

Hi,
I am looking for a project like yours.
I would like to clone and pull a private git repository.
Can I provide a user/password with your api ?

then() causes TypeError in node v0.10.29 and later

When you use a then() block, you'll get this error with node 0.10.29 and later:

TypeError: Incorrect value of args option
    at Object.exports.spawn (child_process.js:725:11)
    at Git._schedule (/home/airspring/scratch/node_modules/simple-git/src/git.js:651:40)
    at process._tickCallback (node.js:442:13)

Platform: OSX
simple-git: 1.3.0

It works in:

0.10.26
0.10.27
0.10.28

It fails in:

0.10.29
0.10.30
0.10.31
0.10.33
0.10.38

I also tested on Linux, and it failed there too with node 0.10.26.
I did not not test node 0.12.x

I'm suspicious of my report since it means this problem has been undetected since node 0.10.29 was released about a year ago: http://blog.nodejs.org/2014/06/16/node-v0-10-29-stable/ But it's easy to reproduce:

if (process.argv.length < 3) {
    console.log('need a path to a git repo');
    process.exit(-1);
}

var path_to_repo = process.argv[2];
console.log('running git status for ' + path_to_repo);

require('simple-git')(path_to_repo)
     .status(function(err, status) {
     })
     .then(function() {
        console.log('status done.');
     });

Expected behavior: 'status done' prints out without any errors
Actual behavior: message is not printed. The error noted above is seen.

How to handle credentials?

Is there any way to have different credentials? can you set what credentials to use for a git call? For example, repository 1 uses my personal credentials while repository 2 uses my work credentials. Is this possible?

using simple-git before running 'git config'

After rebuilding my webserver, I accidentally did not run git config --global user.email "[email protected]" or git config --global user.name "Your Name". This oversight seemed to cause git.commit() to 'hang'. Here is the general idea:

git('/path/to/repo')
  .add('./*')
  .commit('commit message', function(e, data) {
    console.log(e); //null
    console.log(data); //false
  })
  .revparse(['HEAD'], function(e, data) {
    //not reached
  });

Inside the commit() callback, e is set to null and data is set to false. Additionally, the revparse() callback is not executed.

Is this the intended/expected behavior? If you use git commit from the command line before running either of the config steps, you will see a message that looks something like this:

19:00:28: *** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

Do you think this message should be interpreted as an error? In any case, should git.commit() and related methods provide some sort of indication that the global git config has not been set?

Just thought I'd get your opinion on this before I looked at how to do it.

Change working directory

Is there any possible way, outside of require to change between multiple working directories?

I am working in a project that could have multiple git repositories and I need to switch between these folders and branch/commit/push each of them on specific route calls.

Error when nothing to commit

"TypeError: Cannot read property '1' of null"
This error appear when I try to commit but there is nothing to commit

submodule init

I'm not sure if I just completely missed something but I can't find a implementation of submodule init

code execution vulnerability

This module should not be used with any user input as it is very easy to inject code:

~/src/git-js(master ✗) node -e "require('./src/git.js')('.').add('\";echo HELLO WORLD > foo\"')"
~/src/git-js(master ✗) cat foo 
HELLO WORLD
~/src/git-js(master ✗) 

Verbose output

Adding an option (or defaulting) to verbose output would be amazing. When cloning large repo's, the script appears to hang.

EG, when cloning, would be amazing to see the native Git output while the clone was in progress.

I'm not a Node expert, though, so let me know if that's an easy change for me to make myself on my machine.

Checkout local branch

Is there a way I can checkout a local branch? I just want to run git checkout -b develop but it looks like I can't use checkout() or checkoutBranch(). Am I missing something or is this a feature that does not exist?

Would that be something you could possibly add?

Thanks!

merge command

Thank you for the easy to use library.

I may have missed it, but the current API doesn't seem to support git merge, so to merge branches I am doing this:

simpleGit._run(['merge', 'master', 'branch1'], function(err, data) { ... });

Support for merge would be greatly appreciated.

Diff with another branch

Hi, I'm trying to get a diff from another branch and I'm not sure if this is the correct way:

simpleGit.diff(['HEAD remotes/origin/branch_name --name-only'], function (err, diff)...

This is the error I get:

fatal: ambiguous argument 'HEAD remotes/origin/bugfixing_v1 --name-only': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git [...] -- [...]'

Works fine when running from the command line.
Is it the right way to do it or maybe a bug?

Thank you.

Authentication

Is it possible to pass in authorization (such as a GitHub token) on methods such as .clone() for private repos, instead of my current method of adding a username and password in to the remote?

Managing remotes

None of the git remote methods are supported - requires support for git remote add and git remote remove

Pushing to remote

git push not currently supported, pushing to default and to named remote and branch should both be possible.

Expand implemented commands

Hey @steveukx, looks like a good package here. I have a project that uses a much more janky implementation. I would like to switch over to this package, but I need a few more features. If it is good with you, I will fork and upstream the features.

The commands I need are:

  • git init
  • git submodule [add, init, update]
  • git ls-remote --tags

Do you have contributor guidelines? Does this all sound good?

Make startPoint optinal for checkoutBranch

Hi thanks for working on this library.

What do you guys think about making startPoint optional so that I can do:

  simpleGit(root).checkoutBranch('my_new_branch')

that results in:

git checkout -b my_new_branch

If you guys agree with this change I can send a PR.

Typo in Fetch

If i try to use the fetch() method I get this error:

C:\Users\dlowerre\full_throttle\node_modules\simple-git\src\git.js:171
then && then(err, !err && this._parsePush(data));
^
TypeError: Object # has no method '_parsePush'

There is indeed no function '_parsePush' defined for the Git object. Perhaps this should be a call to _parsePull?

It turns out I needed to do a 'pull' instead of a 'fetch' so I am not stuck on this problem, but I thought I would let you know about it.

Empty tags in tag list

Using 1.37 on OS X with git 2.8.4 and node 4.4.4.

My repository looks like this:

$ git tag -l
2016_06_08_NEW
2016_06_08_NEW2
2016_06_08_NEW23

repo.tags() results in

[
    "2016_06_08_NEW",
    "2016_06_08_NEW2",
    "2016_06_08_NEW23",
    ""
]

So an array of 3 tags and an additional empty tag.
I fixed it for now by adding
.filter(function(item){return item !== "";})
Any idea if this a bug in my repo, in my code or in git-js? If anyone can reproduce it, I'd be happy to do a PR.
I assume it's because git adds a final \n to wrap the last line and .split("\n") returns the empty line, too.

Document init command

Whilst this command is featured in one of the examples it is not given as a command in the list of possible commands

log gives quoted output

    gitRepo
        .log(function(err, log) {
            console.log(log);
        });

Gives me hashes with prepended ' and author_email's with appended '. And also the stdoutput is quoted with '

Branch command does not work with detached current branch

After checking out a branch which is detached, git branch command reports something akin to the following:

* (detached from First-tag) 573b9ed for todd
  develop                   1f5dd41 [behind 5] FirstNewFile.txt edited online with Bitbucket
  feature/My-new-feature    1f5dd41 FirstNewFile.txt edited online with Bitbucket
  master                    1be9589 add to master

Note the format of the first line. This causes a problem in regular expression in branchSummary.js:

BranchSummary.parse = function (commit) {
   var branchSummary = new BranchSummary();

   commit.split('\n')
      .forEach(function (line) {
            var branch = /^(\*?\s+)(\S+)\s+([a-z0-9]+)\s(.*)$/.exec(line);
         if (branch) {
            branchSummary.push(
               branch[1].charAt(0) === '*',
               branch[2],
               branch[3],
               branch[4]
            );
         }
      });

   return branchSummary;
};

My local fix looks like this:

BranchSummary.parse = function (commit) {
   var branchSummary = new BranchSummary();

   commit.split('\n')
      .forEach(function (line) {
         if (line.charAt(2) === '(') var branch = /^(\*?\s+)\(([^)]+)\)\s+([a-z0-9]+)\s(.*)$/.exec(line)
            else var branch = /^(\*?\s+)(\S+)\s+([a-z0-9]+)\s(.*)$/.exec(line);
         if (branch) {
            branchSummary.push(
               branch[1].charAt(0) === '*',
               branch[2],
               branch[3],
               branch[4]
            );
         }
      });

   return branchSummary;
};

There may be better other ways to deal with this but hopefully this helps.
Todd

Add custom git log separator

Thank you for this easy to use library! A colleague of mine have been writing commits that included semicolons (;). Now I try to make some statistics from git log, and it fails to parse it correctly. Looking at the code, I found that for log, you use

var command = ["log", "--pretty=format:'%H;%ai;%s%d;%aN;%ae'"];

To overcome the mentioned issue, I replaced semicolons to triple-semicolons and all worked well again. (Also needed to replace in this function: Git.prototype._parseListLog.)

Perhaps you could make it more reliable by selecting a more rare character, or adding an optional parameter for the separator. I would loved to see these changes and further use your great library!

Results of git-pull are unreliable

I've gotten summary strings with changes: 100644 (obviously the mode, not the change), file listings with ... in them, and missing additions/deletions.

Due to how Git formats the output of pull (even with -v), it might be worthwhile to manually abridge the results of git diff <before-pull>...HEAD instead of trying to parse the output of pull.

Documentation too vague?

I've been picking through the code, to be sure the functions do what I expect them to do, and surprisingly I'm finding that the descriptions are somewhat misleading, particularly when they involve a number of parameters (mergeFromTo, pull, etc), as the git commands being used use the parameters in a different way to what's described in the documentation.

For example, mergeFromTo seems to indicate that it merges from into to (or vice versa?), but the git documentation indicates that it merges both into the current branch. Additionally, pull indicates that it pulls a remote branch, which I'd assumed would pull the remote branch to the tracking branch, but actually, if you're not on the tracking branch, pull acts like a merge. It wouldn't surprise me if someone used this expecting some background checking out or something to merge the two specified branches.

At the very least, it might be worth linking to the relevant git docs for each function for transparency regarding both the function parameters and any option flags.

add force flag to checkout

The title says it all :).
I need to force a checkout and dont see a way to do this until now.

Would it be possible to add a force flag (or a forceCheckout-method) to do that?

Push allows -u flag

Would it be possible to add an option, allowing us to set the -u flag of the push command? I do

  var Git = require('simple-git')(localPath);
  Git.init()
        .add('./*')
        .commit("first commit!")
        .addRemote('origin', 'some-repo-url')
        .push('origin', 'master')
        .then(fn);

and then i get the old and famous

 There is no tracking information for the current branch.
 Please specify which branch you want to merge with.
 See git-pull(1) for details

    git pull <remote> <branch>

 If you wish to set tracking information for this branch you can do so with:

   git branch --set-upstream-to=origin/<branch> master

Maybe there is another way of doing that and is currently available?

Regards, Dani

Request: Add option for silent errors

Great module, we're using it with great success.

I'd like to request a small feature addition - the ability to silence the error output to console. We're using this in an environment where we're curating our console output very carefully to deliver a clean experience for our build tools. We're already catching the errors that are thrown should there be an error in the git child process, so we don't need the extraneous console output.

This line here is the culprit: https://github.com/steveukx/git-js/blob/master/src/git.js#L627

Cheers

Missing chain in getRemotes

/node_modules/simple-git/src/git.js:483
         next(err, !err && function () {
         ^
TypeError: next is not a function

Trying to execute simpleGit.getRemotes(true).then();

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.