{"id":19352798,"url":"https://github.com/thisconnect/nodegit-kit","last_synced_at":"2025-04-23T07:31:23.723Z","repository":{"id":2765328,"uuid":"41910804","full_name":"thisconnect/nodegit-kit","owner":"thisconnect","description":"Complementary NodeGit helpers returning native Promises, helps with git commands such as init, add, commit, status, diff","archived":false,"fork":false,"pushed_at":"2023-03-04T02:38:03.000Z","size":882,"stargazers_count":64,"open_issues_count":22,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-16T07:07:13.191Z","etag":null,"topics":["commit","diff","log","nodegit","status"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thisconnect.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-09-04T10:43:45.000Z","updated_at":"2025-01-28T20:49:49.000Z","dependencies_parsed_at":"2023-07-05T17:00:08.474Z","dependency_job_id":null,"html_url":"https://github.com/thisconnect/nodegit-kit","commit_stats":{"total_commits":278,"total_committers":12,"mean_commits":"23.166666666666668","dds":"0.23381294964028776","last_synced_commit":"b4f751a60115551b19c120148e8569dfb0e36197"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fnodegit-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fnodegit-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fnodegit-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thisconnect%2Fnodegit-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thisconnect","download_url":"https://codeload.github.com/thisconnect/nodegit-kit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250391245,"owners_count":21422862,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commit","diff","log","nodegit","status"],"created_at":"2024-11-10T04:40:31.056Z","updated_at":"2025-04-23T07:31:23.154Z","avatar_url":"https://github.com/thisconnect.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"NodeGit-Kit\n-----------\n\n[![Build Status](https://img.shields.io/travis/thisconnect/nodegit-kit/master.svg?style=flat-square\u0026maxAge=1800)](https://travis-ci.org/thisconnect/nodegit-kit)\n[![Build Status](https://img.shields.io/appveyor/ci/thisconnect/nodegit-kit/master.svg?style=flat-square\u0026maxAge=1800)](https://ci.appveyor.com/project/thisconnect/nodegit-kit)\n[![Coverage Status](https://img.shields.io/codecov/c/github/thisconnect/nodegit-kit/master.svg?style=flat-square\u0026maxAge=1800)](https://codecov.io/gh/thisconnect/nodegit-kit)\n[![MIT](https://img.shields.io/npm/l/nodegit-kit.svg?style=flat-square\u0026maxAge=1800)](https://github.com/thisconnect/nodegit-kit/blob/master/license)\n[![NPM Version](https://img.shields.io/npm/v/nodegit-kit.svg?style=flat-square\u0026maxAge=1800)](https://www.npmjs.com/package/nodegit-kit)\n\nPromises for git commands such as `git init`,\n`git status`, `git add *`, `git diff`, `git log` and `git commit -am\"commit message\"`.\n\nComments are welcome at [nodegit-kit/issues](https://github.com/thisconnect/nodegit-kit/issues)\n\n### Install\n\n```bash\nnpm i --save nodegit-kit\n```\n\n\n### Usage\n\n```javascript\nvar git = require('nodegit-kit');\n\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n\n     // git diff\n    return git.diff(repo)\n    .then(diff =\u003e {\n        console.log(diff);\n\n        // git commit -am\"commit message\"\n        return git.commit(repo, {\n            'message': 'commit message'\n        });\n    })\n    .then(() =\u003e {\n        // git log\n        return git.log(repo);\n    })\n    .then(log =\u003e {\n        console.log(log);\n    });\n})\n.catch(error =\u003e {\n    console.error(error);\n});\n```\n\n\n## API\n\n- [open](#open-path-options)\n- [commit](#commit-repo-options)\n- [status](#status-repo)\n- [log](#log-repo-options)\n- [diff](#diff-repo-commit-commit)\n- [config](#config)\n- [init](#init-path-options)\n- [init.commit](#init.commit-repo-options)\n\n\n### open (path[, options])\n\nReturns repository, if no repo is found, tries to create the directory\nand initializes the repository.\nInitializing is using [init](#init-path-options) internally.\n\n- `path` String\n- `options` Object\n  - `init` Boolean whether to create a first commit, defaults to true\n\n```javascript\ngit.open('../repo-path/new/or/existing', {\n    'init': false\n})\n.then(repo =\u003e {\n    // NodeGit repository instance\n})\n.catch(err =\u003e {\n    // no repo here\n});\n```\n\n\n### commit (repo[, options])\n\nChecks if status has pending changes, commits, returns Oid else returns null.\n\n- `repo` NodeGit repository instance\n- `options`\n  - `message` String defaults to 'update'\n\n```javascript\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n    // git commit -am\"a new commit\"\n    return git.commit(repo, {\n        'message': 'a new commit'\n    })\n    .then(oid =\u003e {\n        console.log(oid);\n    });\n});\n```\n\n\n### status (repo)\n\nReturns an Array of changed files and their status.\n\n- `repo` NodeGit repository instance\n\n```javascript\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n    // git status\n    return git.status(repo)\n    .then(status =\u003e {\n        console.log(status);\n    });\n});\n```\n\n\n### log (repo[, options])\n\nReturns an Array of all commits.\n\n- `repo` NodeGit repository instance\n- `options`\n  - `branch` String name of a branch, defaults to 'master'\n  - `sort` String can be 'none', 'topological', 'time' or 'reverse'\n  - `abbrev-commit` Boolean if true shortens checksum, defaults to false\n  - `abbrev` Number to specify a custom number of digits in combination with `abbrev-commit`, otherwise uses 'core.abbrev' config\n  - `max-count` Max number of commits to traverse\n\n```javascript\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n    // git log\n    return git.log(repo)\n    .then(log =\u003e {\n        console.log(log);\n    });\n});\n```\n\n\n### diff (repo[, commit[, commit]][, options])\n\nReturns an Array of modified files and their diffs.\n\n- `repo` NodeGit repository instance\n- `options`\n  - `name-only` Boolean return only filenames, defaults to false\n\n```javascript\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n    // git diff\n    return git.diff(repo, { 'name-only': true })\n    .then(filenames =\u003e {\n        console.log(filenames);\n    });\n});\n```\n\n\n#### Get a diff of a commit\n\n```javascript\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n    return git.log(repo)\n    .then(history =\u003e {\n        return history[0].commit;\n    })\n    .then(commit =\u003e {\n        // git diff \u003ccommit\u003e\n        return git.diff(repo, commit);\n    })\n    .then(diff =\u003e {\n        console.log(diff);\n    });\n});\n```\n\n\n#### Get a diff between 2 commits\n\n**Breaking API change in 0.12.0**\nChanged order of `from` and `to` to be aligned with git-cli.\n\n```javascript\ngit.open('../repo-path/new/or/existing')\n.then(repo =\u003e {\n    return git.log(repo, { sort: 'reverse' })\n    .then(history =\u003e {\n        var commit1 = history[0].commit;\n        var commit2 = history[2].commit;\n        // git diff \u003cfrom\u003e \u003cto\u003e\n        return git.diff(repo, commit1, commit2);\n    })\n    .then(diff =\u003e {\n        console.log(diff);\n    });\n});\n```\n\n\n### config\n\nAllows to write/read global and local git config values.\nLocal values are stored in the Git directory `./git/config` and overrule global configurations.\nNote: Git locks the config when changing configurations,\ntherefore writing multiple configs can not be done in parallel.\ne.g. Promise.all multiple individual `git.config.set` calls\nwill throw a \"Failed to lock file for writing\" error,\n[nodegit/issues/757](https://github.com/nodegit/nodegit/issues/757).\n\n\nSee also [8.1 Customizing Git - Git Configuration](http://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration) (Git SCM Documentation)\n\n\n#### config.set (repo, options)\n\n##### Example setting user.name and user.email for a specific repository\n\nSet user name and email similar to `cd repo` then\n`git config user.name \"John Doe\"` and  `git config user.email johndoe@example.com`.\n\n```javascript\ngit.open('my/repository')\n.then(repo =\u003e {\n    return git.config.set(repo, {\n        'user.name': 'John Doe',\n        'user.email': 'johndoe@example.com'\n    });\n});\n```\n\n\n#### config.get (repo, options)\n\n##### Example reading user.name and user.email\n\nSimilar to `cd repo` then`git config user.name` returns config for a repository if there any or else the global Git configuration.\n\n```javascript\ngit.open('my/repository')\n.then(repo =\u003e {\n    return git.config.get(repo, ['user.name', 'user.email']);\n})\n.then(configs =\u003e {\n    // [ 'John Doe', 'johndoe@example.com' ]\n});\n```\n\n### global git configuration\n\n#### config.get (options)\n\nWhen no repo is given, setting and getting config will operate in `--global` mode and read and write to `~/.gitconfig` (or `~/.config/git/config`).\n\n```javascript\ngit.config.get(['user.name', 'user.email'])\n.then(config =\u003e {\n    // [ 'John Doe', 'johndoe@example.com' ]\n});\n```\n\n#### config.set (options)\n\n```javascript\n// WARNING: this will change your global git config\ngit.config.set({\n    'user.name': 'John Doe',\n    'user.email': 'johndoe@example.com'\n});\n```\n\n\n### init (path[, options])\n\nEnsures directory exists, initializes, creates a first commit and returns repo.\nThis is optional and only useful to control the first commit.\n\n- `path` String\n- `options` Object\n  - `bare` Number defaults to 0\n  - `commit` Boolean defaults to true\n  - `message` String defaults to 'initial commit'\n\n```javascript\ngit.init('../repo-path/new/or/existing', {\n    'bare': 0,\n    'commit': true,\n    'message': 'my first commit'\n})\n.then(repo =\u003e {\n    // NodeGit repository instance\n});\n```\n\n\n### init.commit (repo[, options])\n\nCan be used to in combination with suppressing commit on init.\n\n\n- `repo` NodeGit Repository instance\n- `options`\n  - `message` String defaults to 'initial commit'\n\n\n```javascript\ngit.open('../path/to/repo', {\n    'init': false\n})\n.catch(err =\u003e {\n    return git.init('../path/to/repo', {\n        'commit': false\n    })\n    .then(repo =\u003e {\n        // do something before first commit\n        return repo;\n    })\n    .then(repo =\u003e {\n        git.init.commit(repo, {\n            'message': 'initialize repository'\n        });\n    });\n})\n.then(repo =\u003e {\n    // NodeGit repository instance\n});\n```\n\n\n## Test\n\n```bash\nnpm install\n\nnpm test\n\n# debug nodegit-kit\nDEBUG=kit* npm test\n\n# debug all\nDEBUG=* npm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisconnect%2Fnodegit-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthisconnect%2Fnodegit-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthisconnect%2Fnodegit-kit/lists"}