node.js - 无法通过 Node child_process.spawn 调用 `git submodule add`

标签 node.js git child-process

我想做的就是通过 Node 执行cmd git submodule -q add -f --depth 1 https://github.com/user/repo node_modules/repo,但是我似乎无法让它工作。

var cmd = [
  'git',
  [
    'submodule',
    '--quiet',
    'add',
    '--force',
    '--depth', '1',
    (self.url.replace('git+', '')),
    self.installTo
  ]
]

var git = spawn.apply(spawn, cmd)

git.stderr.on('data', log.error)
git.on('close', function (code, signal) {
  // irrelevant because it errors out...
}

我在终端中收到以下错误:

ERR! usage: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
or: git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: git submodule [--quiet] init [--] [<path>...]
or: git submodule [--quiet] deinit [-f|--force] [--] <path>...
or: git submodule [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
or: git submodule [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: git submodule [--quiet] foreach [--recursive] <command>
or: git submodule [--quiet] sync [--recursive] [--] [<path>...]

最佳答案

使用消息未提及--深度。

这意味着使用的 git 版本不够新,无法包含该选项。
它必须是 1.8.4(2013 年 8 月)之前的 git:该选项是由 commit 275cd18 添加的通过 Fredrik Gustafsson (iveqy)

关于node.js - 无法通过 Node child_process.spawn 调用 `git submodule add`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33006849/

相关文章:

Git 将单个提交从 feature_branch 移​​动到 master

git - "git log -1"有什么作用?

node.js - 在 Node.JS 中从自身内部杀死一个子进程

javascript - 如何在node.js中获取实时生成的childProcess.stdout

javascript - NodeJS - Passport 本地策略给了我 404

node.js - 在 node-sass@4.7.2 安装后脚本失败

javascript - Helenus 无法连接

javascript - 无法通过 bash 使用 phantomjs 打开 javascript 文件

python-2.7 - 处理由 Python 代码产生的 C++ 子进程引起的段错误

OSX 上的 Git 将符号链接(symbolic link)克隆为纯文本文件