-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Description
How would you feel about adding submodule commands to this project?
The complete list of submodule commands can be found here: http://git-scm.com/docs/git-submodule
I would like to do the work, but do not want to go to the effort if it is not desired. Please tell me whether you would like submodule commands to be integrated, or if you would prefer me to create a separate repo.
I see two possible options for integrating submodule commands:
- create a single submodule task to perform all submodule commands. I've started down this road, but am not sure that it is a maintainable or testable approach. Here is an example command_submodule.js scriptl:
'use strict';
var async = require('grunt').util.async;
var grunt = require('grunt');
module.exports = function (task, exec, done) {
var errorMsg = '';
var options = task.options({
subcommand: null,
force: null,
repository: null, //only for add or update subcommand
branch: null, //only for add subcommand
path: null, //not for foreach subcommand
init: null, //for update subcommand
recursive: null, //only for update subcommand
//...
});
var knownSubcommands = [
'add',
'status',
'init',
'deinit',
'upgrade',
'summary',
//'foreach', //Doesn't really make sense in this context IMO
'sync'
]
var args = ['submodule'];
if (!options.subcommand) {
errorMsg = 'Cannot invoke submodule command without a sub-command';
throw new Error(errorMsg);
} else if (knownSubcommands.indexOf(options.subcommand) === -1) {
errorMsg = 'Unknown subcommand: "' + options.subcommand + '". '
errorMsg += 'Possible subcommands are: ' + knownSubcommands.join(', ');
throw new Error(errorMsg);
} else {
args.push(options.subcommand);
}
//TODO: loop through other options, or simply assign them in a loop?
if (options.branch) {
args.push(options.branch);
}
// Add callback
args.push(done);
exec.apply(this, args);
};
module.exports.description = 'Execute submodule command';- An alternative approach would be to create tasks for each submodule command. Here's an example command_submodule_update.js file. I'm also curious what you think of the use of a loop to assign cli flags to the
argsarray.
'use strict';
var async = require('grunt').util.async;
var grunt = require('grunt');
module.exports = function (task, exec, done) {
var optionKey;
var options = task.options({
init: false,
remote: false,
noFetch: false,
force: false,
rebase: false,
merge: false,
reference: null,
depth: null,
recursive: false,
path: null
});
var spawnOptions = ['cwd', 'verbose'];
var args = ['submodule', 'update'];
// options.path is not a cli flag, instead, the value is added
var path = options.path
// unset options.path so that it does not get interpreted below
options.path = null;
// loop through cli flags in options and add to args
for (optionKey in options) {
if (options.hasOwnProperty(optionKey) && options[optionKey] && spawnOptions.indexOf(optionKey) === -1) {
// add flag
args.push('--' + optionKey);
// if not a boolean, add the value after the flag
if (typeof options[optionKey] !== 'boolean') {
args.push(options[optionKey]);
}
}
}
// Add callback
args.push(done);
exec.apply(this, args);
};
module.exports.description = 'Update git submodules.';Metadata
Metadata
Assignees
Labels
No labels