From 34a4a74de59a038ec53608acbb99051b7966edae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E8=89=AF?= <841369634@qq.com>
Date: Wed, 11 Sep 2024 05:41:25 +0800
Subject: [PATCH] =?UTF-8?q?feature:=20`Git.exe`=20=E4=BB=A3=E7=90=86?=
=?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E6=8E=92=E9=99=A4=E8=87=AA=E5=AE=9A?=
=?UTF-8?q?=E4=B9=89=E4=BB=93=E5=BA=93=E5=9C=B0=E5=9D=80=EF=BC=8C=E4=B8=8D?=
=?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=BB=A3=E7=90=86=20(#350)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../core/src/modules/plugin/git/config.js | 6 +-
packages/core/src/modules/plugin/git/index.js | 34 ++++++++--
packages/gui/src/view/pages/plugin/git.vue | 63 ++++++++++++++++++-
3 files changed, 95 insertions(+), 8 deletions(-)
diff --git a/packages/core/src/modules/plugin/git/config.js b/packages/core/src/modules/plugin/git/config.js
index 88506681e..1decf9a16 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 4794ad3de..d72c3384c 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 '
- ]
+ 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) {
- cmds.push('git config --global http.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 e3f9552ff..6949beb8d 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
}
}
}