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.
Install with npm:
$ npm install --save gfc
Install with yarn:
$ yarn add gfc
var firstCommit = require('gfc');
// async
firstCommit(cwd[, options], function(err, stdout, stderr) {
if (err) {
console.error('exec error: ' + err);
return;
}
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
});
// sync
firstCommit.sync(cwd[, options]);
Example
var firstCommit = require('gfc');
var dir = 'foo/bar';
firstCommit(dir, function(err) {
if (err) {
console.log(err);
} else {
console.log('done!');
}
});
(NOTE: Most of the following examples will show async usage, but for the most part, the sync method works the same way without the callback)
By default, this library will:
- create a new git repository
- add a
temp.txt
file git add .
- do a first commit with the message
"first commit"
You can disable #2, or customize other behavior via options.
Type: string
Default: 'test fixture'
If not disabled, customize the contents of the default file added in step 2.
var options = {contents: 'my custom contents'};
firstCommit('foo/bar', options, function(err) {
if (err) {
console.log(err);
} else {
console.log('done!');
}
});
Type: boolean
Default: undefined
Disable adding the default file in step 2.
var options = {file: false};
firstCommit('foo/bar', options, function(err) {
if (err) {
console.log(err);
} else {
console.log('done!');
}
});
Type: string
Default: 'temp.txt'
If not disabled, customize the filename of the file added in step 2.
var options = {message: 'my amazing first commit'};
firstCommit('foo/bar', options, function(err) {
if (err) {
console.log(err);
} else {
console.log('done!');
}
});
Type: string
Default: 'first commit'
Customize the first commit message.
var options = {message: 'my amazing first commit'};
firstCommit('foo/bar', options, function(err) {
if (err) {
console.log(err);
} else {
console.log('done!');
}
});
Type: object
Default: undefined
Options to pass to execSync.
var options = {
message: 'my amazing first commit',
exec: {
timeout: 3000,
killSignal: 'SIGTERM'
}
};
firstCommit.sync('foo/bar', options);
Type: boolean
Default: false
Initialize the repo and create the file but don't git commit
or git add .
.
var options = { skipCommit: true };
firstCommit.sync('foo/bar', options);
- git-branch: Get the current branch for a local git repository. | homepage
- git-user-name: Get a user's name from git config at the project or global scope, depending on… more | homepage
- git-username: Get the username from a git remote origin URL. | homepage
- list-git-remotes: List the remotes for a local git repository. Sync and async. | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
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:
$ npm install && npm test
Jon Schlinkert
Copyright © 2017, Jon Schlinkert. Released under the MIT License.
This file was generated by verb-generate-readme, v0.5.0, on April 19, 2017.