diff --git a/packages/core/src/modules/plugin/git/config.js b/packages/core/src/modules/plugin/git/config.js
index 8850668..1decf9a 100644
--- a/packages/core/src/modules/plugin/git/config.js
+++ b/packages/core/src/modules/plugin/git/config.js
@@ -3,6 +3,10 @@ module.exports = {
enabled: false,
tip: '如果你没有安装git命令行则不需要启动它',
setting: {
- sslVerify: true // Git.exe 是否关闭sslVerify,true=关闭 false=开启
+ sslVerify: true, // Git.exe 是否关闭sslVerify,true=关闭 false=开启
+ noProxyUrls: {
+ 'https://gitee.com/': true,
+ 'https://e.coding.net/': true
+ }
}
}
diff --git a/packages/core/src/modules/plugin/git/index.js b/packages/core/src/modules/plugin/git/index.js
index 4794ad3..d72c338 100644
--- a/packages/core/src/modules/plugin/git/index.js
+++ b/packages/core/src/modules/plugin/git/index.js
@@ -27,10 +27,17 @@ const Plugin = function (context) {
`git config --global http.proxy http://${ip}:${port} `,
`git config --global https.proxy http://${ip}:${port} `
]
+
if (config.get().plugin.git.setting.sslVerify === true) {
cmds.push('git config --global http.sslVerify false ')
}
+ if (config.get().plugin.git.setting.noProxyUrls != null) {
+ for (const url in config.get().plugin.git.setting.noProxyUrls) {
+ cmds.push(`git config --global http."${url}".proxy "" `)
+ }
+ }
+
const ret = await shell.exec(cmds, { type: 'cmd' })
event.fire('status', { key: 'plugin.git.enabled', value: true })
log.info('开启【Git】代理成功')
@@ -38,15 +45,30 @@ const Plugin = function (context) {
return ret
},
+ // 当手动修改过 `~/.gitconfig` 时,`unset` 可能会执行失败,所以除了第一条命令外,其他命令都添加了try-catch,防止关闭Git代理失败
async unsetProxy () {
- const cmds = [
- 'git config --global --unset https.proxy ',
- 'git config --global --unset http.proxy '
- ]
- if (config.get().plugin.git.setting.sslVerify === true) {
- cmds.push('git config --global http.sslVerify true ')
+ const ret = await shell.exec(['git config --global --unset http.proxy '], { type: 'cmd' })
+
+ try {
+ await shell.exec(['git config --global --unset https.proxy '], { type: 'cmd' })
+ } catch (ignore) {
+ }
+
+ if (config.get().plugin.git.setting.sslVerify === true) {
+ try {
+ await shell.exec(['git config --global --unset http.sslVerify '], { type: 'cmd' })
+ } catch (ignore) {
+ }
+ }
+
+ if (config.get().plugin.git.setting.noProxyUrls != null) {
+ for (const url in config.get().plugin.git.setting.noProxyUrls) {
+ try {
+ await shell.exec([`git config --global --unset http."${url}".proxy `], { type: 'cmd' })
+ } catch (ignore) {
+ }
+ }
}
- const ret = await shell.exec(cmds, { type: 'cmd' })
event.fire('status', { key: 'plugin.git.enabled', value: false })
log.info('关闭【Git】代理成功')
return ret
diff --git a/packages/gui/src/view/pages/plugin/git.vue b/packages/gui/src/view/pages/plugin/git.vue
index e3f9552..6949beb 100644
--- a/packages/gui/src/view/pages/plugin/git.vue
+++ b/packages/gui/src/view/pages/plugin/git.vue
@@ -26,6 +26,26 @@
安装Git时未选择使用系统证书管理服务时必须关闭
+
+
+
+
+ Git.exe将不代理以下仓库;可以是站点地址、组/机构地址、单项目地址等
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -46,7 +66,9 @@ export default {
mixins: [Plugin],
data () {
return {
- key: 'plugin.git'
+ key: 'plugin.git',
+ noProxyUrls: [],
+ needRestart: false
}
},
created () {
@@ -56,6 +78,45 @@ export default {
},
methods: {
ready () {
+ this.initNoProxyUrls()
+ },
+ async applyBefore () {
+ if (this.status.plugin.git.enabled) {
+ await this.$api.plugin.git.close()
+ this.needRestart = true
+ } else {
+ this.needRestart = false
+ }
+ this.submitNoProxyUrls()
+ },
+ async applyAfter () {
+ if (this.needRestart) {
+ await this.$api.plugin.git.start()
+ }
+ },
+ initNoProxyUrls () {
+ this.noProxyUrls = []
+ for (const key in this.config.plugin.git.setting.noProxyUrls) {
+ const value = this.config.plugin.git.setting.noProxyUrls[key]
+ this.noProxyUrls.push({
+ key, value
+ })
+ }
+ },
+ addNoProxyUrl () {
+ this.noProxyUrls.unshift({ key: '', value: true })
+ },
+ delNoProxyUrl (item, index) {
+ this.noProxyUrls.splice(index, 1)
+ },
+ submitNoProxyUrls () {
+ const noProxyUrls = {}
+ for (const item of this.noProxyUrls) {
+ if (item.key) {
+ noProxyUrls[item.key] = item.value
+ }
+ }
+ this.config.plugin.git.setting.noProxyUrls = noProxyUrls
}
}
}