Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonschlinkert/gfc

Simple way to initialize a new git repository in an empty directory, add a file and do a first commit (or skip that part in a directory with files). Useful for unit tests and generators.
https://github.com/jonschlinkert/gfc

add api commit first-commit git init javascript nodejs

Last synced: 15 days ago
JSON representation

Simple way to initialize a new git repository in an empty directory, add a file and do a first commit (or skip that part in a directory with files). Useful for unit tests and generators.

Awesome Lists containing this project

README

        

# gfc [![NPM version](https://img.shields.io/npm/v/gfc.svg?style=flat)](https://www.npmjs.com/package/gfc) [![NPM monthly downloads](https://img.shields.io/npm/dm/gfc.svg?style=flat)](https://npmjs.org/package/gfc) [![NPM total downloads](https://img.shields.io/npm/dt/gfc.svg?style=flat)](https://npmjs.org/package/gfc) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/gfc.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/gfc) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/gfc.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/gfc)

> Simple way to initialize a new git repository in an empty directory, add a file and do a first commit (or skip that part in a directory with files). Useful for unit tests and generators.

Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save gfc
```

## Usage

```js
const firstCommit = require('gfc');
```

The main export is an async function that takes a [callback](#async-usage) or returns a [promise](#promise-usage) when no callback is passed. A [.sync](#sync-usage) method is also exposed.

**Default behavior**

The following steps can be customized with [options](#options):

1. Creates a new git repository
2. Adds a `.gitkeep` file if the cwd is empty.
3. `git add .`
4. do a first commit with the message `"first commit"`

### promise usage

Returns a promise if a [callback](#async-usage) is not passed.

```js
firstCommit(cwd[, options])
.then(res => {
console.log('stdout: ' + res.stdout);
console.log('stderr: ' + res.stderr);
})
.catch(err => console.log('Error: ', err));
```

### async usage

```js
firstCommit(cwd[, options], function(err, stdout, stderr) {
if (err) {
console.error('exec error: ' + err);
return;
}
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
});
```

### sync usage

```js
firstCommit.sync(cwd[, options]);
```

## Options

### options.file

**Type**: `object|boolean`

**Default**: `{ path: '.gitkeep', contents: '' }`

```js
firstCommit.sync('foo/bar', { file: false })
```

### options.message

**Type**: `string`

**Default**: `'first commit'`

```js
var options = {message: 'my amazing first commit'};

firstCommit('foo/bar', options, function(err) {
if (err) {
console.log(err);
} else {
console.log('done!');
}
});
```

### options.exec

**Type**: `object`

**Default**: `undefined`

Options to pass to [execSync](https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options).

```js
var options = {
message: 'my amazing first commit',
exec: {
timeout: 3000,
killSignal: 'SIGTERM'
}
};

firstCommit.sync('foo/bar', options);
```

## About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Related projects

You might also be interested in these projects:

* [git-branch](https://www.npmjs.com/package/git-branch): Get the current branch for a local git repository. | [homepage](https://github.com/jonschlinkert/git-branch "Get the current branch for a local git repository.")
* [git-user-name](https://www.npmjs.com/package/git-user-name): Get a user's name from git config at the project or global scope, depending on… [more](https://github.com/jonschlinkert/git-user-name) | [homepage](https://github.com/jonschlinkert/git-user-name "Get a user's name from git config at the project or global scope, depending on what git uses in the current context.")
* [git-username](https://www.npmjs.com/package/git-username): Get the username (or 'owner' name) from a git/GitHub remote origin URL. | [homepage](https://github.com/jonschlinkert/git-username "Get the username (or 'owner' name) from a git/GitHub remote origin URL.")
* [list-git-remotes](https://www.npmjs.com/package/list-git-remotes): List the remotes for a local git repository. Sync and async. | [homepage](https://github.com/jonschlinkert/list-git-remotes "List the remotes for a local git repository. Sync and async.")

### Contributors

| **Commits** | **Contributor** |
| --- | --- |
| 6 | [johno](https://github.com/johno) |
| 6 | [jonschlinkert](https://github.com/jonschlinkert) |

### Author

**Jon Schlinkert**

* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)

### License

Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 09, 2018._