Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
6f05c439
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,发现更多精彩内容 >>
提交
6f05c439
编写于
1月 11, 2017
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git: pimp up commands
上级
ec5c873e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
104 addition
and
70 deletion
+104
-70
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+104
-70
未找到文件。
extensions/git/src/commands.ts
浏览文件 @
6f05c439
...
...
@@ -8,109 +8,143 @@
import
{
Uri
,
commands
,
scm
,
Disposable
,
SCMResourceGroup
,
SCMResource
,
window
}
from
'
vscode
'
;
import
{
Model
,
Resource
}
from
'
./model
'
;
import
{
log
}
from
'
./util
'
;
import
{
decorate
}
from
'
core-decorators
'
;
import
*
as
path
from
'
path
'
;
type
Command
=
(...
args
:
any
[])
=>
any
;
async
function
refresh
(
model
:
Model
):
Promise
<
void
>
{
return
await
model
.
update
(
);
function
catchErrors
(
fn
:
(...
args
)
=>
Promise
<
any
>
):
(...
args
)
=>
void
{
return
(...
args
)
=>
fn
.
call
(
this
,
...
args
).
catch
(
err
=>
console
.
error
(
err
)
);
}
function
openChange
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
open change
'
,
resource
);
}
function
resolveGitURI
(
uri
:
Uri
):
SCMResource
|
SCMResourceGroup
|
undefined
{
if
(
uri
.
authority
!==
'
git
'
)
{
return
;
}
function
openFile
(
model
:
Model
,
resource
:
Resource
):
void
{
log
(
'
open file
'
,
resource
);
return
scm
.
getResourceFromURI
(
uri
);
}
async
function
stage
(
model
:
Model
,
resource
:
Resource
):
Promise
<
void
>
{
return
await
model
.
stage
(
resource
);
}
function
resolveGitResource
(
uri
:
Uri
):
Resource
|
undefined
{
const
resource
=
resolveGitURI
(
uri
);
async
function
stageAll
(
model
:
Model
):
Promise
<
void
>
{
return
await
model
.
stage
()
;
}
if
(
!
(
resource
instanceof
Resource
))
{
return
;
}
async
function
unstage
(
model
:
Model
,
resource
:
Resource
):
Promise
<
void
>
{
return
await
model
.
unstage
(
resource
);
return
resource
;
}
async
function
unstageAll
(
model
:
Model
):
Promise
<
void
>
{
return
await
model
.
unstage
();
}
class
CommandCenter
{
private
disposables
:
Disposable
[]
=
[];
constructor
(
private
model
:
Model
)
{
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
)
);
}
@
decorate
(
catchErrors
)
async
refresh
():
Promise
<
void
>
{
return
await
this
.
model
.
update
();
}
async
function
clean
(
model
:
Model
,
resource
:
Resource
):
Promise
<
void
>
{
const
basename
=
path
.
basename
(
resource
.
uri
.
fsPath
);
const
message
=
`Are you sure you want to clean changes in
${
basename
}
?`
;
const
yes
=
'
Yes
'
;
const
no
=
'
No, keep them
'
;
const
pick
=
await
window
.
showQuickPick
([
no
,
yes
],
{
placeHolder
:
message
});
openChange
(
uri
:
Uri
):
void
{
const
resource
=
resolveGitResource
(
uri
);
log
(
'
open change
'
,
resource
);
}
if
(
pick
!==
yes
)
{
return
;
openFile
(
uri
:
Uri
):
void
{
const
resource
=
resolveGitResource
(
uri
);
log
(
'
open file
'
,
resource
);
}
return
await
model
.
clean
(
resource
);
}
@
decorate
(
catchErrors
)
async
stage
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
async
function
cleanAll
(
model
:
Model
):
Promise
<
void
>
{
const
message
=
`Are you sure you want to clean all changes?`
;
const
yes
=
'
Yes
'
;
const
no
=
'
No, keep them
'
;
const
pick
=
await
window
.
showQuickPick
([
no
,
yes
],
{
placeHolder
:
message
});
if
(
!
resource
)
{
return
;
}
if
(
pick
!==
yes
)
{
return
;
return
await
this
.
model
.
stage
(
resource
);
}
return
await
model
.
clean
(...
model
.
workingTreeGroup
.
resources
);
}
@
decorate
(
catchErrors
)
async
stageAll
():
Promise
<
void
>
{
return
await
this
.
model
.
stage
();
}
function
checkout
(
model
:
Model
):
void
{
console
.
log
(
'
checkout
'
);
}
@
decorate
(
catchErrors
)
async
unstage
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
function
resolveURI
<
R
>
(
command
:
(
t
:
SCMResource
|
SCMResourceGroup
|
undefined
)
=>
R
):
(
uri
:
Uri
)
=>
R
|
undefined
{
return
uri
=>
{
if
(
uri
.
authority
!==
'
git
'
)
{
if
(
!
resource
)
{
return
;
}
const
result
=
scm
.
getResourceFromURI
(
uri
);
return
await
this
.
model
.
unstage
(
resource
);
}
@
decorate
(
catchErrors
)
async
unstageAll
():
Promise
<
void
>
{
return
await
this
.
model
.
unstage
();
}
if
(
!
result
)
{
@
decorate
(
catchErrors
)
async
clean
(
uri
:
Uri
):
Promise
<
void
>
{
const
resource
=
resolveGitResource
(
uri
);
if
(
!
resource
)
{
return
;
}
return
command
(
result
);
};
}
const
basename
=
path
.
basename
(
resource
.
uri
.
fsPath
);
const
message
=
`Are you sure you want to clean changes in
${
basename
}
?`
;
const
yes
=
'
Yes
'
;
const
no
=
'
No, keep them
'
;
const
pick
=
await
window
.
showQuickPick
([
no
,
yes
],
{
placeHolder
:
message
});
// TODO: do more with these errors
function
catchErrors
<
T
,
R
>
(
command
:
(...
args
:
any
[])
=>
Promise
<
R
>
):
(...
args
:
any
[])
=>
void
{
return
(...
args
)
=>
command
(...
args
).
catch
(
err
=>
console
.
error
(
err
));
}
if
(
pick
!==
yes
)
{
return
;
}
return
await
this
.
model
.
clean
(
resource
);
}
function
compose
(
command
:
Command
,
...
args
:
Function
[]):
Command
{
return
args
.
reduce
((
r
,
fn
)
=>
fn
(
r
),
command
)
as
Command
;
@
decorate
(
catchErrors
)
async
cleanAll
():
Promise
<
void
>
{
const
message
=
`Are you sure you want to clean all changes?`
;
const
yes
=
'
Yes
'
;
const
no
=
'
No, keep them
'
;
const
pick
=
await
window
.
showQuickPick
([
no
,
yes
],
{
placeHolder
:
message
});
if
(
pick
!==
yes
)
{
return
;
}
return
await
this
.
model
.
clean
(...
this
.
model
.
workingTreeGroup
.
resources
);
}
checkout
(
model
:
Model
):
void
{
console
.
log
(
'
checkout
'
);
}
dispose
():
void
{
this
.
disposables
.
forEach
(
d
=>
d
.
dispose
());
}
}
export
function
registerCommands
(
model
:
Model
):
Disposable
{
const
bindModel
=
command
=>
(...
args
:
any
[])
=>
command
(
model
,
...
args
);
const
disposables
=
[
commands
.
registerCommand
(
'
git.refresh
'
,
compose
(
refresh
,
catchErrors
,
bindModel
)),
commands
.
registerCommand
(
'
git.openChange
'
,
compose
(
openChange
,
bindModel
,
resolveURI
)),
commands
.
registerCommand
(
'
git.openFile
'
,
compose
(
openFile
,
bindModel
,
resolveURI
)),
commands
.
registerCommand
(
'
git.stage
'
,
compose
(
stage
,
catchErrors
,
bindModel
,
resolveURI
)),
commands
.
registerCommand
(
'
git.stageAll
'
,
compose
(
stageAll
,
catchErrors
,
bindModel
)),
commands
.
registerCommand
(
'
git.unstage
'
,
compose
(
unstage
,
catchErrors
,
bindModel
,
resolveURI
)),
commands
.
registerCommand
(
'
git.unstageAll
'
,
compose
(
unstageAll
,
catchErrors
,
bindModel
)),
commands
.
registerCommand
(
'
git.clean
'
,
compose
(
clean
,
catchErrors
,
bindModel
,
resolveURI
)),
commands
.
registerCommand
(
'
git.cleanAll
'
,
compose
(
cleanAll
,
catchErrors
,
bindModel
)),
commands
.
registerCommand
(
'
git.checkout
'
,
compose
(
checkout
,
bindModel
)),
];
return
Disposable
.
from
(...
disposables
);
return
new
CommandCenter
(
model
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录