var exec = require('exec');
exec('cd folderName', function(){
exec('git diff --name-only', function(err, stdout, stderr){
if(err) throw err;
console.log(stdout);
});
これではうまくいかなかったので調べてみたところ。
Each command is executed in a separate shell, so the first cd only affects that shell process which then terminates.
ということで、どうやら異なるシェルとして動いているためうまくいかないようです。
var exec = require('exec');
exec('git diff --name-only', {cwd: './folderName'}, function(err, stdout, stderr){
if(err) throw err;
console.log(stdout);
});
このように書くとうまくいきました。