Skip to content

Commit

Permalink
Merge pull request #106 from cksource/t/85
Browse files Browse the repository at this point in the history
Other: RIP mgit2 💀 Long live mrgit 🎉 Closes #85.

BREAKING CHANGE: mgit2 was renamed to mrgit.
  • Loading branch information
Reinmar authored Jul 23, 2019
2 parents 2d1450c + ad3acc1 commit 4a2a33f
Show file tree
Hide file tree
Showing 36 changed files with 351 additions and 354 deletions.
132 changes: 65 additions & 67 deletions README.md

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const chalk = require( 'chalk' );
const meow = require( 'meow' );
const mgit = require( './lib/index' );
const mrgit = require( './lib/index' );
const getCommandInstance = require( './lib/utils/getcommandinstance' );

handleCli();
Expand All @@ -33,15 +33,15 @@ function handleCli() {
}
};

const mgitLogo = `
_ _
(_) |
_ __ ___ __ _ _| |_
| '_ \` _ \\ / _\` | | __|
| | | | | | (_| | | |_
|_| |_| |_|\\__, |_|\\__|
__/ |
|___/
const logo = `
_ _
(_) |
_ __ ___ _ __ __ _ _| |_
| '_ \` _ \\| '__| / _\` | | __|
| | | | | | | _ | (_| | | |_
|_| |_| |_|_|(_) \\__, |_|\\__|
__/ |
|___/
`;

