I would like to do this by Node.js:
git archive remote=git@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/
So, I wrote codes something like this:
git = spawn 'git', ['archive', "--remote=git@example.com:repo.git", 'HEAD']
tar = spawn 'tar', ['-x', '-', '-C /path/to/extracted']
git.stderr.on 'data', (data) ->
console.log "git error: #{data}"
git.stdout.on 'data', (data) ->
tar.stdin.write data
tar.stderr.on 'data', (data) ->
console.log "tar error: #{data}"
git.on 'exit', (code) ->
console.log "git process done with code #{code}"
tar.on 'exit', (code) ->
console.log "tar process done with code #{code}"
However this doesn't work as I expected. What should I change to make this work properly?
Thanks in advance.
UPDATE
Proper command actually doesn't need - between -x and -C
git archive remote=git@example.com:repo.git HEAD | tar -x -C /path/to/extracted/
You should use the function exec and not spawn in that case. As seen in the exec documenation it accepts pipes exec documentation
exec('git archive remote=git@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/', function (error, stdout, stderr) {
// logic here
}