我想通过 Node.js 做到这一点:
git archive remote=git@example.com:repo.git HEAD | tar -x - -C /path/to/extracted/
所以,我写了这样的代码:
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}"
然而,这并不像我预期的那样工作。我应该改变什么才能使其正常工作?
提前致谢。
更新
-
正确的命令实际上不需要-x
and-C
git archive remote=git@example.com:repo.git HEAD | tar -x -C /path/to/extracted/