const {
Expand All @@ -52,20 +52,20 @@ function handleCli() {
yellow: y,
} = chalk;

const cli = meow( `${ mgitLogo }
const cli = meow( `${ logo }
${ u( 'Usage:' ) }
$ mgit ${ c( 'command' ) } ${ y( '[--options]' ) } -- ${ m( '[--git-options]' ) }
$ mrgit ${ c( 'command' ) } ${ y( '[--options]' ) } -- ${ m( '[--git-options]' ) }
${ u( 'Commands:' ) }
${ c( 'checkout' ) } Changes branches in repositories according to the configuration file.
${ c( 'close' ) } Merges specified branch with the current one and remove merged branch from the remote.
${ c( 'commit' ) } Commits all changes. A shorthand for "mgit exec 'git commit -a'".
${ c( 'commit' ) } Commits all changes. A shorthand for "mrgit exec 'git commit -a'".
${ c( 'diff' ) } Prints changes from packages where something has changed.
${ c( 'exec' ) } Executes shell command in each package.
${ c( 'fetch' ) } Fetches existing repositories.
${ c( 'pull' ) } Pulls changes in existing repositories.
${ c( 'push' ) } Pushes changes in existing repositories to remotes.
${ c( 'save' ) } Saves hashes of packages in mgit.json. It allows to easily fix project to a specific state.
${ c( 'save' ) } Saves hashes of packages in mrgit.json. It allows to easily fix project to a specific state.
${ c( 'status' ) } Prints a table which contains useful information about the status of repositories.
${ c( 'sync' ) } Updates packages to the latest versions or install missing ones.
Expand All @@ -77,7 +77,7 @@ function handleCli() {
${ y( '--hash' ) } Whether to save current commit hashes. Used only by "${ u( 'save' ) }" command.
${ y( '--ignore' ) } Ignores packages which names match the given glob pattern. E.g.:
${ g( '> mgit exec --ignore="foo*" "git status"' ) }
${ g( '> mrgit exec --ignore="foo*" "git status"' ) }
Will ignore all packages which names start from "foo".
${ g( 'Default: null' ) }
Expand All @@ -91,7 +91,7 @@ function handleCli() {
${ y( '--recursive' ) } Whether to install dependencies recursively. Used only by "${ u( 'sync' ) }" command.
${ y( '--resolver-path' ) } Path to a custom repository resolver function.
${ g( 'Default: \'@mgit2/lib/default-resolver.js\'' ) }
${ g( 'Default: \'@mrgit/lib/default-resolver.js\'' ) }
${ y( '--resolver-url-template' ) } Template used to generate repository URL out of a
simplified 'organization/repository' format of the dependencies option.
Expand All @@ -108,26 +108,26 @@ function handleCli() {
whether the repository will be cloned to packages/@scope/pkgname' or 'packages/pkgname'.
${ g( 'Default: \'git\'' ) }
${ y( '--resolver-default-branch' ) } The branch name to use if not specified in mgit.json dependencies.
${ y( '--resolver-default-branch' ) } The branch name to use if not specified in mrgit.json dependencies.
${ g( 'Default: master' ) }
${ y( '--scope' ) } Restricts the command to packages which names match the given glob pattern.
${ g( 'Default: null' ) }
${ u( 'Git Options:' ) }
Git options are supported by the following commands: commit, diff, fetch, push.
Type "mgit [command] -h" in order to see which options are supported.
Type "mrgit [command] -h" in order to see which options are supported.
`, meowOptions );

const commandName = cli.input[ 0 ];

// If user specified a command and `--help` flag wasn't active.
if ( commandName && !cli.flags.help ) {
return mgit( cli.input, cli.flags );
return mrgit( cli.input, cli.flags );
}

// A user wants to see "help" screen.
// Missing command. Displays help screen for the entire Mgit.
// Missing command. Displays help screen for the entire Mr. Git.
if ( !commandName ) {
return cli.showHelp( 0 );
}
Expand All @@ -141,7 +141,7 @@ function handleCli() {
}

// Specified command is is available, displays the command's help.
console.log( mgitLogo );
console.log( logo );
console.log( ` ${ u( 'Command:' ) } ${ c( commandInstance.name || commandName ) } ` );
console.log( commandInstance.helpMessage );
}
16 changes: 8 additions & 8 deletions lib/commands/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ module.exports = {

return `
${ u( 'Description:' ) }
Checks out the repository to specified branch or commit saved in "mgit.json" file.
Checks out the repository to specified branch or commit saved in "mrgit.json" file.
If specified a branch as an argument for "checkout" command, mgit will use the branch
instead of data saved in "mgit.json". E.g "${ g( 'mgit checkout master' ) }" will check out
If specified a branch as an argument for "checkout" command, mrgit will use the branch
instead of data saved in "mrgit.json". E.g "${ g( 'mrgit checkout master' ) }" will check out
all branches to "master".
You can also call "${ g( 'mgit checkout .' ) }" in order to restore files before changes.
You can also call "${ g( 'mrgit checkout .' ) }" in order to restore files before changes.
${ u( 'Options:' ) }
${ y( '--branch' ) } (-b) If specified, mgit will create given branch in all repositories
${ y( '--branch' ) } (-b) If specified, mrgit will create given branch in all repositories
that contain changes that could be committed.
${ g( '> mgit checkout --branch develop' ) }
${ g( '> mrgit checkout --branch develop' ) }
`;
},

Expand All @@ -42,8 +42,8 @@ module.exports = {
*/
execute( data ) {
// Used `--branch` option.
if ( data.mgitOptions.branch ) {
return this._createAndCheckout( data.mgitOptions.branch, data );
if ( data.toolOptions.branch ) {
return this._createAndCheckout( data.toolOptions.branch, data );
}

const branch = data.arguments[ 0 ] || data.repository.branch;
Expand Down
14 changes: 7 additions & 7 deletions lib/commands/close.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ module.exports = {
${ u( 'Options:' ) }
${ m( '--message' ) } (-m) An additional description for merge commit. It will be
appended to the default message. E.g.:
${ g( '> mgit merge develop -- -m "Some description about merged changes."' ) }
${ g( '> mrgit merge develop -- -m "Some description about merged changes."' ) }
`;
},

beforeExecute( args ) {
if ( !args[ 1 ] ) {
throw new Error( 'Missing branch to merge. Use: mgit close [branch].' );
throw new Error( 'Missing branch to merge. Use: mrgit close [branch].' );
}
},

Expand All @@ -62,7 +62,7 @@ module.exports = {
};
}

const mergeMessage = this._getMergeMessage( data.mgitOptions, data.arguments );
const mergeMessage = this._getMergeMessage( data.toolOptions, data.arguments );
const commitTitle = `Merge branch '${ branch }'`;

let mergeCommand = `git merge ${ branch } --no-ff -m "${ commitTitle }"`;
Expand Down Expand Up @@ -100,17 +100,17 @@ module.exports = {

/**
* @private
* @param {options} mgitOptions Options resolved by mgit.
* @param {options} toolOptions Options resolved by mrgit.
* @param {Array.<String>>} argv List of arguments provided by the user via CLI.
* @returns {Array.<String>}
*/
_getMergeMessage( mgitOptions, argv ) {
_getMergeMessage( toolOptions, argv ) {
const cliOptions = this._parseArguments( argv );

let message;

if ( mgitOptions.message ) {
message = mgitOptions.message;
if ( toolOptions.message ) {
message = toolOptions.message;
} else if ( cliOptions.message ) {
message = cliOptions.message;
} else {
Expand Down
30 changes: 15 additions & 15 deletions lib/commands/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,28 @@ module.exports = {
return `
${ u( 'Description:' ) }
Makes a commit in every repository that contains tracked files that have changed.
This command is a shorthand for: "${ i( 'mgit exec \'git commit -a\'' ) }".
This command is a shorthand for: "${ i( 'mrgit exec \'git commit -a\'' ) }".
${ u( 'Options:' ) }
${ y( '--message' ) } (-m) Required. A message for the commit. It can be specified more then once, e.g.:
${ g( '> mgit commit --message "Title of the commit." --message "Additional description."' ) }
${ g( '> mrgit commit --message "Title of the commit." --message "Additional description."' ) }
${ u( 'Git Options:' ) }
${ m( '--no-verify' ) } (-n) Whether to skip pre-commit and commit-msg hooks.
${ g( '> mgit commit -m "Title of the commit." -- -n' ) }
${ g( '> mrgit commit -m "Title of the commit." -- -n' ) }
`;
},

/**
* @param {Array.<String>} args Arguments and options that a user provided calling the command.
* @param {Options} mgitOptions Options resolved by mgit.
* @param {Options} toolOptions Options resolved by mrgit.
*/
beforeExecute( args, mgitOptions ) {
beforeExecute( args, toolOptions ) {
const cliOptions = this._parseArguments( args );
const commitMessage = this._getCommitMessage( mgitOptions, cliOptions );
const commitMessage = this._getCommitMessage( toolOptions, cliOptions );

if ( !commitMessage.length ) {
throw new Error( 'Missing --message (-m) option. Call "mgit commit -h" in order to read more.' );
throw new Error( 'Missing --message (-m) option. Call "mrgit commit -h" in order to read more.' );
}
},

Expand All @@ -71,7 +71,7 @@ module.exports = {
}

const cliOptions = this._parseArguments( data.arguments );
const commitCommand = this._buildCliCommand( data.mgitOptions, cliOptions );
const commitCommand = this._buildCliCommand( data.toolOptions, cliOptions );

return execCommand.execute( getExecData( commitCommand ) );
} );
Expand All @@ -85,12 +85,12 @@ module.exports = {

/**
* @private
* @param {options} mgitOptions Options resolved by mgit.
* @param {options} toolOptions Options resolved by mrgit.
* @param {Object} cliOptions Parsed arguments provided by the user via CLI.
* @returns {String}
*/
_buildCliCommand( mgitOptions, cliOptions ) {
const commitMessage = this._getCommitMessage( mgitOptions, cliOptions );
_buildCliCommand( toolOptions, cliOptions ) {
const commitMessage = this._getCommitMessage( toolOptions, cliOptions );
let command = 'git commit -a';

command += ' ' + commitMessage.map( message => `-m "${ message }"` ).join( ' ' );
Expand All @@ -104,15 +104,15 @@ module.exports = {

/**
* @private
* @param {Options} mgitOptions Options resolved by mgit.
* @param {Options} toolOptions Options resolved by mrgit.
* @param {Object} cliOptions Parsed arguments provided by the user via CLI.
* @returns {Array.<String>}
*/
_getCommitMessage( mgitOptions, cliOptions ) {
_getCommitMessage( toolOptions, cliOptions ) {
let message;

if ( mgitOptions.message ) {
message = mgitOptions.message;
if ( toolOptions.message ) {
message = toolOptions.message;
} else if ( cliOptions.message ) {
message = cliOptions.message;
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ module.exports = {
"${ m( '--color' ) }" is adding. You can cancel it using option "${ m( '--no-color' ) }".
${ u( 'Git Options:' ) }
All options accepted by "${ i( 'git diff' ) }" are supported by mgit. Everything specified after "--" is passed directly to the
All options accepted by "${ i( 'git diff' ) }" are supported by mrgit. Everything specified after "--" is passed directly to the
"${ i( 'git diff' ) }" command.
E.g.: "${ g( 'mgit diff -- origin/master..master' ) }" will execute "${ i( 'git diff --color origin/master..master' ) }"
E.g.: "${ g( 'mrgit diff -- origin/master..master' ) }" will execute "${ i( 'git diff --color origin/master..master' ) }"
`;
},

Expand Down
16 changes: 8 additions & 8 deletions lib/commands/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ module.exports = {

return `
${ u( 'Description:' ) }
Requires a command that will be executed on all repositories. E.g. "${ g( 'mgit exec pwd' ) }" will execute "${ i( 'pwd' ) }"
Requires a command that will be executed on all repositories. E.g. "${ g( 'mrgit exec pwd' ) }" will execute "${ i( 'pwd' ) }"
command in every repository. Commands that contain spaces must be wrapped in quotation marks,
e.g.: "${ g( 'mgit exec "git remote"' ) }".
e.g.: "${ g( 'mrgit exec "git remote"' ) }".
`;
},

/**
* @param {Array.<String>} args Arguments that user provided calling the mgit.
* @param {Array.<String>} args Arguments that user provided calling the mrgit.
*/
beforeExecute( args ) {
if ( args.length === 1 ) {
throw new Error( 'Missing command to execute. Use: mgit exec [command-to-execute].' );
throw new Error( 'Missing command to execute. Use: mrgit exec [command-to-execute].' );
}
},

Expand All @@ -43,11 +43,11 @@ module.exports = {
const log = require( '../utils/log' )();

return new Promise( ( resolve, reject ) => {
const newCwd = path.join( data.mgitOptions.packages, data.repository.directory );
const newCwd = path.join( data.toolOptions.packages, data.repository.directory );

// Package does not exist.
if ( !fs.existsSync( newCwd ) ) {
log.error( `Package "${ data.packageName }" is not available. Run "mgit sync" in order to download the package.` );
log.error( `Package "${ data.packageName }" is not available. Run "mrgit sync" in order to download the package.` );

return reject( { logs: log.all() } );
}
Expand All @@ -56,14 +56,14 @@ module.exports = {

shell( data.arguments[ 0 ] )
.then( stdout => {
process.chdir( data.mgitOptions.cwd );
process.chdir( data.toolOptions.cwd );

log.info( stdout );

resolve( { logs: log.all() } );
} )
.catch( error => {
process.chdir( data.mgitOptions.cwd );
process.chdir( data.toolOptions.cwd );

log.error( error );

Expand Down
4 changes: 2 additions & 2 deletions lib/commands/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
return `
${ u( 'Description:' ) }
Download objects and refs from the remote repository. If some package is missed, the command will not be executed.
For cloned repositories this command is a shorthand for: "${ i( 'mgit exec \'git fetch\'' ) }".
For cloned repositories this command is a shorthand for: "${ i( 'mrgit exec \'git fetch\'' ) }".
${ u( 'Git Options:' ) }
${ m( '--prune' ) } (-p) Before fetching, remove any remote-tracking references that
Expand All @@ -42,7 +42,7 @@ module.exports = {
const log = require( '../utils/log' )();
const execCommand = require( './exec' );

const destinationPath = path.join( data.mgitOptions.packages, data.repository.directory );
const destinationPath = path.join( data.toolOptions.packages, data.repository.directory );

// Package is not cloned.
if ( !fs.existsSync( destinationPath ) ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
return `
${ u( 'Description:' ) }
Pull changes in all packages. If some package is missed, the command will not be executed.
For cloned repositories this command is a shorthand for: "${ i( 'mgit exec \'git pull\'' ) }".
For cloned repositories this command is a shorthand for: "${ i( 'mrgit exec \'git pull\'' ) }".
`;
},

Expand All @@ -32,7 +32,7 @@ module.exports = {
execute( data ) {
const execCommand = require( './exec' );

const destinationPath = path.join( data.mgitOptions.packages, data.repository.directory );
const destinationPath = path.join( data.toolOptions.packages, data.repository.directory );

// Package is not cloned.
if ( !fs.existsSync( destinationPath ) ) {
Expand Down
Loading

0 comments on commit 4a2a33f

Please sign in to comment.