Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
1f38d8e8
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,发现更多精彩内容 >>
提交
1f38d8e8
编写于
11月 28, 2016
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
git: output channel
上级
3ac3b7a1
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
44 addition
and
32 deletion
+44
-32
extensions/git/src/git.ts
extensions/git/src/git.ts
+15
-12
extensions/git/src/main.ts
extensions/git/src/main.ts
+29
-20
未找到文件。
extensions/git/src/git.ts
浏览文件 @
1f38d8e8
...
...
@@ -11,6 +11,7 @@ import * as cp from 'child_process';
import
*
as
denodeify
from
'
denodeify
'
;
import
{
IDisposable
,
toDisposable
,
dispose
}
from
'
./util
'
;
import
*
as
_
from
'
lodash
'
;
import
{
EventEmitter
,
Event
}
from
'
vscode
'
;
const
readdir
=
denodeify
(
fs
.
readdir
);
...
...
@@ -252,12 +253,15 @@ function encodingExists(encoding) {
export
class
Git
{
gitPath
:
string
;
version
:
string
;
env
:
any
;
private
gitPath
:
string
;
private
version
:
string
;
private
env
:
any
;
private
defaultEncoding
:
string
;
private
outputListeners
:
{
(
output
:
string
):
void
;
}[];
private
_onOutput
=
new
EventEmitter
<
string
>
();
get
onOutput
():
Event
<
string
>
{
return
this
.
_onOutput
.
event
;
}
constructor
(
options
:
IGitOptions
)
{
this
.
gitPath
=
options
.
gitPath
;
this
.
version
=
options
.
version
;
...
...
@@ -276,11 +280,11 @@ export class Git {
stream
(
cwd
:
string
,
args
:
string
[],
options
:
any
=
{}):
cp
.
ChildProcess
{
options
=
_
.
assign
({
cwd
:
cwd
},
options
||
{});
return
this
.
spawn
(
args
,
options
);
return
this
.
_
spawn
(
args
,
options
);
}
private
_exec
(
args
:
string
[],
options
:
any
=
{}):
Promise
<
IExecutionResult
>
{
const
child
=
this
.
spawn
(
args
,
options
);
const
child
=
this
.
_
spawn
(
args
,
options
);
if
(
options
.
input
)
{
child
.
stdin
.
end
(
options
.
input
,
'
utf8
'
);
...
...
@@ -304,6 +308,10 @@ export class Git {
gitErrorCode
=
GitErrorCodes
.
CantAccessRemote
;
}
if
(
options
.
log
!==
false
)
{
this
.
log
(
result
.
stderr
);
}
return
Promise
.
reject
<
IExecutionResult
>
(
new
GitError
({
message
:
'
Failed to execute git
'
,
stdout
:
result
.
stdout
,
...
...
@@ -318,7 +326,7 @@ export class Git {
});
}
spawn
(
args
:
string
[],
options
:
any
=
{}):
cp
.
ChildProcess
{
private
_
spawn
(
args
:
string
[],
options
:
any
=
{}):
cp
.
ChildProcess
{
if
(
!
this
.
gitPath
)
{
throw
new
Error
(
'
git could not be found in the system.
'
);
}
...
...
@@ -340,12 +348,7 @@ export class Git {
return
cp
.
spawn
(
this
.
gitPath
,
args
,
options
);
}
onOutput
(
listener
:
(
output
:
string
)
=>
void
):
()
=>
void
{
this
.
outputListeners
.
push
(
listener
);
return
()
=>
this
.
outputListeners
.
splice
(
this
.
outputListeners
.
indexOf
(
listener
),
1
);
}
private
log
(
output
:
string
):
void
{
this
.
outputListeners
.
forEach
(
l
=>
l
(
output
)
);
this
.
_onOutput
.
fire
(
output
);
}
}
\ No newline at end of file
extensions/git/src/main.ts
浏览文件 @
1f38d8e8
...
...
@@ -5,7 +5,7 @@
'
use strict
'
;
import
{
scm
,
ExtensionContext
,
workspace
,
Uri
}
from
'
vscode
'
;
import
{
scm
,
ExtensionContext
,
workspace
,
Uri
,
window
,
Disposable
}
from
'
vscode
'
;
import
*
as
path
from
'
path
'
;
import
{
findGit
,
Git
}
from
'
./git
'
;
import
{
registerCommands
}
from
'
./commands
'
;
...
...
@@ -27,6 +27,23 @@ class GitSCMProvider {
}
}
class
TextDocumentContentProvider
{
constructor
(
private
git
:
Git
,
private
rootPath
:
string
)
{
}
provideTextDocumentContent
(
uri
:
Uri
)
{
const
relativePath
=
path
.
relative
(
this
.
rootPath
,
uri
.
fsPath
);
return
this
.
git
.
exec
(
this
.
rootPath
,
[
'
show
'
,
`HEAD:
${
relativePath
}
`
]).
then
(
result
=>
{
if
(
result
.
exitCode
!==
0
)
{
return
null
;
}
return
result
.
stdout
;
});
}
}
export
function
activate
(
context
:
ExtensionContext
):
any
{
if
(
!
workspace
.
rootPath
)
{
return
;
...
...
@@ -36,28 +53,20 @@ export function activate(context: ExtensionContext): any {
const
pathHint
=
workspace
.
getConfiguration
(
'
git
'
).
get
<
string
>
(
'
path
'
);
findGit
(
pathHint
).
then
(
info
=>
{
log
(
`Using git
${
info
.
version
}
from
${
info
.
path
}
`
);
const
git
=
new
Git
({
gitPath
:
info
.
path
,
version
:
info
.
version
});
const
provider
=
new
GitSCMProvider
();
const
providerDisposable
=
scm
.
registerSCMProvider
(
'
git
'
,
provider
);
const
contentProvider
=
workspace
.
registerTextDocumentContentProvider
(
'
git-index
'
,
{
provideTextDocumentContent
:
uri
=>
{
const
relativePath
=
path
.
relative
(
rootPath
,
uri
.
fsPath
);
const
disposables
:
Disposable
[]
=
[];
return
git
.
exec
(
rootPath
,
[
'
show
'
,
`HEAD:
${
relativePath
}
`
]).
then
(
result
=>
{
if
(
result
.
exitCode
!==
0
)
{
return
null
;
}
return
result
.
stdout
;
});
}
});
const
outputChannel
=
window
.
createOutputChannel
(
'
git
'
);
outputChannel
.
appendLine
(
`Using git
${
info
.
version
}
from
${
info
.
path
}
`
);
git
.
onOutput
(
str
=>
outputChannel
.
append
(
str
),
null
,
disposables
);
const
commands
=
registerCommands
();
disposables
.
push
(
registerCommands
(),
scm
.
registerSCMProvider
(
'
git
'
,
new
GitSCMProvider
()),
workspace
.
registerTextDocumentContentProvider
(
'
git-index
'
,
new
TextDocumentContentProvider
(
git
,
rootPath
)),
outputChannel
);
context
.
subscriptions
.
push
(
providerDisposable
,
contentProvider
,
command
s
);
context
.
subscriptions
.
push
(
...
disposable
s
);
});
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录