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

Problems with gitcommit for a repository in a sub-directory #79

Open
djmccormick opened this issue Oct 8, 2014 · 8 comments
Open

Problems with gitcommit for a repository in a sub-directory #79

djmccormick opened this issue Oct 8, 2014 · 8 comments

Comments

@djmccormick
Copy link

I'm attempting to use gitcommit against a repository in a sub-directory within my project. The cwd option doesn't seem to be working properly.

My gitcommit task looks like this:

gitcommit: {
    dist: {
        options: {
            expand: true,
            cwd: 'dist',
            message: 'v<%= pkg.version %>'
        },
        files: [{
            expand: true,
            cwd: 'dist',
            src: ['**/*']
        }]
    }
},

And when I run it, I get something like this:

Running "gitcommit:dist" (gitcommit) task
Warning: fatal: pathspec 'dist/about.html' did not match any files Use --force to continue.

Aborted due to warnings.

Or, with verbose mode:

Running "gitcommit:dist" (gitcommit) task
Verifying property gitcommit.dist exists in config...OK
Files: dist/whatsnew.html -> whatsnew.html
Options: message="v0.0.84", ignoreEmpty=false, noVerify=false, noStatus=false, expand, cwd="dist"
Options: verbose=false, expand, cwd="dist", message="v0.0.84"
Warning: fatal: pathspec 'dist/about.html' did not match any files Use --force to continue.

Aborted due to warnings.

It appears that the dist/ portion is still being included despite my cwd, given that the file is in the appropriate location:

djmccormick at computer in ~/Projects/some-category/some-project on some-branch
± ls dist/

about.html

Am I doing something incorrectly or is this a bug?

node v0.10.28
grunt-cli v0.1.13
grunt v0.4.4
grunt-git v0.2.14

@djmccormick
Copy link
Author

I've now tried the same with v0.3.0-alpha and got similar results with the gitadd task.

@Orphestrator
Copy link

Hi,

got the same problem. Any idea when it would be resolved?

regards

@dylancwood
Copy link
Collaborator

Thank you for bringing this up. I've traced the issue to lib/command_commit.js, which references each file's file.src property. This is an array, of what appear to be path names relative to the Grunt process' CWD (not relative to the cwd specified in the file options!). For instance, assume the following directory structure:

project/
    Gruntfile.js
    dist/
        foo.html

and the grunt files directive that you've supplied:

files: [{
    expand: true,
    cwd: 'dist',
    src: ['**/*']
}]

The resulting files array for the task will look like this:

[{ src: [ 'dist/foo.html' ],
  orig: { expand: true, src: [ '**/*' ] },
  dest: 'foo.html' }]

I would expect the src to be given relative to the file's cwd option, not relative to the Grunt process' CWD.

The solution may be to use the file's dest property instead of the src property.

I will continue investigating, and submit a fix when I'm confident in the solution.

@chasingmaxwell
Copy link

Has anyone found a workaround for this in the meantime?

@dylancwood
Copy link
Collaborator

This is because the grunt file API returns paths relative to the Gruntfile,
even if a cwd is specified. I am working on a solution.

Respectfully,
Dylan Wood
The Mind Research Network
Neuroinformatics
+1.505.480.5346
dwood@mrn.org

On Tue, Dec 16, 2014 at 10:53 PM, Peter Sieg notifications@github.com
wrote:

Has anyone found a workaround for this in the meantime?


Reply to this email directly or view it on GitHub
#79 (comment).

@chasingmaxwell
Copy link

@dylancwood thanks for your work on this!

I found a workaround yesterday that I will use until this is solved. For anyone needing an immediate workaround solution, you can use grunt.util.spawn to run git commands:

  grunt.registerTask('gitcommitworkaround', '', function() {
    var done, child;

    done = this.async();
    child = grunt.util.spawn({
      cmd: 'git',
      args: ['-C', 'the/path/to/your/subdirectory', 'commit', '-m', 'This is a commit message.'],
    }, function(err, result, code) {
      done();
    });

    child.stdout.pipe(process.stdout);
    child.stderr.pipe(process.stderr);
  });

@andobolocco
Copy link

any news on this issue? grunt is still giving us the cwd relative to the gruntfile?

@andobolocco
Copy link

I've found another possible workaroud, which is ugly too, this issue affects all grunt-git tasks, not just gitcommit:

var rootPath = process.cwd();

grunt.registerTask("cd", function(subpath) {

    var path = require('path');

    if(env === 'restore') {
        return grunt.file.setBase(rootPath);
    }

    return grunt.file.setBase(path.resolve('my/subdir/' + subpath));

});

grunt.registerTask("taskName", function(env) {

        grunt.task.run("cd:" + env);

        grunt.task.run("gitreset:" + env);
        grunt.task.run("gitpull:" + env);

        grunt.task.run("cd:restore");

        grunt.task.run("othertasks...");
});

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

No branches or pull requests

5 participants