Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
28a78cba
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,发现更多精彩内容 >>
提交
28a78cba
编写于
5月 30, 2016
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reorg imports
上级
ef79eac2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
301 addition
and
301 deletion
+301
-301
src/vs/workbench/parts/git/browser/gitQuickOpen.ts
src/vs/workbench/parts/git/browser/gitQuickOpen.ts
+54
-56
src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts
.../workbench/parts/git/browser/gitWorkbenchContributions.ts
+1
-1
src/vs/workbench/parts/git/common/git.ts
src/vs/workbench/parts/git/common/git.ts
+50
-50
src/vs/workbench/parts/git/common/gitModel.ts
src/vs/workbench/parts/git/common/gitModel.ts
+98
-95
src/vs/workbench/parts/git/common/noopGitService.ts
src/vs/workbench/parts/git/common/noopGitService.ts
+21
-21
src/vs/workbench/parts/git/node/git.lib.ts
src/vs/workbench/parts/git/node/git.lib.ts
+70
-71
src/vs/workbench/parts/git/node/rawGitService.ts
src/vs/workbench/parts/git/node/rawGitService.ts
+7
-7
未找到文件。
src/vs/workbench/parts/git/browser/gitQuickOpen.ts
浏览文件 @
28a78cba
...
...
@@ -4,26 +4,24 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
nls
=
require
(
'
vs/nls
'
)
;
import
filters
=
require
(
'
vs/base/common/filters
'
)
;
import
winjs
=
require
(
'
vs/base/common/winjs.base
'
)
;
import
s
everity
from
'
vs/base/common/severity
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
matchesContiguousSubString
}
from
'
vs/base/common/filters
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
S
everity
from
'
vs/base/common/severity
'
;
import
{
IGitService
,
RefType
,
IRef
,
isValidBranchName
}
from
'
vs/workbench/parts/git/common/git
'
;
import
quickopenwb
=
require
(
'
vs/workbench/browser/quickopen
'
)
;
import
quickopen
=
require
(
'
vs/base/parts/quickopen/common/quickOpen
'
)
;
import
model
=
require
(
'
vs/base/parts/quickopen/browser/quickOpenModel
'
)
;
import
{
IQuickOpenService
}
from
'
vs/workbench/services/quickopen/common/quickOpenService
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
import
{
ICommand
,
CommandQuickOpenHandler
}
from
'
vs/workbench/browser/quickopen
'
;
import
{
Mode
}
from
'
vs/base/parts/quickopen/common/quickOpen
'
;
import
{
QuickOpenEntry
,
IHighlight
,
IContext
,
QuickOpenEntryGroup
}
from
'
vs/base/parts/quickopen/browser/quickOpenModel
'
;
import
{
IQuickOpenService
}
from
'
vs/workbench/services/quickopen/common/quickOpenService
'
;
import
{
IMessageService
}
from
'
vs/platform/message/common/message
'
;
// Entries
class
AbstractRefEntry
extends
model
.
QuickOpenEntry
{
class
AbstractRefEntry
extends
QuickOpenEntry
{
protected
gitService
:
IGitService
;
protected
messageService
:
IMessageService
;
protected
ref
:
IRef
;
constructor
(
gitService
:
IGitService
,
messageService
:
IMessageService
,
ref
:
IRef
,
highlights
:
model
.
IHighlight
[])
{
constructor
(
gitService
:
IGitService
,
messageService
:
IMessageService
,
ref
:
IRef
,
highlights
:
IHighlight
[])
{
super
(
highlights
);
this
.
gitService
=
gitService
;
...
...
@@ -34,10 +32,10 @@ class AbstractRefEntry extends model.QuickOpenEntry {
getIcon
():
string
{
return
'
git
'
;
}
getLabel
():
string
{
return
this
.
ref
.
name
;
}
getDescription
():
string
{
return
''
;
}
getAriaLabel
():
string
{
return
nls
.
localize
(
'
refAriaLabel
'
,
"
{0}, git
"
,
this
.
getLabel
());
}
getAriaLabel
():
string
{
return
localize
(
'
refAriaLabel
'
,
"
{0}, git
"
,
this
.
getLabel
());
}
run
(
mode
:
quickopen
.
Mode
,
context
:
model
.
IContext
):
boolean
{
if
(
mode
===
quickopen
.
Mode
.
PREVIEW
)
{
run
(
mode
:
Mode
,
context
:
IContext
):
boolean
{
if
(
mode
===
Mode
.
PREVIEW
)
{
return
false
;
}
...
...
@@ -47,54 +45,54 @@ class AbstractRefEntry extends model.QuickOpenEntry {
class
CheckoutHeadEntry
extends
AbstractRefEntry
{
getDescription
():
string
{
return
nls
.
localize
(
'
checkoutBranch
'
,
"
Branch at {0}
"
,
this
.
ref
.
commit
.
substr
(
0
,
8
));
}
getDescription
():
string
{
return
localize
(
'
checkoutBranch
'
,
"
Branch at {0}
"
,
this
.
ref
.
commit
.
substr
(
0
,
8
));
}
run
(
mode
:
quickopen
.
Mode
,
context
:
model
.
IContext
):
boolean
{
if
(
mode
===
quickopen
.
Mode
.
PREVIEW
)
{
run
(
mode
:
Mode
,
context
:
IContext
):
boolean
{
if
(
mode
===
Mode
.
PREVIEW
)
{
return
false
;
}
this
.
gitService
.
checkout
(
this
.
ref
.
name
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
s
everity
.
Error
,
e
));
this
.
gitService
.
checkout
(
this
.
ref
.
name
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
S
everity
.
Error
,
e
));
return
true
;
}
}
class
CheckoutRemoteHeadEntry
extends
AbstractRefEntry
{
getDescription
():
string
{
return
nls
.
localize
(
'
checkoutRemoteBranch
'
,
"
Remote branch at {0}
"
,
this
.
ref
.
commit
.
substr
(
0
,
8
));
}
getDescription
():
string
{
return
localize
(
'
checkoutRemoteBranch
'
,
"
Remote branch at {0}
"
,
this
.
ref
.
commit
.
substr
(
0
,
8
));
}
run
(
mode
:
quickopen
.
Mode
,
context
:
model
.
IContext
):
boolean
{
if
(
mode
===
quickopen
.
Mode
.
PREVIEW
)
{
run
(
mode
:
Mode
,
context
:
IContext
):
boolean
{
if
(
mode
===
Mode
.
PREVIEW
)
{
return
false
;
}
const
match
=
/^
[^/]
+
\/(
.*
)
$/
.
exec
(
this
.
ref
.
name
);
const
name
=
match
?
match
[
1
]
:
this
.
ref
.
name
;
this
.
gitService
.
checkout
(
name
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
s
everity
.
Error
,
e
));
this
.
gitService
.
checkout
(
name
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
S
everity
.
Error
,
e
));
return
true
;
}
}
class
CheckoutTagEntry
extends
AbstractRefEntry
{
getDescription
():
string
{
return
nls
.
localize
(
'
checkoutTag
'
,
"
Tag at {0}
"
,
this
.
ref
.
commit
.
substr
(
0
,
8
));
}
getDescription
():
string
{
return
localize
(
'
checkoutTag
'
,
"
Tag at {0}
"
,
this
.
ref
.
commit
.
substr
(
0
,
8
));
}
run
(
mode
:
quickopen
.
Mode
,
context
:
model
.
IContext
):
boolean
{
if
(
mode
===
quickopen
.
Mode
.
PREVIEW
)
{
run
(
mode
:
Mode
,
context
:
IContext
):
boolean
{
if
(
mode
===
Mode
.
PREVIEW
)
{
return
false
;
}
this
.
gitService
.
checkout
(
this
.
ref
.
name
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
s
everity
.
Error
,
e
));
this
.
gitService
.
checkout
(
this
.
ref
.
name
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
S
everity
.
Error
,
e
));
return
true
;
}
}
class
CurrentHeadEntry
extends
AbstractRefEntry
{
getDescription
():
string
{
return
nls
.
localize
(
'
alreadyCheckedOut
'
,
"
Branch {0} is already the current branch
"
,
this
.
ref
.
name
);
}
getDescription
():
string
{
return
localize
(
'
alreadyCheckedOut
'
,
"
Branch {0} is already the current branch
"
,
this
.
ref
.
name
);
}
}
class
BranchEntry
extends
model
.
QuickOpenEntry
{
class
BranchEntry
extends
QuickOpenEntry
{
private
gitService
:
IGitService
;
private
messageService
:
IMessageService
;
...
...
@@ -110,22 +108,22 @@ class BranchEntry extends model.QuickOpenEntry {
getIcon
():
string
{
return
'
git
'
;
}
getLabel
():
string
{
return
this
.
name
;
}
getAriaLabel
():
string
{
return
nls
.
localize
({
key
:
'
branchAriaLabel
'
,
comment
:
[
'
the branch name
'
]
},
"
{0}, git branch
"
,
this
.
getLabel
());
}
getDescription
():
string
{
return
nls
.
localize
(
'
createBranch
'
,
"
Create branch {0}
"
,
this
.
name
);
}
getAriaLabel
():
string
{
return
localize
({
key
:
'
branchAriaLabel
'
,
comment
:
[
'
the branch name
'
]
},
"
{0}, git branch
"
,
this
.
getLabel
());
}
getDescription
():
string
{
return
localize
(
'
createBranch
'
,
"
Create branch {0}
"
,
this
.
name
);
}
run
(
mode
:
quickopen
.
Mode
,
context
:
model
.
IContext
):
boolean
{
if
(
mode
===
quickopen
.
Mode
.
PREVIEW
)
{
run
(
mode
:
Mode
,
context
:
IContext
):
boolean
{
if
(
mode
===
Mode
.
PREVIEW
)
{
return
false
;
}
this
.
gitService
.
branch
(
this
.
name
,
true
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
s
everity
.
Error
,
e
));
this
.
gitService
.
branch
(
this
.
name
,
true
).
done
(
null
,
e
=>
this
.
messageService
.
show
(
S
everity
.
Error
,
e
));
return
true
;
}
}
// Commands
class
CheckoutCommand
implements
quickopenwb
.
ICommand
{
class
CheckoutCommand
implements
ICommand
{
aliases
=
[
'
checkout
'
,
'
co
'
];
icon
=
'
git
'
;
...
...
@@ -134,7 +132,7 @@ class CheckoutCommand implements quickopenwb.ICommand {
// noop
}
getResults
(
input
:
string
):
winjs
.
TPromise
<
model
.
QuickOpenEntry
[]
>
{
getResults
(
input
:
string
):
TPromise
<
QuickOpenEntry
[]
>
{
input
=
input
.
trim
();
const
gitModel
=
this
.
gitService
.
getModel
();
...
...
@@ -145,15 +143,15 @@ class CheckoutCommand implements quickopenwb.ICommand {
const
remoteHeads
=
refs
.
filter
(
ref
=>
ref
.
type
===
RefType
.
RemoteHead
);
const
headMatches
=
heads
.
map
(
head
=>
({
head
,
highlights
:
filters
.
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
map
(
head
=>
({
head
,
highlights
:
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
filter
(({
highlights
})
=>
!!
highlights
);
const
headEntries
:
model
.
QuickOpenEntry
[]
=
headMatches
const
headEntries
:
QuickOpenEntry
[]
=
headMatches
.
filter
(({
head
})
=>
head
.
name
!==
currentHead
.
name
)
.
map
(({
head
,
highlights
})
=>
new
CheckoutHeadEntry
(
this
.
gitService
,
this
.
messageService
,
head
,
highlights
));
const
tagMatches
=
tags
.
map
(
head
=>
({
head
,
highlights
:
filters
.
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
map
(
head
=>
({
head
,
highlights
:
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
filter
(({
highlights
})
=>
!!
highlights
);
const
tagEntries
=
tagMatches
...
...
@@ -165,20 +163,20 @@ class CheckoutCommand implements quickopenwb.ICommand {
.
sort
((
a
,
b
)
=>
a
.
getLabel
().
localeCompare
(
b
.
getLabel
()));
const
remoteHeadMatches
=
remoteHeads
.
map
(
head
=>
({
head
,
highlights
:
filters
.
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
map
(
head
=>
({
head
,
highlights
:
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
filter
(({
highlights
})
=>
!!
highlights
);
const
remoteHeadEntries
:
model
.
QuickOpenEntry
[]
=
remoteHeadMatches
const
remoteHeadEntries
:
QuickOpenEntry
[]
=
remoteHeadMatches
.
filter
(({
head
})
=>
head
.
name
!==
currentHead
.
name
)
.
map
(({
head
,
highlights
})
=>
new
CheckoutRemoteHeadEntry
(
this
.
gitService
,
this
.
messageService
,
head
,
highlights
))
.
sort
((
a
,
b
)
=>
a
.
getLabel
().
localeCompare
(
b
.
getLabel
()));
if
(
checkoutEntries
.
length
>
0
)
{
checkoutEntries
[
0
]
=
new
model
.
QuickOpenEntryGroup
(
checkoutEntries
[
0
],
'
checkout
'
,
false
);
checkoutEntries
[
0
]
=
new
QuickOpenEntryGroup
(
checkoutEntries
[
0
],
'
checkout
'
,
false
);
}
if
(
remoteHeadEntries
.
length
>
0
)
{
remoteHeadEntries
[
0
]
=
new
model
.
QuickOpenEntryGroup
(
remoteHeadEntries
[
0
],
'
checkout remote
'
,
checkoutEntries
.
length
>
0
);
remoteHeadEntries
[
0
]
=
new
QuickOpenEntryGroup
(
remoteHeadEntries
[
0
],
'
checkout remote
'
,
checkoutEntries
.
length
>
0
);
}
const
entries
=
checkoutEntries
...
...
@@ -194,18 +192,18 @@ class CheckoutCommand implements quickopenwb.ICommand {
}
else
if
(
exactMatches
.
length
===
0
&&
isValidBranchName
(
input
))
{
const
branchEntry
=
new
BranchEntry
(
this
.
gitService
,
this
.
messageService
,
input
);
entries
.
push
(
new
model
.
QuickOpenEntryGroup
(
branchEntry
,
'
branch
'
,
checkoutEntries
.
length
>
0
||
remoteHeadEntries
.
length
>
0
));
entries
.
push
(
new
QuickOpenEntryGroup
(
branchEntry
,
'
branch
'
,
checkoutEntries
.
length
>
0
||
remoteHeadEntries
.
length
>
0
));
}
return
winjs
.
TPromise
.
as
<
model
.
QuickOpenEntry
[]
>
(
entries
);
return
TPromise
.
as
<
QuickOpenEntry
[]
>
(
entries
);
}
getEmptyLabel
(
input
:
string
):
string
{
return
nls
.
localize
(
'
noBranches
'
,
"
No other branches
"
);
return
localize
(
'
noBranches
'
,
"
No other branches
"
);
}
}
class
BranchCommand
implements
quickopenwb
.
ICommand
{
class
BranchCommand
implements
ICommand
{
aliases
=
[
'
branch
'
];
icon
=
'
git
'
;
...
...
@@ -214,39 +212,39 @@ class BranchCommand implements quickopenwb.ICommand {
// noop
}
getResults
(
input
:
string
):
winjs
.
TPromise
<
model
.
QuickOpenEntry
[]
>
{
getResults
(
input
:
string
):
TPromise
<
QuickOpenEntry
[]
>
{
input
=
input
.
trim
();
if
(
!
isValidBranchName
(
input
))
{
return
winjs
.
TPromise
.
as
([]);
return
TPromise
.
as
([]);
}
const
gitModel
=
this
.
gitService
.
getModel
();
const
currentHead
=
gitModel
.
getHEAD
();
const
matches
=
gitModel
.
getRefs
()
.
map
(
head
=>
({
head
,
highlights
:
filters
.
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
map
(
head
=>
({
head
,
highlights
:
matchesContiguousSubString
(
input
,
head
.
name
)
}))
.
filter
(({
highlights
})
=>
!!
highlights
);
const
exactMatches
=
matches
.
filter
(({
head
})
=>
head
.
name
===
input
);
const
headMatches
=
exactMatches
.
filter
(({
head
})
=>
head
.
name
===
currentHead
.
name
);
if
(
headMatches
.
length
>
0
)
{
return
winjs
.
TPromise
.
as
([
new
CurrentHeadEntry
(
this
.
gitService
,
this
.
messageService
,
headMatches
[
0
].
head
,
headMatches
[
0
].
highlights
)]);
return
TPromise
.
as
([
new
CurrentHeadEntry
(
this
.
gitService
,
this
.
messageService
,
headMatches
[
0
].
head
,
headMatches
[
0
].
highlights
)]);
}
else
if
(
exactMatches
.
length
>
0
)
{
return
winjs
.
TPromise
.
as
([
new
CheckoutHeadEntry
(
this
.
gitService
,
this
.
messageService
,
exactMatches
[
0
].
head
,
exactMatches
[
0
].
highlights
)]);
return
TPromise
.
as
([
new
CheckoutHeadEntry
(
this
.
gitService
,
this
.
messageService
,
exactMatches
[
0
].
head
,
exactMatches
[
0
].
highlights
)]);
}
const
branchEntry
=
new
BranchEntry
(
this
.
gitService
,
this
.
messageService
,
input
);
return
winjs
.
TPromise
.
as
([
new
model
.
QuickOpenEntryGroup
(
branchEntry
,
'
branch
'
,
false
)]);
return
TPromise
.
as
([
new
QuickOpenEntryGroup
(
branchEntry
,
'
branch
'
,
false
)]);
}
getEmptyLabel
(
input
:
string
):
string
{
return
nls
.
localize
(
'
notValidBranchName
'
,
"
Please provide a valid branch name
"
);
return
localize
(
'
notValidBranchName
'
,
"
Please provide a valid branch name
"
);
}
}
export
class
CommandQuickOpenHandler
extends
quickopenwb
.
CommandQuickOpenHandler
{
export
class
GitCommandQuickOpenHandler
extends
CommandQuickOpenHandler
{
constructor
(@
IQuickOpenService
quickOpenService
:
IQuickOpenService
,
@
IGitService
gitService
:
IGitService
,
@
IMessageService
messageService
:
IMessageService
)
{
super
(
quickOpenService
,
{
...
...
src/vs/workbench/parts/git/browser/gitWorkbenchContributions.ts
浏览文件 @
28a78cba
...
...
@@ -498,7 +498,7 @@ export function registerContributions(): void {
(
<
quickopen
.
IQuickOpenRegistry
>
platform
.
Registry
.
as
(
quickopen
.
Extensions
.
Quickopen
)).
registerQuickOpenHandler
(
new
quickopen
.
QuickOpenHandlerDescriptor
(
'
vs/workbench/parts/git/browser/gitQuickOpen
'
,
'
CommandQuickOpenHandler
'
,
'
Git
CommandQuickOpenHandler
'
,
'
git
'
,
nls
.
localize
(
'
gitCommands
'
,
"
Git Commands
"
)
)
...
...
src/vs/workbench/parts/git/common/git.ts
浏览文件 @
28a78cba
...
...
@@ -4,12 +4,12 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
WinJS
=
require
(
'
vs/base/common/winjs.base
'
);
import
WorkbenchEditorCommon
=
require
(
'
vs/workbench/common/editor
'
);
import
EventEmitter
=
require
(
'
vs/base/common/eventEmitter
'
);
import
Lifecycle
=
require
(
'
vs/base/common/lifecycle
'
);
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
EditorInput
}
from
'
vs/workbench/common/editor
'
;
import
{
IEventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
createDecorator
,
ServiceIdentifier
}
from
'
vs/platform/instantiation/common/instantiation
'
;
import
Event
from
'
vs/base/common/event
'
;
import
{
createDecorator
,
ServiceIdentifier
}
from
'
vs/platform/instantiation/common/instantiation
'
;
// Model raw interfaces
...
...
@@ -107,7 +107,7 @@ export interface IFileStatus {
update
(
other
:
IFileStatus
):
void
;
}
export
interface
IStatusGroup
extends
EventEmitter
.
IEventEmitter
{
export
interface
IStatusGroup
extends
IEventEmitter
{
getType
():
StatusType
;
update
(
statusList
:
IFileStatus
[]):
void
;
all
():
IFileStatus
[];
...
...
@@ -120,7 +120,7 @@ export interface IStatusSummary {
hasMergeChanges
:
boolean
;
}
export
interface
IStatusModel
extends
EventEmitter
.
IEventEmitter
{
export
interface
IStatusModel
extends
IEventEmitter
{
getSummary
():
IStatusSummary
;
update
(
status
:
IRawFileStatus
[]):
void
;
getIndexStatus
():
IStatusGroup
;
...
...
@@ -130,7 +130,7 @@ export interface IStatusModel extends EventEmitter.IEventEmitter {
find
(
path
:
string
,
type
:
StatusType
):
IFileStatus
;
}
export
interface
IModel
extends
EventEmitter
.
IEventEmitter
{
export
interface
IModel
extends
IEventEmitter
{
getRepositoryRoot
():
string
;
getStatus
():
IStatusModel
;
getHEAD
():
IBranch
;
...
...
@@ -142,9 +142,9 @@ export interface IModel extends EventEmitter.IEventEmitter {
// Service operations
export
interface
IGitOperation
extends
Lifecycle
.
IDisposable
{
export
interface
IGitOperation
extends
IDisposable
{
id
:
string
;
run
():
WinJS
.
Promise
;
run
():
TPromise
<
any
>
;
}
// Service enums
...
...
@@ -260,56 +260,56 @@ export interface IPushOptions {
export
interface
IRawGitService
{
onOutput
:
Event
<
string
>
;
getVersion
():
WinJS
.
TPromise
<
string
>
;
serviceState
():
WinJS
.
TPromise
<
RawServiceState
>
;
status
():
WinJS
.
TPromise
<
IRawStatus
>
;
init
():
WinJS
.
TPromise
<
IRawStatus
>
;
add
(
filesPaths
?:
string
[]):
WinJS
.
TPromise
<
IRawStatus
>
;
stage
(
filePath
:
string
,
content
:
string
):
WinJS
.
TPromise
<
IRawStatus
>
;
branch
(
name
:
string
,
checkout
?:
boolean
):
WinJS
.
TPromise
<
IRawStatus
>
;
checkout
(
treeish
?:
string
,
filePaths
?:
string
[]):
WinJS
.
TPromise
<
IRawStatus
>
;
clean
(
filePaths
:
string
[]):
WinJS
.
TPromise
<
IRawStatus
>
;
undo
():
WinJS
.
TPromise
<
IRawStatus
>
;
reset
(
treeish
:
string
,
hard
?:
boolean
):
WinJS
.
TPromise
<
IRawStatus
>
;
revertFiles
(
treeish
:
string
,
filePaths
?:
string
[]):
WinJS
.
TPromise
<
IRawStatus
>
;
fetch
():
WinJS
.
TPromise
<
IRawStatus
>
;
pull
(
rebase
?:
boolean
):
WinJS
.
TPromise
<
IRawStatus
>
;
push
(
remote
?:
string
,
name
?:
string
,
options
?:
IPushOptions
):
WinJS
.
TPromise
<
IRawStatus
>
;
sync
():
WinJS
.
TPromise
<
IRawStatus
>
;
commit
(
message
:
string
,
amend
?:
boolean
,
stage
?:
boolean
):
WinJS
.
TPromise
<
IRawStatus
>
;
detectMimetypes
(
path
:
string
,
treeish
?:
string
):
WinJS
.
TPromise
<
string
[]
>
;
show
(
path
:
string
,
treeish
?:
string
):
WinJS
.
TPromise
<
string
>
;
getVersion
():
TPromise
<
string
>
;
serviceState
():
TPromise
<
RawServiceState
>
;
status
():
TPromise
<
IRawStatus
>
;
init
():
TPromise
<
IRawStatus
>
;
add
(
filesPaths
?:
string
[]):
TPromise
<
IRawStatus
>
;
stage
(
filePath
:
string
,
content
:
string
):
TPromise
<
IRawStatus
>
;
branch
(
name
:
string
,
checkout
?:
boolean
):
TPromise
<
IRawStatus
>
;
checkout
(
treeish
?:
string
,
filePaths
?:
string
[]):
TPromise
<
IRawStatus
>
;
clean
(
filePaths
:
string
[]):
TPromise
<
IRawStatus
>
;
undo
():
TPromise
<
IRawStatus
>
;
reset
(
treeish
:
string
,
hard
?:
boolean
):
TPromise
<
IRawStatus
>
;
revertFiles
(
treeish
:
string
,
filePaths
?:
string
[]):
TPromise
<
IRawStatus
>
;
fetch
():
TPromise
<
IRawStatus
>
;
pull
(
rebase
?:
boolean
):
TPromise
<
IRawStatus
>
;
push
(
remote
?:
string
,
name
?:
string
,
options
?:
IPushOptions
):
TPromise
<
IRawStatus
>
;
sync
():
TPromise
<
IRawStatus
>
;
commit
(
message
:
string
,
amend
?:
boolean
,
stage
?:
boolean
):
TPromise
<
IRawStatus
>
;
detectMimetypes
(
path
:
string
,
treeish
?:
string
):
TPromise
<
string
[]
>
;
show
(
path
:
string
,
treeish
?:
string
):
TPromise
<
string
>
;
}
export
var
GIT_SERVICE_ID
=
'
gitService
'
;
export
var
IGitService
=
createDecorator
<
IGitService
>
(
GIT_SERVICE_ID
);
export
interface
IGitService
extends
EventEmitter
.
IEventEmitter
{
export
interface
IGitService
extends
IEventEmitter
{
serviceId
:
ServiceIdentifier
<
any
>
;
onOutput
:
Event
<
string
>
;
status
():
WinJS
.
TPromise
<
IModel
>
;
init
():
WinJS
.
TPromise
<
IModel
>
;
add
(
files
?:
IFileStatus
[]):
WinJS
.
TPromise
<
IModel
>
;
stage
(
filePath
:
string
,
content
:
string
):
WinJS
.
TPromise
<
IModel
>
;
branch
(
name
:
string
,
checkout
?:
boolean
):
WinJS
.
TPromise
<
IModel
>
;
checkout
(
treeish
?:
string
,
files
?:
IFileStatus
[]):
WinJS
.
TPromise
<
IModel
>
;
clean
(
files
:
IFileStatus
[]):
WinJS
.
TPromise
<
IModel
>
;
undo
():
WinJS
.
TPromise
<
IModel
>
;
reset
(
treeish
:
string
,
hard
?:
boolean
):
WinJS
.
TPromise
<
IModel
>
;
revertFiles
(
treeish
:
string
,
files
?:
IFileStatus
[]):
WinJS
.
TPromise
<
IModel
>
;
fetch
():
WinJS
.
TPromise
<
IModel
>
;
pull
(
rebase
?:
boolean
):
WinJS
.
TPromise
<
IModel
>
;
push
(
remote
?:
string
,
name
?:
string
,
options
?:
IPushOptions
):
WinJS
.
TPromise
<
IModel
>
;
sync
():
WinJS
.
TPromise
<
IModel
>
;
commit
(
message
:
string
,
amend
?:
boolean
,
stage
?:
boolean
):
WinJS
.
TPromise
<
IModel
>
;
detectMimetypes
(
path
:
string
,
treeish
?:
string
):
WinJS
.
Promise
;
buffer
(
path
:
string
,
treeish
?:
string
):
WinJS
.
TPromise
<
string
>
;
status
():
TPromise
<
IModel
>
;
init
():
TPromise
<
IModel
>
;
add
(
files
?:
IFileStatus
[]):
TPromise
<
IModel
>
;
stage
(
filePath
:
string
,
content
:
string
):
TPromise
<
IModel
>
;
branch
(
name
:
string
,
checkout
?:
boolean
):
TPromise
<
IModel
>
;
checkout
(
treeish
?:
string
,
files
?:
IFileStatus
[]):
TPromise
<
IModel
>
;
clean
(
files
:
IFileStatus
[]):
TPromise
<
IModel
>
;
undo
():
TPromise
<
IModel
>
;
reset
(
treeish
:
string
,
hard
?:
boolean
):
TPromise
<
IModel
>
;
revertFiles
(
treeish
:
string
,
files
?:
IFileStatus
[]):
TPromise
<
IModel
>
;
fetch
():
TPromise
<
IModel
>
;
pull
(
rebase
?:
boolean
):
TPromise
<
IModel
>
;
push
(
remote
?:
string
,
name
?:
string
,
options
?:
IPushOptions
):
TPromise
<
IModel
>
;
sync
():
TPromise
<
IModel
>
;
commit
(
message
:
string
,
amend
?:
boolean
,
stage
?:
boolean
):
TPromise
<
IModel
>
;
detectMimetypes
(
path
:
string
,
treeish
?:
string
):
TPromise
<
string
[]
>
;
buffer
(
path
:
string
,
treeish
?:
string
):
TPromise
<
string
>
;
getState
():
ServiceState
;
getModel
():
IModel
;
show
(
path
:
string
,
status
:
IFileStatus
,
treeish
?:
string
,
mimetype
?:
string
):
WinJS
.
Promise
;
getInput
(
status
:
IFileStatus
):
WinJS
.
TPromise
<
WorkbenchEditorCommon
.
EditorInput
>
;
show
(
path
:
string
,
status
:
IFileStatus
,
treeish
?:
string
,
mimetype
?:
string
):
TPromise
<
string
>
;
getInput
(
status
:
IFileStatus
):
TPromise
<
EditorInput
>
;
isInitialized
():
boolean
;
isIdle
():
boolean
;
getRunningOperations
():
IGitOperation
[];
...
...
@@ -317,7 +317,7 @@ export interface IGitService extends EventEmitter.IEventEmitter {
}
export
interface
IAskpassService
{
askpass
(
id
:
string
,
host
:
string
,
command
:
string
):
WinJS
.
TPromise
<
ICredentials
>
;
askpass
(
id
:
string
,
host
:
string
,
command
:
string
):
TPromise
<
ICredentials
>
;
}
// Utils
...
...
src/vs/workbench/parts/git/common/gitModel.ts
浏览文件 @
28a78cba
...
...
@@ -4,12 +4,15 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
Lifecycle
=
require
(
'
vs/base/common/lifecycle
'
);
import
Strings
=
require
(
'
vs/base/common/strings
'
);
import
EventEmitter
=
require
(
'
vs/base/common/eventEmitter
'
);
import
Git
=
require
(
'
vs/workbench/parts/git/common/git
'
);
import
{
IDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
{
format
}
from
'
vs/base/common/strings
'
;
import
{
EventEmitter
}
from
'
vs/base/common/eventEmitter
'
;
import
{
IStatusModel
,
IStatusSummary
,
IRawFileStatus
,
ModelEvents
,
IFileStatus
,
IStatusGroup
,
Status
,
StatusType
,
IBranch
,
IRef
,
IRemote
,
IModel
,
IRawStatus
}
from
'
vs/workbench/parts/git/common/git
'
;
export
class
FileStatus
implements
Git
.
IFileStatus
{
export
class
FileStatus
implements
IFileStatus
{
private
id
:
string
;
private
pathComponents
:
string
[];
...
...
@@ -17,7 +20,7 @@ export class FileStatus implements Git.IFileStatus {
constructor
(
private
path
:
string
,
private
mimetype
:
string
,
private
status
:
Git
.
Status
,
private
status
:
Status
,
private
rename
?:
string
,
isModifiedInIndex
?:
boolean
)
{
...
...
@@ -25,60 +28,60 @@ export class FileStatus implements Git.IFileStatus {
this
.
pathComponents
=
path
.
split
(
'
/
'
);
}
public
getPath
():
string
{
getPath
():
string
{
return
this
.
path
;
}
public
getPathComponents
():
string
[]
{
getPathComponents
():
string
[]
{
return
this
.
pathComponents
.
slice
(
0
);
}
public
getMimetype
():
string
{
getMimetype
():
string
{
return
this
.
mimetype
;
}
public
getStatus
():
Git
.
Status
{
getStatus
():
Status
{
return
this
.
status
;
}
public
getRename
():
string
{
getRename
():
string
{
return
this
.
rename
;
}
public
getId
():
string
{
getId
():
string
{
return
this
.
id
;
}
public
getType
():
Git
.
StatusType
{
getType
():
StatusType
{
switch
(
FileStatus
.
typeOf
(
this
.
status
))
{
case
'
index
'
:
return
Git
.
StatusType
.
INDEX
;
case
'
workingTree
'
:
return
Git
.
StatusType
.
WORKING_TREE
;
default
:
return
Git
.
StatusType
.
MERGE
;
case
'
index
'
:
return
StatusType
.
INDEX
;
case
'
workingTree
'
:
return
StatusType
.
WORKING_TREE
;
default
:
return
StatusType
.
MERGE
;
}
}
public
clone
():
Git
.
IFileStatus
{
clone
():
IFileStatus
{
return
new
FileStatus
(
this
.
path
,
this
.
mimetype
,
this
.
status
,
this
.
rename
);
}
public
update
(
other
:
FileStatus
):
void
{
update
(
other
:
FileStatus
):
void
{
this
.
status
=
other
.
getStatus
();
this
.
rename
=
other
.
getRename
();
}
static
typeOf
(
s
:
Git
.
Status
):
string
{
static
typeOf
(
s
:
Status
):
string
{
switch
(
s
)
{
case
Git
.
Status
.
INDEX_MODIFIED
:
case
Git
.
Status
.
INDEX_ADDED
:
case
Git
.
Status
.
INDEX_DELETED
:
case
Git
.
Status
.
INDEX_RENAMED
:
case
Git
.
Status
.
INDEX_COPIED
:
case
Status
.
INDEX_MODIFIED
:
case
Status
.
INDEX_ADDED
:
case
Status
.
INDEX_DELETED
:
case
Status
.
INDEX_RENAMED
:
case
Status
.
INDEX_COPIED
:
return
'
index
'
;
case
Git
.
Status
.
MODIFIED
:
case
Git
.
Status
.
DELETED
:
case
Git
.
Status
.
UNTRACKED
:
case
Git
.
Status
.
IGNORED
:
case
Status
.
MODIFIED
:
case
Status
.
DELETED
:
case
Status
.
UNTRACKED
:
case
Status
.
IGNORED
:
return
'
workingTree
'
;
default
:
...
...
@@ -88,18 +91,18 @@ export class FileStatus implements Git.IFileStatus {
}
interface
IStatusSet
{
[
path
:
string
]:
Git
.
IFileStatus
;
[
path
:
string
]:
IFileStatus
;
}
export
class
StatusGroup
extends
EventEmitter
.
EventEmitter
implements
Git
.
IStatusGroup
{
export
class
StatusGroup
extends
EventEmitter
implements
IStatusGroup
{
private
type
:
Git
.
StatusType
;
private
type
:
StatusType
;
private
statusSet
:
IStatusSet
;
private
statusList
:
Git
.
IFileStatus
[];
private
statusList
:
IFileStatus
[];
private
statusByName
:
IStatusSet
;
private
statusByRename
:
IStatusSet
;
constructor
(
type
:
Git
.
StatusType
)
{
constructor
(
type
:
StatusType
)
{
super
();
this
.
type
=
type
;
...
...
@@ -109,15 +112,15 @@ export class StatusGroup extends EventEmitter.EventEmitter implements Git.IStatu
this
.
statusByRename
=
Object
.
create
(
null
);
}
public
getType
():
Git
.
StatusType
{
getType
():
StatusType
{
return
this
.
type
;
}
public
update
(
statusList
:
FileStatus
[]):
void
{
update
(
statusList
:
FileStatus
[]):
void
{
var
toDelete
:
IStatusSet
=
Object
.
create
(
null
);
var
id
:
string
,
path
:
string
,
rename
:
string
;
var
status
:
Git
.
IFileStatus
;
var
status
:
IFileStatus
;
for
(
id
in
this
.
statusSet
)
{
toDelete
[
id
]
=
this
.
statusSet
[
id
];
...
...
@@ -161,15 +164,15 @@ export class StatusGroup extends EventEmitter.EventEmitter implements Git.IStatu
}
}
public
all
():
Git
.
IFileStatus
[]
{
all
():
IFileStatus
[]
{
return
this
.
statusList
;
}
public
find
(
path
:
string
):
Git
.
IFileStatus
{
find
(
path
:
string
):
IFileStatus
{
return
this
.
statusByName
[
path
]
||
this
.
statusByRename
[
path
]
||
null
;
}
public
dispose
():
void
{
dispose
():
void
{
this
.
type
=
null
;
this
.
statusSet
=
null
;
this
.
statusList
=
null
;
...
...
@@ -180,19 +183,19 @@ export class StatusGroup extends EventEmitter.EventEmitter implements Git.IStatu
}
}
export
class
StatusModel
extends
EventEmitter
.
EventEmitter
implements
Git
.
IStatusModel
{
export
class
StatusModel
extends
EventEmitter
implements
IStatusModel
{
private
indexStatus
:
StatusGroup
;
private
workingTreeStatus
:
StatusGroup
;
private
mergeStatus
:
StatusGroup
;
private
toDispose
:
Lifecycle
.
IDisposable
[];
private
toDispose
:
IDisposable
[];
constructor
()
{
super
();
this
.
indexStatus
=
new
StatusGroup
(
Git
.
StatusType
.
INDEX
);
this
.
workingTreeStatus
=
new
StatusGroup
(
Git
.
StatusType
.
WORKING_TREE
);
this
.
mergeStatus
=
new
StatusGroup
(
Git
.
StatusType
.
MERGE
);
this
.
indexStatus
=
new
StatusGroup
(
StatusType
.
INDEX
);
this
.
workingTreeStatus
=
new
StatusGroup
(
StatusType
.
WORKING_TREE
);
this
.
mergeStatus
=
new
StatusGroup
(
StatusType
.
MERGE
);
this
.
toDispose
=
[
this
.
addEmitter2
(
this
.
indexStatus
),
...
...
@@ -201,7 +204,7 @@ export class StatusModel extends EventEmitter.EventEmitter implements Git.IStatu
];
}
public
getSummary
():
Git
.
IStatusSummary
{
getSummary
():
IStatusSummary
{
return
{
hasWorkingTreeChanges
:
this
.
getWorkingTreeStatus
().
all
().
length
>
0
,
hasIndexChanges
:
this
.
getIndexStatus
().
all
().
length
>
0
,
...
...
@@ -209,37 +212,37 @@ export class StatusModel extends EventEmitter.EventEmitter implements Git.IStatu
};
}
public
update
(
status
:
Git
.
IRawFileStatus
[]):
void
{
update
(
status
:
IRawFileStatus
[]):
void
{
var
index
:
FileStatus
[]
=
[];
var
workingTree
:
FileStatus
[]
=
[];
var
merge
:
FileStatus
[]
=
[];
status
.
forEach
(
raw
=>
{
switch
(
raw
.
x
+
raw
.
y
)
{
case
'
??
'
:
return
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
UNTRACKED
));
case
'
!!
'
:
return
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
IGNORED
));
case
'
DD
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
BOTH_DELETED
));
case
'
AU
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
ADDED_BY_US
));
case
'
UD
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
DELETED_BY_THEM
));
case
'
UA
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
ADDED_BY_THEM
));
case
'
DU
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
DELETED_BY_US
));
case
'
AA
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
BOTH_ADDED
));
case
'
UU
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
BOTH_MODIFIED
));
case
'
??
'
:
return
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
UNTRACKED
));
case
'
!!
'
:
return
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
IGNORED
));
case
'
DD
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
BOTH_DELETED
));
case
'
AU
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
ADDED_BY_US
));
case
'
UD
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
DELETED_BY_THEM
));
case
'
UA
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
ADDED_BY_THEM
));
case
'
DU
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
DELETED_BY_US
));
case
'
AA
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
BOTH_ADDED
));
case
'
UU
'
:
return
merge
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
BOTH_MODIFIED
));
}
let
isModifiedInIndex
=
false
;
switch
(
raw
.
x
)
{
case
'
M
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
INDEX_MODIFIED
));
isModifiedInIndex
=
true
;
break
;
case
'
A
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
INDEX_ADDED
));
break
;
case
'
D
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
INDEX_DELETED
));
break
;
case
'
R
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
INDEX_RENAMED
,
raw
.
rename
));
break
;
case
'
C
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
INDEX_COPIED
));
break
;
case
'
M
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
INDEX_MODIFIED
));
isModifiedInIndex
=
true
;
break
;
case
'
A
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
INDEX_ADDED
));
break
;
case
'
D
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
INDEX_DELETED
));
break
;
case
'
R
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
INDEX_RENAMED
,
raw
.
rename
));
break
;
case
'
C
'
:
index
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
INDEX_COPIED
));
break
;
}
switch
(
raw
.
y
)
{
case
'
M
'
:
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
MODIFIED
,
raw
.
rename
,
isModifiedInIndex
));
break
;
case
'
D
'
:
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Git
.
Status
.
DELETED
,
raw
.
rename
));
break
;
case
'
M
'
:
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
MODIFIED
,
raw
.
rename
,
isModifiedInIndex
));
break
;
case
'
D
'
:
workingTree
.
push
(
new
FileStatus
(
raw
.
path
,
raw
.
mimetype
,
Status
.
DELETED
,
raw
.
rename
));
break
;
}
});
...
...
@@ -247,34 +250,34 @@ export class StatusModel extends EventEmitter.EventEmitter implements Git.IStatu
this
.
workingTreeStatus
.
update
(
workingTree
);
this
.
mergeStatus
.
update
(
merge
);
this
.
emit
(
Git
.
ModelEvents
.
STATUS_MODEL_UPDATED
);
this
.
emit
(
ModelEvents
.
STATUS_MODEL_UPDATED
);
}
public
getIndexStatus
():
Git
.
IStatusGroup
{
getIndexStatus
():
IStatusGroup
{
return
this
.
indexStatus
;
}
public
getWorkingTreeStatus
():
Git
.
IStatusGroup
{
getWorkingTreeStatus
():
IStatusGroup
{
return
this
.
workingTreeStatus
;
}
public
getMergeStatus
():
Git
.
IStatusGroup
{
getMergeStatus
():
IStatusGroup
{
return
this
.
mergeStatus
;
}
public
getGroups
():
Git
.
IStatusGroup
[]
{
getGroups
():
IStatusGroup
[]
{
return
[
this
.
mergeStatus
,
this
.
indexStatus
,
this
.
workingTreeStatus
];
}
public
find
(
path
:
string
,
type
:
Git
.
StatusType
):
Git
.
IFileStatus
{
var
group
:
Git
.
IStatusGroup
;
find
(
path
:
string
,
type
:
StatusType
):
IFileStatus
{
var
group
:
IStatusGroup
;
switch
(
type
)
{
case
Git
.
StatusType
.
INDEX
:
case
StatusType
.
INDEX
:
group
=
this
.
indexStatus
;
break
;
case
Git
.
StatusType
.
WORKING_TREE
:
case
StatusType
.
WORKING_TREE
:
group
=
this
.
workingTreeStatus
;
break
;
case
Git
.
StatusType
.
MERGE
:
case
StatusType
.
MERGE
:
group
=
this
.
mergeStatus
;
break
;
default
:
return
null
;
...
...
@@ -283,8 +286,8 @@ export class StatusModel extends EventEmitter.EventEmitter implements Git.IStatu
return
group
.
find
(
path
);
}
public
dispose
():
void
{
this
.
toDispose
=
Lifecycle
.
dispose
(
this
.
toDispose
);
dispose
():
void
{
this
.
toDispose
=
dispose
(
this
.
toDispose
);
if
(
this
.
indexStatus
)
{
this
.
indexStatus
.
dispose
();
...
...
@@ -305,14 +308,14 @@ export class StatusModel extends EventEmitter.EventEmitter implements Git.IStatu
}
}
export
class
Model
extends
EventEmitter
.
EventEmitter
implements
Git
.
IModel
{
export
class
Model
extends
EventEmitter
implements
IModel
{
private
repositoryRoot
:
string
;
private
status
:
Git
.
IStatusModel
;
private
HEAD
:
Git
.
IBranch
;
private
refs
:
Git
.
IRef
[];
private
remotes
:
Git
.
IRemote
[];
private
toDispose
:
Lifecycle
.
IDisposable
[];
private
status
:
IStatusModel
;
private
HEAD
:
IBranch
;
private
refs
:
IRef
[];
private
remotes
:
IRemote
[];
private
toDispose
:
IDisposable
[];
constructor
()
{
super
();
...
...
@@ -328,27 +331,27 @@ export class Model extends EventEmitter.EventEmitter implements Git.IModel {
this
.
remotes
=
[];
}
public
getRepositoryRoot
():
string
{
getRepositoryRoot
():
string
{
return
this
.
repositoryRoot
;
}
public
getStatus
():
Git
.
IStatusModel
{
getStatus
():
IStatusModel
{
return
this
.
status
;
}
public
getHEAD
():
Git
.
IBranch
{
getHEAD
():
IBranch
{
return
this
.
HEAD
;
}
public
getRefs
():
Git
.
IRef
[]
{
getRefs
():
IRef
[]
{
return
this
.
refs
;
}
public
getRemotes
():
Git
.
IRemote
[]
{
getRemotes
():
IRemote
[]
{
return
this
.
remotes
;
}
public
update
(
status
:
Git
.
IRawStatus
):
void
{
update
(
status
:
IRawStatus
):
void
{
if
(
!
status
)
{
status
=
{
repositoryRoot
:
null
,
...
...
@@ -363,18 +366,18 @@ export class Model extends EventEmitter.EventEmitter implements Git.IModel {
this
.
status
.
update
(
status
.
status
);
this
.
HEAD
=
status
.
HEAD
;
this
.
emit
(
Git
.
ModelEvents
.
HEAD_UPDATED
);
this
.
emit
(
ModelEvents
.
HEAD_UPDATED
);
this
.
refs
=
status
.
refs
;
this
.
emit
(
Git
.
ModelEvents
.
REFS_UPDATED
);
this
.
emit
(
ModelEvents
.
REFS_UPDATED
);
this
.
remotes
=
status
.
remotes
;
this
.
emit
(
Git
.
ModelEvents
.
REMOTES_UPDATED
);
this
.
emit
(
ModelEvents
.
REMOTES_UPDATED
);
this
.
emit
(
Git
.
ModelEvents
.
MODEL_UPDATED
);
this
.
emit
(
ModelEvents
.
MODEL_UPDATED
);
}
public
getStatusSummary
():
Git
.
IStatusSummary
{
getStatusSummary
():
IStatusSummary
{
var
status
=
this
.
getStatus
();
return
{
...
...
@@ -384,7 +387,7 @@ export class Model extends EventEmitter.EventEmitter implements Git.IModel {
};
}
public
getPS1
():
string
{
getPS1
():
string
{
if
(
!
this
.
HEAD
)
{
return
''
;
}
...
...
@@ -392,7 +395,7 @@ export class Model extends EventEmitter.EventEmitter implements Git.IModel {
var
label
=
this
.
HEAD
.
name
||
this
.
HEAD
.
commit
.
substr
(
0
,
8
);
var
statusSummary
=
this
.
getStatus
().
getSummary
();
return
Strings
.
format
(
'
{0}{1}{2}{3}
'
,
return
format
(
'
{0}{1}{2}{3}
'
,
label
,
statusSummary
.
hasWorkingTreeChanges
?
'
*
'
:
''
,
statusSummary
.
hasIndexChanges
?
'
+
'
:
''
,
...
...
@@ -400,8 +403,8 @@ export class Model extends EventEmitter.EventEmitter implements Git.IModel {
);
}
public
dispose
():
void
{
this
.
toDispose
=
Lifecycle
.
dispose
(
this
.
toDispose
);
dispose
():
void
{
this
.
toDispose
=
dispose
(
this
.
toDispose
);
super
.
dispose
();
}
}
src/vs/workbench/parts/git/common/noopGitService.ts
浏览文件 @
28a78cba
...
...
@@ -4,18 +4,18 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
git
=
require
(
'
vs/workbench/parts/git/common/git
'
)
;
import
{
IRawGitService
,
IRawStatus
,
ServiceState
,
RawServiceState
}
from
'
vs/workbench/parts/git/common/git
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
export
class
NoOpGitService
implements
git
.
IRawGitService
{
export
class
NoOpGitService
implements
IRawGitService
{
private
_onOutput
=
new
Emitter
<
string
>
();
get
onOutput
():
Event
<
string
>
{
return
this
.
_onOutput
.
event
;
}
private
static
STATUS
:
git
.
IRawStatus
=
{
private
static
STATUS
:
IRawStatus
=
{
repositoryRoot
:
null
,
state
:
git
.
ServiceState
.
NotAWorkspace
,
state
:
ServiceState
.
NotAWorkspace
,
status
:
[],
HEAD
:
null
,
refs
:
[],
...
...
@@ -26,67 +26,67 @@ export class NoOpGitService implements git.IRawGitService {
return
TPromise
.
as
(
null
);
}
serviceState
():
TPromise
<
git
.
RawServiceState
>
{
return
TPromise
.
as
(
git
.
RawServiceState
.
OK
);
serviceState
():
TPromise
<
RawServiceState
>
{
return
TPromise
.
as
(
RawServiceState
.
OK
);
}
status
():
TPromise
<
git
.
IRawStatus
>
{
status
():
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
init
():
TPromise
<
git
.
IRawStatus
>
{
init
():
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
add
(
filesPaths
?:
string
[]):
TPromise
<
git
.
IRawStatus
>
{
add
(
filesPaths
?:
string
[]):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
stage
(
filePath
:
string
,
content
:
string
):
TPromise
<
git
.
IRawStatus
>
{
stage
(
filePath
:
string
,
content
:
string
):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
branch
(
name
:
string
,
checkout
?:
boolean
):
TPromise
<
git
.
IRawStatus
>
{
branch
(
name
:
string
,
checkout
?:
boolean
):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
checkout
(
treeish
?:
string
,
filePaths
?:
string
[]):
TPromise
<
git
.
IRawStatus
>
{
checkout
(
treeish
?:
string
,
filePaths
?:
string
[]):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
clean
(
filePaths
:
string
[]):
TPromise
<
git
.
IRawStatus
>
{
clean
(
filePaths
:
string
[]):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
undo
():
TPromise
<
git
.
IRawStatus
>
{
undo
():
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
reset
(
treeish
:
string
,
hard
?:
boolean
):
TPromise
<
git
.
IRawStatus
>
{
reset
(
treeish
:
string
,
hard
?:
boolean
):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
revertFiles
(
treeish
:
string
,
filePaths
?:
string
[]):
TPromise
<
git
.
IRawStatus
>
{
revertFiles
(
treeish
:
string
,
filePaths
?:
string
[]):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
fetch
():
TPromise
<
git
.
IRawStatus
>
{
fetch
():
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
pull
(
rebase
?:
boolean
):
TPromise
<
git
.
IRawStatus
>
{
pull
(
rebase
?:
boolean
):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
push
():
TPromise
<
git
.
IRawStatus
>
{
push
():
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
sync
():
TPromise
<
git
.
IRawStatus
>
{
sync
():
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
commit
(
message
:
string
,
amend
?:
boolean
,
stage
?:
boolean
):
TPromise
<
git
.
IRawStatus
>
{
commit
(
message
:
string
,
amend
?:
boolean
,
stage
?:
boolean
):
TPromise
<
IRawStatus
>
{
return
TPromise
.
as
(
NoOpGitService
.
STATUS
);
}
...
...
src/vs/workbench/parts/git/node/git.lib.ts
浏览文件 @
28a78cba
...
...
@@ -4,17 +4,16 @@
*--------------------------------------------------------------------------------------------*/
import
{
Promise
,
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
extfs
=
require
(
'
vs/base/node/extfs
'
)
;
import
{
del
}
from
'
vs/base/node/extfs
'
;
import
{
guessMimeTypes
,
isBinaryMime
}
from
'
vs/base/common/mime
'
;
import
{
IDisposable
,
toDisposable
,
dispose
}
from
'
vs/base/common/lifecycle
'
;
import
objects
=
require
(
'
vs/base/common/objects
'
);
import
uuid
=
require
(
'
vs/base/common/uuid
'
);
import
nls
=
require
(
'
vs/nls
'
);
import
strings
=
require
(
'
vs/base/common/strings
'
);
import
{
assign
}
from
'
vs/base/common/objects
'
;
import
{
v4
as
UUIDv4
}
from
'
vs/base/common/uuid
'
;
import
{
localize
}
from
'
vs/nls
'
;
import
{
uniqueFilter
}
from
'
vs/base/common/arrays
'
;
import
{
IRawFileStatus
,
RefType
,
IRef
,
IBranch
,
IRemote
,
GitErrorCodes
,
IPushOptions
}
from
'
vs/workbench/parts/git/common/git
'
;
import
{
detectMimesFromStream
}
from
'
vs/base/node/mime
'
;
import
files
=
require
(
'
vs/platform/files/common/files
'
)
;
import
{
IFileOperationResult
,
FileOperationResult
}
from
'
vs/platform/files/common/files
'
;
import
{
spawn
,
ChildProcess
}
from
'
child_process
'
;
import
{
decode
,
encodingExists
}
from
'
vs/base/node/encoding
'
;
...
...
@@ -75,13 +74,13 @@ export interface IGitErrorData {
export
class
GitError
{
public
error
:
Error
;
public
message
:
string
;
public
stdout
:
string
;
public
stderr
:
string
;
public
exitCode
:
number
;
public
gitErrorCode
:
string
;
public
gitCommand
:
string
;
error
:
Error
;
message
:
string
;
stdout
:
string
;
stderr
:
string
;
exitCode
:
number
;
gitErrorCode
:
string
;
gitCommand
:
string
;
constructor
(
data
:
IGitErrorData
)
{
if
(
data
.
error
)
{
...
...
@@ -99,7 +98,7 @@ export class GitError {
this
.
gitCommand
=
data
.
gitCommand
||
null
;
}
public
toString
():
string
{
toString
():
string
{
let
result
=
this
.
message
+
'
'
+
JSON
.
stringify
({
exitCode
:
this
.
exitCode
,
gitErrorCode
:
this
.
gitErrorCode
,
...
...
@@ -126,9 +125,9 @@ export interface IGitOptions {
export
class
Git
{
public
gitPath
:
string
;
public
version
:
string
;
public
env
:
any
;
gitPath
:
string
;
version
:
string
;
env
:
any
;
private
tmpPath
:
string
;
private
defaultEncoding
:
string
;
private
outputListeners
:
{
(
output
:
string
):
void
;
}[];
...
...
@@ -145,27 +144,27 @@ export class Git {
this
.
outputListeners
=
[];
}
public
run
(
cwd
:
string
,
args
:
string
[],
options
:
any
=
{}):
TPromise
<
IExecutionResult
>
{
options
=
objects
.
assign
({
cwd
:
cwd
},
options
||
{});
run
(
cwd
:
string
,
args
:
string
[],
options
:
any
=
{}):
TPromise
<
IExecutionResult
>
{
options
=
assign
({
cwd
:
cwd
},
options
||
{});
return
this
.
exec
(
args
,
options
);
}
public
stream
(
cwd
:
string
,
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
options
=
objects
.
assign
({
cwd
:
cwd
},
options
||
{});
stream
(
cwd
:
string
,
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
options
=
assign
({
cwd
:
cwd
},
options
||
{});
return
this
.
spawn
(
args
,
options
);
}
public
open
(
repository
:
string
,
env
:
any
=
{}):
Repository
{
open
(
repository
:
string
,
env
:
any
=
{}):
Repository
{
return
new
Repository
(
this
,
repository
,
this
.
defaultEncoding
,
env
);
}
public
clone
(
repository
:
string
,
repoURL
:
string
):
TPromise
<
boolean
>
{
clone
(
repository
:
string
,
repoURL
:
string
):
TPromise
<
boolean
>
{
return
this
.
exec
([
'
clone
'
,
repoURL
,
repository
]).
then
(()
=>
true
,
(
err
)
=>
{
return
new
TPromise
<
boolean
>
((
c
,
e
)
=>
{
// If there's any error, git will still leave the folder in the FS,
// so we need to remove it.
extfs
.
del
(
repository
,
this
.
tmpPath
,
(
err
)
=>
{
del
(
repository
,
this
.
tmpPath
,
(
err
)
=>
{
if
(
err
)
{
return
e
(
err
);
}
c
(
true
);
});
...
...
@@ -173,7 +172,7 @@ export class Git {
});
}
public
config
(
name
:
string
,
value
:
string
):
Promise
{
config
(
name
:
string
,
value
:
string
):
Promise
{
return
this
.
exec
([
'
config
'
,
'
--global
'
,
name
,
value
]);
}
...
...
@@ -220,7 +219,7 @@ export class Git {
});
}
public
spawn
(
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
spawn
(
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
if
(
!
this
.
gitPath
)
{
throw
new
Error
(
'
git could not be found in the system.
'
);
}
...
...
@@ -233,22 +232,22 @@ export class Git {
options
.
stdio
=
[
'
ignore
'
,
null
,
null
];
// Unless provided, ignore stdin and leave default streams for stdout and stderr
}
options
.
env
=
objects
.
assign
({},
options
.
env
||
{});
options
.
env
=
objects
.
assign
(
options
.
env
,
this
.
env
);
options
.
env
=
objects
.
assign
(
options
.
env
,
{
MONACO_REQUEST_GUID
:
uuid
.
v4
().
asHex
(),
VSCODE_GIT_REQUEST_ID
:
uuid
.
v4
().
asHex
(),
options
.
env
=
assign
({},
options
.
env
||
{});
options
.
env
=
assign
(
options
.
env
,
this
.
env
);
options
.
env
=
assign
(
options
.
env
,
{
MONACO_REQUEST_GUID
:
UUID
v4
().
asHex
(),
VSCODE_GIT_REQUEST_ID
:
UUID
v4
().
asHex
(),
MONACO_GIT_COMMAND
:
args
[
0
]
});
if
(
options
.
log
!==
false
)
{
this
.
log
(
strings
.
format
(
'
git {0}
\n
'
,
args
.
join
(
'
'
))
);
this
.
log
(
`git
${
args
.
join
(
'
'
)
}
\n`
);
}
return
spawn
(
this
.
gitPath
,
args
,
options
);
}
public
onOutput
(
listener
:
(
output
:
string
)
=>
void
):
()
=>
void
{
onOutput
(
listener
:
(
output
:
string
)
=>
void
):
()
=>
void
{
this
.
outputListeners
.
push
(
listener
);
return
()
=>
this
.
outputListeners
.
splice
(
this
.
outputListeners
.
indexOf
(
listener
),
1
);
}
...
...
@@ -272,40 +271,40 @@ export class Repository {
this
.
env
=
env
;
}
public
get
version
():
string
{
get
version
():
string
{
return
this
.
git
.
version
;
}
public
get
path
():
string
{
get
path
():
string
{
return
this
.
repository
;
}
public
run
(
args
:
string
[],
options
:
any
=
{}):
TPromise
<
IExecutionResult
>
{
options
.
env
=
objects
.
assign
({},
options
.
env
||
{});
options
.
env
=
objects
.
assign
(
options
.
env
,
this
.
env
);
run
(
args
:
string
[],
options
:
any
=
{}):
TPromise
<
IExecutionResult
>
{
options
.
env
=
assign
({},
options
.
env
||
{});
options
.
env
=
assign
(
options
.
env
,
this
.
env
);
return
this
.
git
.
run
(
this
.
repository
,
args
,
options
);
}
public
stream
(
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
options
.
env
=
objects
.
assign
({},
options
.
env
||
{});
options
.
env
=
objects
.
assign
(
options
.
env
,
this
.
env
);
stream
(
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
options
.
env
=
assign
({},
options
.
env
||
{});
options
.
env
=
assign
(
options
.
env
,
this
.
env
);
return
this
.
git
.
stream
(
this
.
repository
,
args
,
options
);
}
public
spawn
(
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
options
.
env
=
objects
.
assign
({},
options
.
env
||
{});
options
.
env
=
objects
.
assign
(
options
.
env
,
this
.
env
);
spawn
(
args
:
string
[],
options
:
any
=
{}):
ChildProcess
{
options
.
env
=
assign
({},
options
.
env
||
{});
options
.
env
=
assign
(
options
.
env
,
this
.
env
);
return
this
.
git
.
spawn
(
args
,
options
);
}
public
init
():
Promise
{
init
():
Promise
{
return
this
.
run
([
'
init
'
]);
}
public
config
(
scope
:
string
,
key
:
string
,
value
:
any
,
options
:
any
):
TPromise
<
string
>
{
config
(
scope
:
string
,
key
:
string
,
value
:
any
,
options
:
any
):
TPromise
<
string
>
{
const
args
=
[
'
config
'
];
if
(
scope
)
{
...
...
@@ -321,11 +320,11 @@ export class Repository {
return
this
.
run
(
args
,
options
).
then
((
result
)
=>
result
.
stdout
);
}
public
show
(
object
:
string
):
ChildProcess
{
show
(
object
:
string
):
ChildProcess
{
return
this
.
stream
([
'
show
'
,
object
]);
}
public
buffer
(
object
:
string
):
TPromise
<
string
>
{
buffer
(
object
:
string
):
TPromise
<
string
>
{
const
child
=
this
.
show
(
object
);
return
new
Promise
((
c
,
e
)
=>
{
...
...
@@ -333,9 +332,9 @@ export class Repository {
if
(
err
)
{
e
(
err
);
}
else
if
(
isBinaryMime
(
result
.
mimes
))
{
e
(
<
files
.
IFileOperationResult
>
{
message
:
nls
.
localize
(
'
fileBinaryError
'
,
"
File seems to be binary and cannot be opened as text
"
),
fileOperationResult
:
files
.
FileOperationResult
.
FILE_IS_BINARY
e
(
<
IFileOperationResult
>
{
message
:
localize
(
'
fileBinaryError
'
,
"
File seems to be binary and cannot be opened as text
"
),
fileOperationResult
:
FileOperationResult
.
FILE_IS_BINARY
});
}
else
{
c
(
this
.
doBuffer
(
object
));
...
...
@@ -359,7 +358,7 @@ export class Repository {
});
}
public
add
(
paths
:
string
[]):
Promise
{
add
(
paths
:
string
[]):
Promise
{
const
args
=
[
'
add
'
,
'
-A
'
,
'
--
'
];
if
(
paths
&&
paths
.
length
)
{
...
...
@@ -371,7 +370,7 @@ export class Repository {
return
this
.
run
(
args
);
}
public
stage
(
path
:
string
,
data
:
string
):
Promise
{
stage
(
path
:
string
,
data
:
string
):
Promise
{
const
child
=
this
.
stream
([
'
hash-object
'
,
'
--stdin
'
,
'
-w
'
],
{
stdio
:
[
null
,
null
,
null
]
});
child
.
stdin
.
end
(
data
,
'
utf8
'
);
...
...
@@ -387,7 +386,7 @@ export class Repository {
});
}
public
checkout
(
treeish
:
string
,
paths
:
string
[]):
Promise
{
checkout
(
treeish
:
string
,
paths
:
string
[]):
Promise
{
const
args
=
[
'
checkout
'
,
'
-q
'
];
if
(
treeish
)
{
...
...
@@ -408,7 +407,7 @@ export class Repository {
});
}
public
commit
(
message
:
string
,
all
:
boolean
,
amend
:
boolean
):
Promise
{
commit
(
message
:
string
,
all
:
boolean
,
amend
:
boolean
):
Promise
{
const
args
=
[
'
commit
'
,
'
--quiet
'
,
'
--allow-empty-message
'
,
'
--file
'
,
'
-
'
];
if
(
all
)
{
...
...
@@ -439,17 +438,17 @@ export class Repository {
});
}
public
branch
(
name
:
string
,
checkout
:
boolean
):
Promise
{
branch
(
name
:
string
,
checkout
:
boolean
):
Promise
{
const
args
=
checkout
?
[
'
checkout
'
,
'
-q
'
,
'
-b
'
,
name
]
:
[
'
branch
'
,
'
-q
'
,
name
];
return
this
.
run
(
args
);
}
public
clean
(
paths
:
string
[]):
Promise
{
clean
(
paths
:
string
[]):
Promise
{
const
args
=
[
'
clean
'
,
'
-f
'
,
'
-q
'
,
'
--
'
].
concat
(
paths
);
return
this
.
run
(
args
);
}
public
undo
():
Promise
{
undo
():
Promise
{
return
this
.
run
([
'
clean
'
,
'
-fd
'
]).
then
(()
=>
{
return
this
.
run
([
'
checkout
'
,
'
--
'
,
'
.
'
]).
then
(
null
,
(
err
:
GitError
)
=>
{
if
(
/did not match any file
\(
s
\)
known to git
\.
/
.
test
(
err
.
stderr
))
{
...
...
@@ -461,7 +460,7 @@ export class Repository {
});
}
public
reset
(
treeish
:
string
,
hard
:
boolean
=
false
):
Promise
{
reset
(
treeish
:
string
,
hard
:
boolean
=
false
):
Promise
{
const
args
=
[
'
reset
'
];
if
(
hard
)
{
...
...
@@ -473,7 +472,7 @@ export class Repository {
return
this
.
run
(
args
);
}
public
revertFiles
(
treeish
:
string
,
paths
:
string
[]):
Promise
{
revertFiles
(
treeish
:
string
,
paths
:
string
[]):
Promise
{
return
this
.
run
([
'
branch
'
]).
then
((
result
)
=>
{
let
args
:
string
[];
...
...
@@ -502,7 +501,7 @@ export class Repository {
});
}
public
fetch
():
Promise
{
fetch
():
Promise
{
return
this
.
run
([
'
fetch
'
]).
then
(
null
,
(
err
:
GitError
)
=>
{
if
(
/No remote repository specified
\.
/
.
test
(
err
.
stderr
))
{
err
.
gitErrorCode
=
GitErrorCodes
.
NoRemoteRepositorySpecified
;
...
...
@@ -514,7 +513,7 @@ export class Repository {
});
}
pu
blic
pu
ll
(
rebase
?:
boolean
):
Promise
{
pull
(
rebase
?:
boolean
):
Promise
{
const
args
=
[
'
pull
'
];
if
(
rebase
)
{
args
.
push
(
'
-r
'
);
}
...
...
@@ -533,7 +532,7 @@ export class Repository {
});
}
pu
blic
pu
sh
(
remote
?:
string
,
name
?:
string
,
options
?:
IPushOptions
):
Promise
{
push
(
remote
?:
string
,
name
?:
string
,
options
?:
IPushOptions
):
Promise
{
const
args
=
[
'
push
'
];
if
(
options
&&
options
.
setUpstream
)
{
args
.
push
(
'
-u
'
);
}
if
(
remote
)
{
args
.
push
(
remote
);
}
...
...
@@ -550,15 +549,15 @@ export class Repository {
});
}
public
sync
():
Promise
{
sync
():
Promise
{
return
this
.
pull
().
then
(()
=>
this
.
push
());
}
public
getRoot
():
TPromise
<
string
>
{
getRoot
():
TPromise
<
string
>
{
return
this
.
run
([
'
rev-parse
'
,
'
--show-toplevel
'
],
{
log
:
false
}).
then
(
result
=>
result
.
stdout
.
trim
());
}
public
getStatus
():
TPromise
<
IRawFileStatus
[]
>
{
getStatus
():
TPromise
<
IRawFileStatus
[]
>
{
return
this
.
run
([
'
status
'
,
'
-z
'
,
'
-u
'
],
{
log
:
false
}).
then
((
executionResult
)
=>
{
const
status
=
executionResult
.
stdout
;
const
result
:
IRawFileStatus
[]
=
[];
...
...
@@ -601,7 +600,7 @@ export class Repository {
});
}
public
getHEAD
():
TPromise
<
IRef
>
{
getHEAD
():
TPromise
<
IRef
>
{
return
this
.
run
([
'
symbolic-ref
'
,
'
--short
'
,
'
HEAD
'
],
{
log
:
false
}).
then
((
result
)
=>
{
if
(
!
result
.
stdout
)
{
return
TPromise
.
wrapError
<
IRef
>
(
new
Error
(
'
Not in a branch
'
));
...
...
@@ -619,7 +618,7 @@ export class Repository {
});
}
public
getRefs
():
TPromise
<
IRef
[]
>
{
getRefs
():
TPromise
<
IRef
[]
>
{
return
this
.
run
([
'
for-each-ref
'
,
'
--format
'
,
'
%(refname) %(objectname)
'
],
{
log
:
false
}).
then
(
result
=>
{
return
result
.
stdout
.
trim
().
split
(
'
\n
'
)
.
filter
(
line
=>
!!
line
)
...
...
@@ -640,7 +639,7 @@ export class Repository {
});
}
public
getRemotes
():
TPromise
<
IRemote
[]
>
{
getRemotes
():
TPromise
<
IRemote
[]
>
{
const
regex
=
/^
([^\s]
+
)\s
+
([^\s]
+
)\s
/
;
return
this
.
run
([
'
remote
'
,
'
--verbose
'
],
{
log
:
false
})
...
...
@@ -655,7 +654,7 @@ export class Repository {
);
}
public
getBranch
(
branch
:
string
):
TPromise
<
IBranch
>
{
getBranch
(
branch
:
string
):
TPromise
<
IBranch
>
{
if
(
branch
===
'
HEAD
'
)
{
return
this
.
getHEAD
();
}
...
...
@@ -698,7 +697,7 @@ export class Repository {
});
}
public
onOutput
(
listener
:
(
output
:
string
)
=>
void
):
()
=>
void
{
onOutput
(
listener
:
(
output
:
string
)
=>
void
):
()
=>
void
{
return
this
.
git
.
onOutput
(
listener
);
}
}
src/vs/workbench/parts/git/node/rawGitService.ts
浏览文件 @
28a78cba
...
...
@@ -4,10 +4,10 @@
*--------------------------------------------------------------------------------------------*/
'
use strict
'
;
import
path
=
require
(
'
path
'
)
;
import
{
join
}
from
'
path
'
;
import
{
TPromise
,
Promise
}
from
'
vs/base/common/winjs.base
'
;
import
mime
=
require
(
'
vs/base/node/mime
'
)
;
import
pfs
=
require
(
'
vs/base/node/pfs
'
)
;
import
{
detectMimesFromFile
,
detectMimesFromStream
}
from
'
vs/base/node/mime
'
;
import
{
realpath
,
exists
}
from
'
vs/base/node/pfs
'
;
import
{
Repository
,
GitError
}
from
'
vs/workbench/parts/git/node/git.lib
'
;
import
{
IRawGitService
,
RawServiceState
,
IRawStatus
,
IRef
,
GitErrorCodes
,
IPushOptions
}
from
'
vs/workbench/parts/git/common/git
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
...
...
@@ -40,7 +40,7 @@ export class RawGitService implements IRawGitService {
}
private
getRepositoryRoot
():
TPromise
<
string
>
{
return
this
.
_repositoryRoot
||
(
this
.
_repositoryRoot
=
pfs
.
realpath
(
this
.
repo
.
path
));
return
this
.
_repositoryRoot
||
(
this
.
_repositoryRoot
=
realpath
(
this
.
repo
.
path
));
}
serviceState
():
TPromise
<
RawServiceState
>
{
...
...
@@ -151,10 +151,10 @@ export class RawGitService implements IRawGitService {
}
detectMimetypes
(
filePath
:
string
,
treeish
?:
string
):
TPromise
<
string
[]
>
{
return
pfs
.
exists
(
path
.
join
(
this
.
repo
.
path
,
filePath
)).
then
((
exists
)
=>
{
return
exists
(
join
(
this
.
repo
.
path
,
filePath
)).
then
((
exists
)
=>
{
if
(
exists
)
{
return
new
TPromise
<
string
[]
>
((
c
,
e
)
=>
{
mime
.
detectMimesFromFile
(
path
.
join
(
this
.
repo
.
path
,
filePath
),
(
err
,
result
)
=>
{
detectMimesFromFile
(
join
(
this
.
repo
.
path
,
filePath
),
(
err
,
result
)
=>
{
if
(
err
)
{
e
(
err
);
}
else
{
c
(
result
.
mimes
);
}
});
...
...
@@ -164,7 +164,7 @@ export class RawGitService implements IRawGitService {
const
child
=
this
.
repo
.
show
(
treeish
+
'
:
'
+
filePath
);
return
new
TPromise
<
string
[]
>
((
c
,
e
)
=>
{
mime
.
detectMimesFromStream
(
child
.
stdout
,
filePath
,
(
err
,
result
)
=>
{
detectMimesFromStream
(
child
.
stdout
,
filePath
,
(
err
,
result
)
=>
{
if
(
err
)
{
e
(
err
);
}
else
{
c
(
result
.
mimes
);
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录