0

I need to put a git log into a file. The command line works fine

Git log command line result

But if I call this command with a grunt task using shelljs.exec, I dont get any output

Git log with grunt task using shelljs.exec

Here the grunt code :

/*global module:false,require,console*/
'use strict';

var shell = require('shelljs');


module.exports = function (grunt) {

    // Project configuration.
    grunt.initConfig({
        // Task configuration.
    });

    grunt.task.registerTask('git-log', 'git log output', function () {
        console.log('RESULT : ', shell.exec('git log HEAD...HEAD^ --oneline',{silent : true}).output);
    });

    // Default task.
    grunt.registerTask('default', ['git-log']);

};

I checked all the shelljs docs and tried different ways (including async) with no success...

Any idea ? Thx

7
  • Could you try this and post the result ? grunt.log.writeln( JSON.stringify( shell.exec('git log HEAD...HEAD^ --oneline', {silent : true}), null, 2 ) ); Commented Jan 28, 2016 at 13:30
  • Running "git-log" task {"code": 0, "output": "" } Done, without errors. Process finished with exit code 0 Commented Jan 28, 2016 at 14:05
  • It seems there is not output when the command succeeds (code = 0). I'm going to check something then I'll get back to you. Commented Jan 28, 2016 at 14:08
  • Do you have to use shelljs absolutely ? Because this module github.com/juliangruber/git-log may be a solution. Commented Jan 28, 2016 at 14:14
  • Yes, I need to append the log result into a file (Im using file-creator task) with another input Commented Jan 28, 2016 at 14:33

1 Answer 1

1

Try to use .stdout instead of .output.

In your code:

shell.exec(
  'git log HEAD...HEAD^ --oneline',
  {silent : true}
).output;

Change to:

shell.exec(
  'git log HEAD...HEAD^ --oneline',
  {silent : true}
).stdout;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.