Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
掘金者说
vscode
提交
f3d8873b
V
vscode
项目概览
掘金者说
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f3d8873b
编写于
2月 09, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git: cleanup command center
上级
81c028ea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
105 deletion
+76
-105
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+76
-105
未找到文件。
extensions/git/src/commands.ts
浏览文件 @
f3d8873b
...
...
@@ -74,59 +74,19 @@ class CheckoutRemoteHeadItem extends CheckoutItem {
}
}
export
class
CommandCenter
{
private
static
readonly
Commands
:
{
commandId
:
string
;
method
:
any
;
}[]
=
[];
private
static
Command
(
commandId
:
string
):
Function
{
return
(
target
:
any
,
key
:
string
,
descriptor
:
any
)
=>
{
if
(
!
(
typeof
descriptor
.
value
===
'
function
'
))
{
throw
new
Error
(
'
not supported
'
);
}
CommandCenter
.
Commands
.
push
({
commandId
,
method
:
descriptor
.
value
});
};
}
const
Commands
:
{
commandId
:
string
;
method
:
Function
;
}[]
=
[];
private
static
CatchErrors
(
target
:
any
,
key
:
string
,
descriptor
:
any
):
void
{
function
command
(
commandId
:
string
):
Function
{
return
(
target
:
any
,
key
:
string
,
descriptor
:
any
)
=>
{
if
(
!
(
typeof
descriptor
.
value
===
'
function
'
))
{
throw
new
Error
(
'
not supported
'
);
}
const
fn
=
descriptor
.
value
;
descriptor
.
value
=
function
(...
args
:
any
[])
{
fn
.
apply
(
this
,
args
).
catch
(
async
err
=>
{
let
message
:
string
;
switch
(
err
.
gitErrorCode
)
{
case
'
DirtyWorkTree
'
:
message
=
localize
(
'
clean repo
'
,
"
Please clean your repository working tree before checkout.
"
);
break
;
default
:
const
lines
=
(
err
.
stderr
||
err
.
message
||
String
(
err
))
.
replace
(
/^error: /
,
''
)
.
split
(
/
[\r\n]
/
)
.
filter
(
line
=>
!!
line
);
message
=
lines
[
0
]
||
'
Git error
'
;
break
;
}
if
(
!
message
)
{
console
.
error
(
err
);
return
;
}
const
outputChannel
=
this
.
outputChannel
as
OutputChannel
;
const
openOutputChannelChoice
=
localize
(
'
open git log
'
,
"
Open Git Log
"
);
const
choice
=
await
window
.
showErrorMessage
(
message
,
openOutputChannelChoice
);
Commands
.
push
({
commandId
,
method
:
descriptor
.
value
});
};
}
if
(
choice
===
openOutputChannelChoice
)
{
outputChannel
.
show
();
}
});
};
}
export
class
CommandCenter
{
private
model
:
Model
;
private
disposables
:
Disposable
[];
...
...
@@ -139,25 +99,16 @@ export class CommandCenter {
this
.
model
=
model
;
}
this
.
disposables
=
CommandCenter
.
Commands
.
map
(({
commandId
,
method
})
=>
commands
.
registerCommand
(
commandId
,
(...
args
)
=>
{
if
(
!
model
)
{
window
.
showInformationMessage
(
localize
(
'
disabled
'
,
"
Git is either disabled or not supported in this workspace
"
));
return
;
}
return
method
.
apply
(
this
,
args
);
}));
this
.
disposables
=
Commands
.
map
(({
commandId
,
method
})
=>
commands
.
registerCommand
(
commandId
,
this
.
createCommand
(
method
)));
}
@
CommandCenter
.
Command
(
'
git.refresh
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.refresh
'
)
async
refresh
():
Promise
<
void
>
{
await
this
.
model
.
status
();
}
@
CommandCenter
.
Command
(
'
git.openChange
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.openChange
'
)
async
openChange
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -239,8 +190,7 @@ export class CommandCenter {
return
''
;
}
@
CommandCenter
.
Command
(
'
git.openFile
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.openFile
'
)
async
openFile
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -251,8 +201,7 @@ export class CommandCenter {
return
commands
.
executeCommand
<
void
>
(
'
vscode.open
'
,
resource
.
uri
);
}
@
CommandCenter
.
Command
(
'
git.stage
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.stage
'
)
async
stage
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -263,14 +212,12 @@ export class CommandCenter {
return
await
this
.
model
.
stage
(
resource
);
}
@
CommandCenter
.
Command
(
'
git.stageAll
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.stageAll
'
)
async
stageAll
():
Promise
<
void
>
{
return
await
this
.
model
.
stage
();
}
@
CommandCenter
.
Command
(
'
git.unstage
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.unstage
'
)
async
unstage
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -281,14 +228,12 @@ export class CommandCenter {
return
await
this
.
model
.
unstage
(
resource
);
}
@
CommandCenter
.
Command
(
'
git.unstageAll
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.unstageAll
'
)
async
unstageAll
():
Promise
<
void
>
{
return
await
this
.
model
.
unstage
();
}
@
CommandCenter
.
Command
(
'
git.clean
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.clean
'
)
async
clean
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -308,8 +253,7 @@ export class CommandCenter {
await
this
.
model
.
clean
(
resource
);
}
@
CommandCenter
.
Command
(
'
git.cleanAll
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.cleanAll
'
)
async
cleanAll
():
Promise
<
void
>
{
const
message
=
localize
(
'
confirm clean all
'
,
"
Are you sure you want to clean all changes?
"
);
const
yes
=
localize
(
'
clean
'
,
"
Clean Changes
"
);
...
...
@@ -372,14 +316,12 @@ export class CommandCenter {
}
}
@
CommandCenter
.
Command
(
'
git.commit
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.commit
'
)
async
commit
():
Promise
<
void
>
{
await
this
.
commitWithAnyInput
();
}
@
CommandCenter
.
Command
(
'
git.commitWithInput
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.commitWithInput
'
)
async
commitWithInput
():
Promise
<
void
>
{
const
didCommit
=
await
this
.
smartCommit
(
async
()
=>
scm
.
inputBox
.
value
);
...
...
@@ -388,32 +330,27 @@ export class CommandCenter {
}
}
@
CommandCenter
.
Command
(
'
git.commitStaged
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.commitStaged
'
)
async
commitStaged
():
Promise
<
void
>
{
await
this
.
commitWithAnyInput
({
all
:
false
});
}
@
CommandCenter
.
Command
(
'
git.commitStagedSigned
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.commitStagedSigned
'
)
async
commitStagedSigned
():
Promise
<
void
>
{
await
this
.
commitWithAnyInput
({
all
:
false
,
signoff
:
true
});
}
@
CommandCenter
.
Command
(
'
git.commitAll
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.commitAll
'
)
async
commitAll
():
Promise
<
void
>
{
await
this
.
commitWithAnyInput
({
all
:
true
});
}
@
CommandCenter
.
Command
(
'
git.commitAllSigned
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.commitAllSigned
'
)
async
commitAllSigned
():
Promise
<
void
>
{
await
this
.
commitWithAnyInput
({
all
:
true
,
signoff
:
true
});
}
@
CommandCenter
.
Command
(
'
git.undoCommit
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.undoCommit
'
)
async
undoCommit
():
Promise
<
void
>
{
const
HEAD
=
this
.
model
.
HEAD
;
...
...
@@ -426,8 +363,7 @@ export class CommandCenter {
scm
.
inputBox
.
value
=
commit
.
message
;
}
@
CommandCenter
.
Command
(
'
git.checkout
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.checkout
'
)
async
checkout
():
Promise
<
void
>
{
const
config
=
workspace
.
getConfiguration
(
'
git
'
);
const
checkoutType
=
config
.
get
<
string
>
(
'
checkoutType
'
)
||
'
all
'
;
...
...
@@ -454,8 +390,7 @@ export class CommandCenter {
await
choice
.
run
(
this
.
model
);
}
@
CommandCenter
.
Command
(
'
git.branch
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.branch
'
)
async
branch
():
Promise
<
void
>
{
const
result
=
await
window
.
showInputBox
({
placeHolder
:
localize
(
'
branch name
'
,
"
Branch name
"
),
...
...
@@ -470,8 +405,7 @@ export class CommandCenter {
await
this
.
model
.
branch
(
name
);
}
@
CommandCenter
.
Command
(
'
git.pull
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.pull
'
)
async
pull
():
Promise
<
void
>
{
const
remotes
=
this
.
model
.
remotes
;
...
...
@@ -483,8 +417,7 @@ export class CommandCenter {
await
this
.
model
.
pull
();
}
@
CommandCenter
.
Command
(
'
git.pullRebase
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.pullRebase
'
)
async
pullRebase
():
Promise
<
void
>
{
const
remotes
=
this
.
model
.
remotes
;
...
...
@@ -496,8 +429,7 @@ export class CommandCenter {
await
this
.
model
.
pull
(
true
);
}
@
CommandCenter
.
Command
(
'
git.push
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.push
'
)
async
push
():
Promise
<
void
>
{
const
remotes
=
this
.
model
.
remotes
;
...
...
@@ -509,8 +441,7 @@ export class CommandCenter {
await
this
.
model
.
push
();
}
@
CommandCenter
.
Command
(
'
git.pushTo
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.pushTo
'
)
async
pushTo
():
Promise
<
void
>
{
const
remotes
=
this
.
model
.
remotes
;
...
...
@@ -536,8 +467,7 @@ export class CommandCenter {
this
.
model
.
push
(
pick
.
label
,
branchName
);
}
@
CommandCenter
.
Command
(
'
git.sync
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.sync
'
)
async
sync
():
Promise
<
void
>
{
const
HEAD
=
this
.
model
.
HEAD
;
...
...
@@ -564,8 +494,7 @@ export class CommandCenter {
await
this
.
model
.
sync
();
}
@
CommandCenter
.
Command
(
'
git.publish
'
)
@
CommandCenter
.
CatchErrors
@
command
(
'
git.publish
'
)
async
publish
():
Promise
<
void
>
{
const
remotes
=
this
.
model
.
remotes
;
...
...
@@ -586,11 +515,53 @@ export class CommandCenter {
await
this
.
model
.
push
(
choice
,
branchName
,
{
setUpstream
:
true
});
}
@
CommandCenter
.
C
ommand
(
'
git.showOutput
'
)
@
c
ommand
(
'
git.showOutput
'
)
showOutput
():
void
{
this
.
outputChannel
.
show
();
}
private
createCommand
(
method
:
Function
):
(...
args
:
any
[])
=>
any
{
return
(...
args
)
=>
{
if
(
!
this
.
model
)
{
window
.
showInformationMessage
(
localize
(
'
disabled
'
,
"
Git is either disabled or not supported in this workspace
"
));
return
;
}
const
result
=
Promise
.
resolve
(
method
.
apply
(
this
,
args
));
return
result
.
catch
(
async
err
=>
{
let
message
:
string
;
switch
(
err
.
gitErrorCode
)
{
case
'
DirtyWorkTree
'
:
message
=
localize
(
'
clean repo
'
,
"
Please clean your repository working tree before checkout.
"
);
break
;
default
:
const
lines
=
(
err
.
stderr
||
err
.
message
||
String
(
err
))
.
replace
(
/^error: /
,
''
)
.
split
(
/
[\r\n]
/
)
.
filter
(
line
=>
!!
line
);
message
=
lines
[
0
]
||
'
Git error
'
;
break
;
}
if
(
!
message
)
{
console
.
error
(
err
);
return
;
}
const
outputChannel
=
this
.
outputChannel
as
OutputChannel
;
const
openOutputChannelChoice
=
localize
(
'
open git log
'
,
"
Open Git Log
"
);
const
choice
=
await
window
.
showErrorMessage
(
message
,
openOutputChannelChoice
);
if
(
choice
===
openOutputChannelChoice
)
{
outputChannel
.
show
();
}
});
};
}
dispose
():
void
{
this
.
disposables
.
forEach
(
d
=>
d
.
dispose
());
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录