Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/atlassubbed/atlas-repo-info
https://github.com/atlassubbed/atlas-repo-info
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/atlassubbed/atlas-repo-info
- Owner: atlassubbed
- License: other
- Created: 2018-06-26T05:41:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-28T22:49:08.000Z (over 6 years ago)
- Last Synced: 2024-04-26T08:04:38.145Z (9 months ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# atlas-repo-info
Get basic git repository information about a directory.
[![Travis](https://img.shields.io/travis/atlassubbed/atlas-repo-info.svg)](https://travis-ci.org/atlassubbed/atlas-repo-info)
---
## install
```
npm install --save atlas-repo-info
```## why
This function returns basic git information about a directory, so you don't need to clutter your codebase with git-related `exec` or `spawn` calls.
## examples
All you need to do is pass in the desired path to inspect, and a callback. If there is no `info` object passed to the callback, it means the passed directory is not a git repository. See caveats.
```javascript
const getRepoInfo = require("atlas-repo-info");
const projectPath = process.cwd();
getRepoInfo(projectPath, (err, info) => {
if (err) return console.error(err);
if (!info) return console.log(`${projectPath} is not a repo`);
const { gitRoot, name, dir, branch, remotes } = info;
// full path of the root of the git project
console.log(gitRoot)
// name of the project's folder
console.log(name)
// name of the project's parent dir
console.log(dir)
// name of the checked-out branch
console.log(branch)
// hash of remote name -> url pairs
console.log(remotes)
// url for the "origin" remote, if it exists
if (remotes.origin)
console.log(remotes.origin)
})
```## caveats
You might run into issues if used with a bare repository (i.e. repoistories created with `git init --bare`). No check is currently implemented for bare repositories. It might be implemented later if I need it.