Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1ab31376
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1ab31376
编写于
7月 15, 2020
作者:
J
João Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git: PushErrorHandler
上级
8b531a22
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
72 addition
and
8 deletion
+72
-8
extensions/git/src/api/api1.ts
extensions/git/src/api/api1.ts
+5
-1
extensions/git/src/api/git.d.ts
extensions/git/src/api/git.d.ts
+6
-0
extensions/git/src/git.ts
extensions/git/src/git.ts
+2
-0
extensions/git/src/model.ts
extensions/git/src/model.ts
+15
-3
extensions/git/src/pushError.ts
extensions/git/src/pushError.ts
+12
-0
extensions/git/src/repository.ts
extensions/git/src/repository.ts
+32
-4
未找到文件。
extensions/git/src/api/api1.ts
浏览文件 @
1ab31376
...
...
@@ -5,7 +5,7 @@
import
{
Model
}
from
'
../model
'
;
import
{
Repository
as
BaseRepository
,
Resource
}
from
'
../repository
'
;
import
{
InputBox
,
Git
,
API
,
Repository
,
Remote
,
RepositoryState
,
Branch
,
Ref
,
Submodule
,
Commit
,
Change
,
RepositoryUIState
,
Status
,
LogOptions
,
APIState
,
CommitOptions
,
RefType
,
RemoteSourceProvider
,
CredentialsProvider
,
BranchQuery
}
from
'
./git
'
;
import
{
InputBox
,
Git
,
API
,
Repository
,
Remote
,
RepositoryState
,
Branch
,
Ref
,
Submodule
,
Commit
,
Change
,
RepositoryUIState
,
Status
,
LogOptions
,
APIState
,
CommitOptions
,
RefType
,
RemoteSourceProvider
,
CredentialsProvider
,
BranchQuery
,
PushErrorHandler
}
from
'
./git
'
;
import
{
Event
,
SourceControlInputBox
,
Uri
,
SourceControl
,
Disposable
,
commands
}
from
'
vscode
'
;
import
{
mapEvent
}
from
'
../util
'
;
import
{
toGitUri
}
from
'
../uri
'
;
...
...
@@ -273,6 +273,10 @@ export class ApiImpl implements API {
return
this
.
_model
.
registerCredentialsProvider
(
provider
);
}
registerPushErrorHandler
(
handler
:
PushErrorHandler
):
Disposable
{
return
this
.
_model
.
registerPushErrorHandler
(
handler
);
}
constructor
(
private
_model
:
Model
)
{
}
}
...
...
extensions/git/src/api/git.d.ts
浏览文件 @
1ab31376
...
...
@@ -223,6 +223,10 @@ export interface CredentialsProvider {
getCredentials
(
host
:
Uri
):
ProviderResult
<
Credentials
>
;
}
export
interface
PushErrorHandler
{
handlePushError
(
repository
:
Repository
,
remote
:
Remote
,
refspec
:
string
,
error
:
Error
&
{
gitErrorCode
:
GitErrorCodes
}):
Promise
<
boolean
>
;
}
export
type
APIState
=
'
uninitialized
'
|
'
initialized
'
;
export
interface
API
{
...
...
@@ -239,6 +243,7 @@ export interface API {
registerRemoteSourceProvider
(
provider
:
RemoteSourceProvider
):
Disposable
;
registerCredentialsProvider
(
provider
:
CredentialsProvider
):
Disposable
;
registerPushErrorHandler
(
handler
:
PushErrorHandler
):
Disposable
;
}
export
interface
GitExtension
{
...
...
@@ -276,6 +281,7 @@ export const enum GitErrorCodes {
CantOpenResource
=
'
CantOpenResource
'
,
GitNotFound
=
'
GitNotFound
'
,
CantCreatePipe
=
'
CantCreatePipe
'
,
PermissionDenied
=
'
PermissionDenied
'
,
CantAccessRemote
=
'
CantAccessRemote
'
,
RepositoryNotFound
=
'
RepositoryNotFound
'
,
RepositoryIsLocked
=
'
RepositoryIsLocked
'
,
...
...
extensions/git/src/git.ts
浏览文件 @
1ab31376
...
...
@@ -1627,6 +1627,8 @@ export class Repository {
err.gitErrorCode = GitErrorCodes.RemoteConnectionError;
} else if (/^fatal: The current branch .* has no upstream branch/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.NoUpstreamBranch;
} else if (/Permission.*denied/.test(err.stderr || '')) {
err.gitErrorCode = GitErrorCodes.PermissionDenied;
}
throw err;
...
...
extensions/git/src/model.ts
浏览文件 @
1ab31376
...
...
@@ -12,9 +12,10 @@ import * as path from 'path';
import
*
as
fs
from
'
fs
'
;
import
*
as
nls
from
'
vscode-nls
'
;
import
{
fromGitUri
}
from
'
./uri
'
;
import
{
APIState
as
State
,
RemoteSourceProvider
,
CredentialsProvider
}
from
'
./api/git
'
;
import
{
APIState
as
State
,
RemoteSourceProvider
,
CredentialsProvider
,
PushErrorHandler
}
from
'
./api/git
'
;
import
{
Askpass
}
from
'
./askpass
'
;
import
{
IRemoteSourceProviderRegistry
}
from
'
./remoteProvider
'
;
import
{
IPushErrorHandlerRegistry
}
from
'
./pushError
'
;
const
localize
=
nls
.
loadMessageBundle
();
...
...
@@ -46,7 +47,7 @@ interface OpenRepository extends Disposable {
repository
:
Repository
;
}
export
class
Model
implements
IRemoteSourceProviderRegistry
{
export
class
Model
implements
IRemoteSourceProviderRegistry
,
IPushErrorHandlerRegistry
{
private
_onDidOpenRepository
=
new
EventEmitter
<
Repository
>
();
readonly
onDidOpenRepository
:
Event
<
Repository
>
=
this
.
_onDidOpenRepository
.
event
;
...
...
@@ -94,6 +95,8 @@ export class Model implements IRemoteSourceProviderRegistry {
private
_onDidRemoveRemoteSourceProvider
=
new
EventEmitter
<
RemoteSourceProvider
>
();
readonly
onDidRemoveRemoteSourceProvider
=
this
.
_onDidRemoveRemoteSourceProvider
.
event
;
private
pushErrorHandlers
=
new
Set
<
PushErrorHandler
>
();
private
disposables
:
Disposable
[]
=
[];
constructor
(
readonly
git
:
Git
,
private
readonly
askpass
:
Askpass
,
private
globalState
:
Memento
,
private
outputChannel
:
OutputChannel
)
{
...
...
@@ -269,7 +272,7 @@ export class Model implements IRemoteSourceProviderRegistry {
}
const
dotGit
=
await
this
.
git
.
getRepositoryDotGit
(
repositoryRoot
);
const
repository
=
new
Repository
(
this
.
git
.
open
(
repositoryRoot
,
dotGit
),
this
,
this
.
globalState
,
this
.
outputChannel
);
const
repository
=
new
Repository
(
this
.
git
.
open
(
repositoryRoot
,
dotGit
),
this
,
this
,
this
.
globalState
,
this
.
outputChannel
);
this
.
open
(
repository
);
await
repository
.
status
();
...
...
@@ -485,6 +488,15 @@ export class Model implements IRemoteSourceProviderRegistry {
return
[...
this
.
remoteSourceProviders
.
values
()];
}
registerPushErrorHandler
(
handler
:
PushErrorHandler
):
Disposable
{
this
.
pushErrorHandlers
.
add
(
handler
);
return
toDisposable
(()
=>
this
.
pushErrorHandlers
.
delete
(
handler
));
}
getPushErrorHandlers
():
PushErrorHandler
[]
{
return
[...
this
.
pushErrorHandlers
];
}
dispose
():
void
{
const
openRepositories
=
[...
this
.
openRepositories
];
openRepositories
.
forEach
(
r
=>
r
.
dispose
());
...
...
extensions/git/src/pushError.ts
0 → 100644
浏览文件 @
1ab31376
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import
{
Disposable
}
from
'
vscode
'
;
import
{
PushErrorHandler
}
from
'
./api/git
'
;
export
interface
IPushErrorHandlerRegistry
{
registerPushErrorHandler
(
provider
:
PushErrorHandler
):
Disposable
;
getPushErrorHandlers
():
PushErrorHandler
[];
}
extensions/git/src/repository.ts
浏览文件 @
1ab31376
...
...
@@ -17,6 +17,8 @@ import { anyEvent, combinedDisposable, debounceEvent, dispose, EmptyDisposable,
import
{
IFileWatcher
,
watch
}
from
'
./watch
'
;
import
{
Log
,
LogLevel
}
from
'
./log
'
;
import
{
IRemoteSourceProviderRegistry
}
from
'
./remoteProvider
'
;
import
{
IPushErrorHandlerRegistry
}
from
'
./pushError
'
;
import
{
ApiRepository
}
from
'
./api/api1
'
;
const
timeout
=
(
millis
:
number
)
=>
new
Promise
(
c
=>
setTimeout
(
c
,
millis
));
...
...
@@ -683,6 +685,7 @@ export class Repository implements Disposable {
constructor
(
private
readonly
repository
:
BaseRepository
,
remoteSourceProviderRegistry
:
IRemoteSourceProviderRegistry
,
private
pushErrorHandlerRegistry
:
IPushErrorHandlerRegistry
,
globalState
:
Memento
,
outputChannel
:
OutputChannel
)
{
...
...
@@ -1181,15 +1184,15 @@ export class Repository implements Disposable {
branch
=
`
${
head
.
name
}
:
${
head
.
upstream
.
name
}
`
;
}
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
branch
,
undefined
,
undefined
,
forcePushMode
));
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
_
push
(
remote
,
branch
,
undefined
,
undefined
,
forcePushMode
));
}
async
pushTo
(
remote
?:
string
,
name
?:
string
,
setUpstream
:
boolean
=
false
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
name
,
setUpstream
,
undefined
,
forcePushMode
));
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
_
push
(
remote
,
name
,
setUpstream
,
undefined
,
forcePushMode
));
}
async
pushFollowTags
(
remote
?:
string
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
undefined
,
false
,
true
,
forcePushMode
));
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
_
push
(
remote
,
undefined
,
false
,
true
,
forcePushMode
));
}
async
blame
(
path
:
string
):
Promise
<
string
>
{
...
...
@@ -1249,7 +1252,7 @@ export class Repository implements Disposable {
const
shouldPush
=
this
.
HEAD
&&
(
typeof
this
.
HEAD
.
ahead
===
'
number
'
?
this
.
HEAD
.
ahead
>
0
:
true
);
if
(
shouldPush
)
{
await
this
.
repository
.
push
(
remoteName
,
pushBranch
);
await
this
.
_
push
(
remoteName
,
pushBranch
);
}
});
});
...
...
@@ -1411,6 +1414,31 @@ export class Repository implements Disposable {
return
ignored
;
}
private
async
_push
(
remote
?:
string
,
refspec
?:
string
,
setUpstream
:
boolean
=
false
,
tags
=
false
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
try
{
await
this
.
repository
.
push
(
remote
,
refspec
,
setUpstream
,
tags
,
forcePushMode
);
}
catch
(
err
)
{
if
(
!
remote
||
!
refspec
)
{
throw
err
;
}
const
repository
=
new
ApiRepository
(
this
);
const
remoteObj
=
repository
.
state
.
remotes
.
find
(
r
=>
r
.
name
===
remote
);
if
(
!
remoteObj
)
{
throw
err
;
}
for
(
const
handler
of
this
.
pushErrorHandlerRegistry
.
getPushErrorHandlers
())
{
if
(
await
handler
.
handlePushError
(
repository
,
remoteObj
,
refspec
,
err
))
{
return
;
}
}
throw
err
;
}
}
private
async
run
<
T
>
(
operation
:
Operation
,
runOperation
:
()
=>
Promise
<
T
>
=
()
=>
Promise
.
resolve
<
any
>
(
null
)):
Promise
<
T
>
{
if
(
this
.
state
!==
RepositoryState
.
Idle
)
{
throw
new
Error
(
'
Repository not initialized
'
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录