{"_id":"git-promise","_rev":"244834","name":"git-promise","description":"Simple wrapper to run any git command and process it's output using promises.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"piuccio","email":"piuccio@gmail.com"}],"time":{"modified":"2023-03-27T06:45:52.000Z","created":"2014-04-26T09:31:43.068Z","1.0.0":"2020-02-29T02:44:23.246Z","0.3.1":"2016-12-28T09:51:56.490Z","0.3.0":"2016-01-20T09:45:43.019Z","0.2.0":"2014-06-25T00:48:33.125Z","0.1.0":"2014-04-26T09:31:43.068Z"},"users":{},"author":{"name":"Fabio Crisci","email":"piuccio@gmail.com"},"repository":{"type":"git","url":"git://github.com/piuccio/git-promise.git"},"versions":{"1.0.0":{"name":"git-promise","description":"Simple wrapper to run any git command and process it's output using promises.","version":"1.0.0","homepage":"https://github.com/piuccio/git-promise","author":{"name":"Fabio Crisci","email":"piuccio@gmail.com"},"repository":{"type":"git","url":"git://github.com/piuccio/git-promise.git"},"bugs":{"url":"https://github.com/piuccio/git-promise/issues"},"licenses":[{"type":"MIT","url":"https://github.com/piuccio/git-promise/blob/master/LICENSE"}],"main":"./index.js","engines":{"node":">=10.0"},"scripts":{"test":"node test","lint":"eslint test '*.js'","posttest":"npm run lint","cover":"istanbul cover node_modules/nodeunit/bin/nodeunit -- test"},"keywords":["git","shell"],"devDependencies":{"baretest":"1.0.0","eslint":"6.8.0"},"gitHead":"7f40e328bc73af83bd55aa58a0410022f64c348d","_id":"git-promise@1.0.0","_nodeVersion":"10.16.0","_npmVersion":"6.9.0","dist":{"shasum":"6337fa79b72f9a2370863d43059a6259e01922eb","size":4896,"noattachment":false,"key":"/git-promise/-/git-promise-1.0.0.tgz","tarball":"http://name.csiicloud.com:7001/git-promise/download/git-promise-1.0.0.tgz"},"maintainers":[{"name":"piuccio","email":"piuccio@gmail.com"}],"_npmUser":{"name":"piuccio","email":"piuccio@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/git-promise_1.0.0_1582944263126_0.369957215711862"},"_hasShrinkwrap":false,"publish_time":1582944263246,"_cnpm_publish_time":1582944263246,"_cnpmcore_publish_time":"2021-12-17T00:17:14.050Z"},"0.3.1":{"name":"git-promise","description":"Simple wrapper to run any git command and process it's output using promises.","version":"0.3.1","homepage":"https://github.com/piuccio/git-promise","author":{"name":"Fabio Crisci","email":"piuccio@gmail.com"},"repository":{"type":"git","url":"git://github.com/piuccio/git-promise.git"},"bugs":{"url":"https://github.com/piuccio/git-promise/issues"},"licenses":[{"type":"MIT","url":"https://github.com/piuccio/git-promise/blob/master/LICENSE"}],"main":"./index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"nodeunit test","cover":"istanbul cover node_modules/nodeunit/bin/nodeunit -- test"},"keywords":["git","shell"],"dependencies":{"q":"~1.4.1","shelljs":"~0.5.3"},"devDependencies":{"nodeunit":"~0.9.1"},"gitHead":"8e5869ac40718fa5043ecfbee74ab1c471a81e5e","_id":"git-promise@0.3.1","_shasum":"0c6dbd16acbb35ecaf407311bb790f923f62891f","_from":".","_npmVersion":"3.10.8","_nodeVersion":"6.9.1","_npmUser":{"name":"piuccio","email":"piuccio@gmail.com"},"dist":{"shasum":"0c6dbd16acbb35ecaf407311bb790f923f62891f","size":4698,"noattachment":false,"key":"/git-promise/-/git-promise-0.3.1.tgz","tarball":"http://name.csiicloud.com:7001/git-promise/download/git-promise-0.3.1.tgz"},"maintainers":[{"name":"piuccio","email":"piuccio@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/git-promise-0.3.1.tgz_1482918714444_0.3428482855670154"},"directories":{},"publish_time":1482918716490,"_hasShrinkwrap":false,"_cnpm_publish_time":1482918716490,"_cnpmcore_publish_time":"2021-12-17T00:17:14.404Z"},"0.3.0":{"name":"git-promise","description":"Simple wrapper to run any git command and process it's output using promises.","version":"0.3.0","homepage":"https://github.com/piuccio/git-promise","author":{"name":"Fabio Crisci","email":"piuccio@gmail.com"},"repository":{"type":"git","url":"git://github.com/piuccio/git-promise.git"},"bugs":{"url":"https://github.com/piuccio/git-promise/issues"},"licenses":[{"type":"MIT","url":"https://github.com/piuccio/git-promise/blob/master/LICENSE"}],"main":"./index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"nodeunit test","cover":"istanbul cover node_modules/nodeunit/bin/nodeunit -- test"},"keywords":["git","shell"],"dependencies":{"q":"~1.4.1","shelljs":"~0.5.3"},"devDependencies":{"nodeunit":"~0.9.1"},"gitHead":"18f7642c4438264ec73a6264cedaa6a08cb31bb0","_id":"git-promise@0.3.0","_shasum":"3b72294e33c4c334146a845fffd7a3ce72967efd","_from":".","_npmVersion":"3.3.12","_nodeVersion":"5.4.0","_npmUser":{"name":"piuccio","email":"piuccio@gmail.com"},"dist":{"shasum":"3b72294e33c4c334146a845fffd7a3ce72967efd","size":4608,"noattachment":false,"key":"/git-promise/-/git-promise-0.3.0.tgz","tarball":"http://name.csiicloud.com:7001/git-promise/download/git-promise-0.3.0.tgz"},"maintainers":[{"name":"piuccio","email":"piuccio@gmail.com"}],"directories":{},"publish_time":1453283143019,"_hasShrinkwrap":false,"_cnpm_publish_time":1453283143019,"_cnpmcore_publish_time":"2021-12-17T00:17:14.592Z"},"0.2.0":{"name":"git-promise","description":"Simple wrapper to run any git command and process it's output using promises.","version":"0.2.0","homepage":"https://github.com/piuccio/git-promise","author":{"name":"Fabio Crisci","email":"piuccio@gmail.com"},"repository":{"type":"git","url":"git://github.com/piuccio/git-promise.git"},"bugs":{"url":"https://github.com/piuccio/git-promise/issues"},"licenses":[{"type":"MIT","url":"https://github.com/piuccio/git-promise/blob/master/LICENSE"}],"main":"./index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"nodeunit test","cover":"istanbul cover node_modules/nodeunit/bin/nodeunit -- test"},"keywords":["git","shell"],"dependencies":{"q":"~1.0.1","shelljs":"~0.3.0"},"devDependencies":{"nodeunit":"~0.8.6"},"_id":"git-promise@0.2.0","_shasum":"133b08061b1dbb14d77163dbb332379e13a22cfc","_from":"./","_npmVersion":"1.4.9","_npmUser":{"name":"piuccio","email":"piuccio@gmail.com"},"maintainers":[{"name":"piuccio","email":"piuccio@gmail.com"}],"dist":{"shasum":"133b08061b1dbb14d77163dbb332379e13a22cfc","size":4184,"noattachment":false,"key":"/git-promise/-/git-promise-0.2.0.tgz","tarball":"http://name.csiicloud.com:7001/git-promise/download/git-promise-0.2.0.tgz"},"directories":{},"publish_time":1403657313125,"_hasShrinkwrap":false,"_cnpm_publish_time":1403657313125,"_cnpmcore_publish_time":"2021-12-17T00:17:14.817Z"},"0.1.0":{"name":"git-promise","description":"Simple wrapper to run any git command and process it's output using promises.","version":"0.1.0","homepage":"https://github.com/piuccio/git-promise","author":{"name":"Fabio Crisci","email":"piuccio@gmail.com"},"repository":{"type":"git","url":"git://github.com/piuccio/git-promise.git"},"bugs":{"url":"https://github.com/piuccio/git-promise/issues"},"licenses":[{"type":"MIT","url":"https://github.com/piuccio/git-promise/blob/master/LICENSE"}],"main":"./index.js","engines":{"node":">=0.10.0"},"scripts":{"test":"nodeunit test","cover":"istanbul cover node_modules/nodeunit/bin/nodeunit -- test"},"keywords":["git","shell"],"dependencies":{"q":"~1.0.1","shelljs":"~0.2.6"},"devDependencies":{"nodeunit":"~0.8.6"},"_id":"git-promise@0.1.0","dist":{"shasum":"49e29670036988e7c8263ce88a3c294c6a12262e","size":3939,"noattachment":false,"key":"/git-promise/-/git-promise-0.1.0.tgz","tarball":"http://name.csiicloud.com:7001/git-promise/download/git-promise-0.1.0.tgz"},"_from":"./","_npmVersion":"1.4.3","_npmUser":{"name":"piuccio","email":"piuccio@gmail.com"},"maintainers":[{"name":"piuccio","email":"piuccio@gmail.com"}],"directories":{},"publish_time":1398504703068,"_hasShrinkwrap":false,"_cnpm_publish_time":1398504703068,"_cnpmcore_publish_time":"2021-12-17T00:17:15.009Z"}},"readme":"# git-promise\r\n\r\nSimple wrapper that allows you to run any `git` command using a more intuitive syntax.\r\n\r\n## Getting Started\r\n\r\n```shell\r\nnpm install git-promise --save\r\n```\r\n\r\nOnce installed, you can use it in your JavaScript files like so:\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\nconst branch = await git(\"rev-parse --abbrev-ref HEAD\");\r\nconsole.log(branch); // This is your current branch\r\n```\r\n\r\nThe module will handle git exit code automatically, so\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\ntry {\r\n  await git(\"merge origin/master\");\r\n  // Everything was fine\r\n} catch (err) {\r\n  // Something went bad, maybe merge conflict?\r\n  console.error(err);\r\n}\r\n```\r\n\r\n`err` is an [`Error`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) object augmented with `code` property. The following code:\r\n\r\n```js\r\ntry {\r\n  await git('clone http://example.org/notExistingExample.git');\r\n} catch (err) {\r\n  console.log(\"MESSAGE\");\r\n  console.log(err.message);\r\n  console.log(\"ERROR CODE\");\r\n  console.log(err.code);\r\n}\r\n```\r\n\r\nwill log:\r\n\r\n```\r\nMESSAGE\r\nCloning into 'notExistingExample'...\r\nfatal: remote error: Repository does not exist\r\nThe requested repository does not exist, or you do not have permission to\r\naccess it.\r\n}\r\nERROR CODE\r\n128\r\n```\r\n\r\n## Advanced usage\r\n\r\nThe `git` command accepts a second parameter that can be used to parse the output or to deal with non 0 exit code.\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\nconst branch = await git(\"status -sb\",\r\n  (stdout) => stdout.match(/## (.*)/)[1]);\r\nconsole.log(branch); // This is your current branch\r\n```\r\n\r\nThe callback accepts 2 parameters, `(stdout, error)`, where `stdout` is the output of the git command and `error` is either `null` or an `Error` in case the git command fails.\r\n\r\nThe return value of this function will be the resolved value of the promise.\r\n\r\nIf the `error` parameter is not specified, it'll be handled automatically and the promise will be rejected in case of non 0 error codes.\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\ngit(\"merge-base --is-ancestor master HEAD\", function (stdout, error) {\r\n  if (!error) {\r\n    // the branch we are on is fast forward to master\r\n    return true;\r\n  } else if (error.code === 1) {\r\n    // no, it's not\r\n    return false;\r\n  } else {\r\n    // some other error happened\r\n    throw error;\r\n  }\r\n}).then(function (isFastForward) {\r\n  console.log(isFastForward);\r\n}).catch(function (err) {\r\n  // deal with the error\r\n});\r\n```\r\n\r\n### Argument parsing\r\n\r\nVersion 1.0 changes the way the input command is parsed, so instead of executing anything that gets passed as the first parameter, it makes sure that `git` is the only executable used.\r\n\r\n`git(\"status | grep hello\")` won't be executed as a shell command, but everything will be passed as arguments to `git`, likely resulting in an error in this specific case.\r\n\r\nIf your `git` command stops working after upgrading to version 1.0\r\n1. Make sure you're only executing git commands.\r\n1. Try passing an array of arguments instead of a string. For instance: `git([\"merge-base\", \"--is-ancestor\", \"master\", \"HEAD\"]);`.\r\n\r\n### Chaining commands\r\n\r\nImagine to be on a local branch which is not fast forward with master and you want to know which commit were pushed on master after the forking point:\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\nfunction findForkCommit () {\r\n  return git(\"merge-base master HEAD\", output => output.trim());\r\n}\r\n\r\nfunction findChanges (forkCommit) {\r\n  return git(\"log \" + forkCommit + \"..master --format=oneline\",\r\n    output => output.trim().split(\"\\n\"));\r\n}\r\n\r\nconst forkCommit = await findForkCommit();\r\nconst commits = await findChanges(forkCommit);\r\n```\r\n\r\n### Working directory\r\n\r\nBy default all git commands run in the current working directory (i.e. `process.cwd()`).\r\n\r\nYou can use the following syntax to run a git command in different folder\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\nawait git(\"blame file1.js\", {cwd: \"src/\"});\r\n```\r\n\r\n### Custom git executable\r\n\r\nBy default any command tries to use `git` in `$PATH`, if you have installed `git` in a funky location you can override this value using `gitExec`.\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\n\r\nawait git(\"status\", {gitExec: \"/usr/local/sbin/git\"});\r\n```\r\n\r\n## Utility methods\r\n\r\nThis module comes with some utility methods to parse the output of some git commands\r\n\r\n```js\r\nconst util = require(\"git-promise/util\");\r\n```\r\n\r\n* `util.extractStatus(output [, lineSeparator])`\r\n\r\nParse the output of `git status --porcelain` and returns an object with\r\n\r\n```\r\n{\r\n  branch: \"current branch name, only if git status -b is used\",\r\n  index: {\r\n    modified: [\"list of files modified in the index\"],\r\n    added: [\"list of files added in the index\"],\r\n    deleted: [\"list of files deleted in the index\"],\r\n    renamed: [\"list of files renamed in the index\"],\r\n    copied: [\"list of files copied in the index\"]\r\n  },\r\n  workingTree: {\r\n    modified: [\"list of files modified in the local working tree\"],\r\n    added: [\"list of files added / renamed / copied in the local working tree\"],\r\n    deleted: [\"list of files deleted in the local working tree\"]\r\n  }\r\n}\r\n```\r\n\r\nThe method works both with or without option `-z`.\r\n\r\n* `util.hasConflict(output)`\r\n\r\nTry to determine if there's a merge conflict from the output of `git merge-tree`\r\n\r\n```js\r\nconst git = require(\"git-promise\");\r\nconst util = require(\"git-promise/util\");\r\n\r\ngit(\"merge-tree <root-commit> <branch1> <branch2>\").then(function (stdout) {\r\n  console.log(util.hasConflict(stdout));\r\n});\r\n```\r\n\r\n## Release History\r\n\r\n* 1.0.0\r\n  BREAKING CHANGE: The returned value is now a standard JavaScript `Promise`, not anymore a `Q` promise.\r\n  BREAKING CHANGE: Internally the library switches from `shell` to `execFile` to avoid problems with non sanitized input commands.\r\n  BREAKING CHANGE: Callbacks using 2 parameters now receive an error as second parameter instead of an error code.\r\n* 0.3.1 Fix current working directory not switching back when command exits with error\r\n* 0.3.0 Custom git executable with `gitExec` option\r\n* 0.2.0 Change current working directory\r\n* 0.1.0 Just started\r\n","_attachments":{},"homepage":"https://github.com/piuccio/git-promise","bugs":{"url":"https://github.com/piuccio/git-promise/issues"}}