6

我正在编写一个电子应用程序,它必须每隔一段时间克隆和提取存储库,并且运行良好。但是,它在企业认证(基本或摘要)代理之后失败。据我了解,电子可以促进 Chromium 代理功能,但我正在使用的 git 库dugite正在主进程中运行,并尝试直接连接到 git 存储库。有什么方法可以将代理用于 dugite?

编辑:我做了一些额外的研究,发现节点不为你处理代理连接。代理设置只有在渲染器视图中被简化并且只有当它们使用浏览器窗口的方法(如 fetch)时才会被尊重。因此,我还尝试了isomorphic-git作为渲染器进程中的 dugite 替代品,但由于某些未知原因,它也不起作用。

接受的解决方案必须是可以在电子应用程序内部处理的代码。

4

1 回答 1

0

你可以传递HTTP_PROXYGitProcess.exec()

const options = {
  env: {
    'GIT_HTTP_USER_AGENT': 'dugite/2.12.0',
    'GIT_TRACE': '1',
    'GIT_CURL_VERBOSE': '1',
    'HTTP_PROXY': '[protocol://][user[:password]@]proxyhost[:port]'
  },
  processCallback: (process: ChildProcess) => {
    byline(process.stderr).on('data', (chunk: string) => {
      // read line from progress and convert to percentage
    })
  }
}

const result = await GitProcess.exec([ 'pull', 'origin' ], path, options)

或者,您可以git config http.proxy [protocol://][user[:password]@]proxyhost[:port]在您的存储库中执行,这将为存储库范围配置 http 代理(https://git-scm.com/docs/git-config#Documentation/git-config.txt-httpproxy

于 2020-08-08T11:53:45.400 回答