Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
2184638d
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,发现更多精彩内容 >>
提交
2184638d
编写于
1月 12, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git: pimp up CommandCenter
上级
bd8a10e4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
57 deletion
+79
-57
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+79
-57
未找到文件。
extensions/git/src/commands.ts
浏览文件 @
2184638d
...
...
@@ -8,36 +8,8 @@
import
{
Uri
,
commands
,
scm
,
Disposable
,
SCMResourceGroup
,
SCMResource
,
window
,
workspace
,
QuickPickItem
,
OutputChannel
}
from
'
vscode
'
;
import
{
IRef
,
RefType
}
from
'
./git
'
;
import
{
Model
,
Resource
,
Status
}
from
'
./model
'
;
import
{
decorate
}
from
'
core-decorators
'
;
import
*
as
path
from
'
path
'
;
function
catchErrors
(
fn
:
(...
args
)
=>
Promise
<
any
>
):
(...
args
)
=>
void
{
return
(...
args
)
=>
fn
.
call
(
this
,
...
args
).
catch
(
async
err
=>
{
if
(
err
.
gitErrorCode
)
{
let
message
:
string
;
switch
(
err
.
gitErrorCode
)
{
case
'
DirtyWorkTree
'
:
message
=
'
Please clean your repository working tree before checkout.
'
;
break
;
default
:
message
=
(
err
.
stderr
||
err
.
message
).
replace
(
/^error: /
,
''
);
break
;
}
const
outputChannel
=
this
.
outputChannel
as
OutputChannel
;
const
openOutputChannelChoice
=
'
Open Git Log
'
;
const
choice
=
await
window
.
showErrorMessage
(
message
,
openOutputChannelChoice
);
if
(
choice
===
openOutputChannelChoice
)
{
outputChannel
.
show
();
}
}
else
{
console
.
error
(
err
);
}
});
}
function
resolveGitURI
(
uri
:
Uri
):
SCMResource
|
SCMResourceGroup
|
undefined
{
if
(
uri
.
authority
!==
'
git
'
)
{
return
;
...
...
@@ -97,32 +69,71 @@ class CheckoutRemoteHeadItem extends CheckoutItem {
export
class
CommandCenter
{
private
disposables
:
Disposable
[]
=
[];
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
});
};
}
private
static
CatchErrors
(
target
:
any
,
key
:
string
,
descriptor
:
any
):
void
{
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
=>
{
if
(
err
.
gitErrorCode
)
{
let
message
:
string
;
switch
(
err
.
gitErrorCode
)
{
case
'
DirtyWorkTree
'
:
message
=
'
Please clean your repository working tree before checkout.
'
;
break
;
default
:
message
=
(
err
.
stderr
||
err
.
message
).
replace
(
/^error: /
,
''
);
break
;
}
const
outputChannel
=
this
.
outputChannel
as
OutputChannel
;
const
openOutputChannelChoice
=
'
Open Git Log
'
;
const
choice
=
await
window
.
showErrorMessage
(
message
,
openOutputChannelChoice
);
if
(
choice
===
openOutputChannelChoice
)
{
outputChannel
.
show
();
}
}
else
if
(
err
.
message
)
{
window
.
showErrorMessage
(
err
.
message
);
console
.
error
(
err
);
}
else
{
console
.
error
(
err
);
}
});
};
}
private
disposables
:
Disposable
[];
constructor
(
private
model
:
Model
,
private
outputChannel
:
OutputChannel
)
{
this
.
disposables
.
push
(
commands
.
registerCommand
(
'
git.refresh
'
,
this
.
refresh
,
this
),
commands
.
registerCommand
(
'
git.openChange
'
,
this
.
openChange
,
this
),
commands
.
registerCommand
(
'
git.openFile
'
,
this
.
openFile
,
this
),
commands
.
registerCommand
(
'
git.stage
'
,
this
.
stage
,
this
),
commands
.
registerCommand
(
'
git.stageAll
'
,
this
.
stageAll
,
this
),
commands
.
registerCommand
(
'
git.unstage
'
,
this
.
unstage
,
this
),
commands
.
registerCommand
(
'
git.unstageAll
'
,
this
.
unstageAll
,
this
),
commands
.
registerCommand
(
'
git.clean
'
,
this
.
clean
,
this
),
commands
.
registerCommand
(
'
git.cleanAll
'
,
this
.
cleanAll
,
this
),
commands
.
registerCommand
(
'
git.checkout
'
,
this
.
checkout
,
this
),
commands
.
registerCommand
(
'
git.sync
'
,
this
.
sync
,
this
),
commands
.
registerCommand
(
'
git.publish
'
,
this
.
publish
,
this
),
commands
.
registerCommand
(
'
git.showOutput
'
,
this
.
showOutput
,
this
),
);
this
.
disposables
=
CommandCenter
.
Commands
.
map
(({
commandId
,
method
})
=>
commands
.
registerCommand
(
commandId
,
method
,
this
));
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.refresh
'
)
@
CommandCenter
.
CatchErrors
async
refresh
():
Promise
<
void
>
{
return
await
this
.
model
.
update
();
await
this
.
model
.
update
();
throw
new
Error
(
'
OH MY LORD
'
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.openChange
'
)
@
CommandCenter
.
CatchErrors
async
openChange
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -200,7 +211,8 @@ export class CommandCenter {
return
''
;
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.openFile
'
)
@
CommandCenter
.
CatchErrors
async
openFile
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -211,7 +223,8 @@ export class CommandCenter {
return
commands
.
executeCommand
<
void
>
(
'
vscode.open
'
,
resource
.
uri
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.stage
'
)
@
CommandCenter
.
CatchErrors
async
stage
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -222,12 +235,14 @@ export class CommandCenter {
return
await
this
.
model
.
stage
(
resource
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.stageAll
'
)
@
CommandCenter
.
CatchErrors
async
stageAll
():
Promise
<
void
>
{
return
await
this
.
model
.
stage
();
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.unstage
'
)
@
CommandCenter
.
CatchErrors
async
unstage
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -238,12 +253,14 @@ export class CommandCenter {
return
await
this
.
model
.
unstage
(
resource
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.unstageAll
'
)
@
CommandCenter
.
CatchErrors
async
unstageAll
():
Promise
<
void
>
{
return
await
this
.
model
.
unstage
();
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.clean
'
)
@
CommandCenter
.
CatchErrors
async
clean
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
...
...
@@ -264,7 +281,8 @@ export class CommandCenter {
return
await
this
.
model
.
clean
(
resource
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.cleanAll
'
)
@
CommandCenter
.
CatchErrors
async
cleanAll
():
Promise
<
void
>
{
const
message
=
`Are you sure you want to clean all changes?`
;
const
yes
=
'
Yes
'
;
...
...
@@ -278,7 +296,8 @@ export class CommandCenter {
return
await
this
.
model
.
clean
(...
this
.
model
.
workingTreeGroup
.
resources
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.checkout
'
)
@
CommandCenter
.
CatchErrors
async
checkout
():
Promise
<
void
>
{
const
config
=
workspace
.
getConfiguration
(
'
git
'
);
const
checkoutType
=
config
.
get
<
string
>
(
'
checkoutType
'
);
...
...
@@ -305,12 +324,14 @@ export class CommandCenter {
await
choice
.
run
(
this
.
model
);
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.sync
'
)
@
CommandCenter
.
CatchErrors
async
sync
():
Promise
<
void
>
{
await
this
.
model
.
sync
();
}
@
decorate
(
catchErrors
)
@
CommandCenter
.
Command
(
'
git.publish
'
)
@
CommandCenter
.
CatchErrors
async
publish
():
Promise
<
void
>
{
const
branchName
=
this
.
model
.
HEAD
&&
this
.
model
.
HEAD
.
name
||
''
;
const
picks
=
this
.
model
.
remotes
.
map
(
r
=>
r
.
name
);
...
...
@@ -324,6 +345,7 @@ export class CommandCenter {
await
this
.
model
.
push
(
choice
,
branchName
,
{
setUpstream
:
true
});
}
@
CommandCenter
.
Command
(
'
git.showOutput
'
)
showOutput
():
void
{
this
.
outputChannel
.
show
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录