feature: `Git.exe` 代理,支持排除自定义仓库地址,不进行代理 (#350)
parent
d359522250
commit
34a4a74de5
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,6 +26,26 @@
|
|||
</a-checkbox>
|
||||
安装Git时未选择使用系统证书管理服务时必须关闭
|
||||
</a-form-item>
|
||||
<a-form-item label="排除仓库地址" :label-col="labelCol" :wrapper-col="wrapperCol">
|
||||
<div>
|
||||
<a-row :gutter="10">
|
||||
<a-col :span="22">
|
||||
<span>Git.exe将不代理以下仓库;可以是站点地址、组/机构地址、单项目地址等</span>
|
||||
</a-col>
|
||||
<a-col :span="2">
|
||||
<a-button type="primary" icon="plus" @click="addNoProxyUrl()"/>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row :gutter="10" v-for="(item,index) of noProxyUrls" :key='index'>
|
||||
<a-col :span="22">
|
||||
<a-input :disabled="item.value === false" v-model="item.key"></a-input>
|
||||
</a-col>
|
||||
<a-col :span="2">
|
||||
<a-button type="danger" icon="minus" @click="delNoProxyUrl(item,index)"/>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</div>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</div>
|
||||
<template slot="footer">
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue