grunt-git icon indicating copy to clipboard operation
grunt-git copied to clipboard

Create new submodule update target to run git submodule update

Open dylancwood opened this issue 10 years ago • 8 comments

Resolves #59 at least partially. I have no need for the other submodule commands, but can start adding them if you would like.

My current project needed to perform submodule updates during the build process, so I added this functionality into grunt-git. I tried to maintain the current style, but did do one thing very differently: Instead of pushing options onto the args array individually, I do so in a loop that loops through an array of acceptableOptions. This way, only options that we are expecting will be passed to the child process, and those that might cause an error (e.g. verbose) will not be.

I'm happy to convert it to the more explicit method used elsewhere in this repo if you would prefer.

All CLI flags for git-submodule-update are supported by this patch, though I suspect that most folks will only use init and recursive.

I've also updated the README to include documentation for the new task, and added tests for each option.

dylancwood avatar Jun 22 '14 04:06 dylancwood

Sorry for all the commits and comments. Here's a concise account:

  1. No need for hasOwnProperty. Fixed
  2. Add string conversion of camelCase options to dash-separated arguments inside of argument generation loop. I elected to use the underscore.string library for this, but am willing to build a separate lib/util.js library if you prefer.
  3. The standard variable name for the underscore.string library is _s, but that name breaks the jshint test, so I am calling it stringUtil.
  4. I modified filtering of options so that options with a value === 0 will be allowed to become args.

Note: I spot-checked a few of the other tasks for options that cannot be converted to CLI flags using underscore's dasherize(). The option noff in gitmerge will not work with the camelCase conversion, since it needs to be converted to --no-ff. There may be others as well.

dylancwood avatar Jun 23 '14 18:06 dylancwood

Bump. Just checking in on this: no pressure, but wanted to make sure that you weren't waiting on me.

dylancwood avatar Jun 26 '14 20:06 dylancwood

Haven't had time to look into this, but it's on my list! Apologies! On Jun 26, 2014 10:47 PM, "Dylan Wood" [email protected] wrote:

Bump. Just checking in on this: no pressure, but wanted to make sure that you weren't waiting on me.

— Reply to this email directly or view it on GitHub https://github.com/rubenv/grunt-git/pull/61#issuecomment-47277915.

rubenv avatar Jun 27 '14 06:06 rubenv

No problem. Thanks for the update.

dylancwood avatar Jun 27 '14 15:06 dylancwood

I elected to use the underscore.string library for this, but am willing to build a separate lib/util.js library if you prefer.

Nah, just leave it, it's a small dependency anyway.

rubenv avatar Jun 30 '14 08:06 rubenv

As it stands, I see no reason not to merge this. Do you reckon we could do the same for other commands?

Note that I'm trying to map tasks to commands 1:1 (see #44). I'm planning to break compatibility in the next minor version to allow that. So don't worry about breaking existing things, there's currently a bugfix 0.2 branch and master holds the future.

rubenv avatar Jun 30 '14 08:06 rubenv

Sounds good. I will apply the same logic to the other tasks, and will look for any task or property names that do not match exactly with the git CLI API. This is going to be a busy week for me, so I expect to tackle this next week.

My plan for the moment is to modify tasks/git.js and add a method for converting options to arguments called optsToArgs(options, optionsForGit, optionsWithoutFlags) that takes the current tasks options, and an array of the options that should be converted and passed to the child process as CLI arguments. It will return an array of dash-separated strings.

Here's a rough implementation:

optsToArgs(options, optionsForGit, optionsWithoutFlags) {
    var args = [];
    // Add 
    for (optionKey in optionsForGit) {
        if (options[optionKey] || options[optionKey] === 0 ) { \\allow numeric zero to pass through        
            // Add flag
            args.push('--' + stringUtil.dasherize(optionKey));                                                         
            // If not a boolean, add the value after the flag                                                          
            if (typeof options[optionKey] !== 'boolean') {                                                             
                args.push(options[optionKey]);
            }
        }       
    }
    // Add arguments that do not have flags (e.g. *repository* arg in git clone)
    for (optionKey in optionsWithoutFlags) {
        if (options[optionKey] || options[optionKey] === 0 ) { \\allow numeric zero to pass through        
            // Add value                                      
            args.push(options[optionKey]);
        }
    }        
    return args;
}

I might come up with a cleaner implementation before I get started though.

dylancwood avatar Jun 30 '14 19:06 dylancwood

It would be nice to have support for the git submodule update command via grunt-git. I've merged this branch into my own fork of grunt-git and combined it with some other needed commands and it's been working great.

gabema avatar Sep 21 '15 22:09 gabema