Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add submodule commands #59

Open
dylancwood opened this issue Jun 20, 2014 · 4 comments · May be fixed by #61
Open

Add submodule commands #59

dylancwood opened this issue Jun 20, 2014 · 4 comments · May be fixed by #61

Comments

@dylancwood
Copy link
Collaborator

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:

  1. 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';
  1. 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 args array.
'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.';
@AoDev
Copy link
Contributor

AoDev commented Aug 16, 2014

Since you asked, I would love to see this feature :) it would help our build process greatly.

@dylancwood
Copy link
Collaborator Author

Great i will try to add these in soon

@AoDev
Copy link
Contributor

AoDev commented Aug 16, 2014

I saw your PR for git submodule update. I guess it's one of the most important. Thank you for your work :)

@krwillxyz
Copy link

a year later any word on this? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants