Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Git.exe 代理,支持排除自定义仓库地址,不进行代理 #350

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/core/src/modules/plugin/git/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
34 changes: 28 additions & 6 deletions packages/core/src/modules/plugin/git/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,48 @@ 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】代理成功')

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
Expand Down
63 changes: 62 additions & 1 deletion packages/gui/src/view/pages/plugin/git.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -46,7 +66,9 @@ export default {
mixins: [Plugin],
data () {
return {
key: 'plugin.git'
key: 'plugin.git',
noProxyUrls: [],
needRestart: false
}
},
created () {
Expand All @@ -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
}
}
}
Expand Down