Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
d0bae42c
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,发现更多精彩内容 >>
提交
d0bae42c
编写于
5月 24, 2017
作者:
J
João Moreno
提交者:
GitHub
5月 24, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #25862 from letmaik/git-delete-branch
Add git delete branch command
上级
04c6d432
1c7f33e4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
79 addition
and
2 deletion
+79
-2
extensions/git/package.json
extensions/git/package.json
+9
-0
extensions/git/package.nls.json
extensions/git/package.nls.json
+1
-0
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+54
-0
extensions/git/src/git.ts
extensions/git/src/git.ts
+9
-1
extensions/git/src/model.ts
extensions/git/src/model.ts
+6
-1
未找到文件。
extensions/git/package.json
浏览文件 @
d0bae42c
...
...
@@ -172,6 +172,11 @@
"title"
:
"%command.branch%"
,
"category"
:
"Git"
},
{
"command"
:
"git.deleteBranch"
,
"title"
:
"%command.deleteBranch%"
,
"category"
:
"Git"
},
{
"command"
:
"git.pull"
,
"title"
:
"%command.pull%"
,
...
...
@@ -298,6 +303,10 @@
"command"
:
"git.branch"
,
"when"
:
"config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command"
:
"git.deleteBranch"
,
"when"
:
"config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command"
:
"git.pull"
,
"when"
:
"config.git.enabled && scmProvider == git && gitState == idle"
...
...
extensions/git/package.nls.json
浏览文件 @
d0bae42c
...
...
@@ -21,6 +21,7 @@
"command.undoCommit"
:
"Undo Last Commit"
,
"command.checkout"
:
"Checkout to..."
,
"command.branch"
:
"Create Branch..."
,
"command.deleteBranch"
:
"Delete Branch..."
,
"command.pull"
:
"Pull"
,
"command.pullRebase"
:
"Pull (Rebase)"
,
"command.push"
:
"Push"
,
...
...
extensions/git/src/commands.ts
浏览文件 @
d0bae42c
...
...
@@ -60,6 +60,23 @@ class CheckoutRemoteHeadItem extends CheckoutItem {
}
}
class
BranchDeleteItem
implements
QuickPickItem
{
private
get
shortCommit
():
string
{
return
(
this
.
ref
.
commit
||
''
).
substr
(
0
,
8
);
}
get
branchName
():
string
|
undefined
{
return
this
.
ref
.
name
;
}
get
label
():
string
{
return
this
.
branchName
||
''
;
}
get
description
():
string
{
return
this
.
shortCommit
;
}
constructor
(
private
ref
:
Ref
)
{
}
async
run
(
model
:
Model
,
force
?:
boolean
):
Promise
<
void
>
{
if
(
!
this
.
branchName
)
{
return
;
}
await
model
.
deleteBranch
(
this
.
branchName
,
force
);
}
}
interface
Command
{
commandId
:
string
;
key
:
string
;
...
...
@@ -699,6 +716,43 @@ export class CommandCenter {
await
this
.
model
.
branch
(
name
);
}
@
command
(
'
git.deleteBranch
'
)
async
deleteBranch
(
name
:
string
,
force
?:
boolean
):
Promise
<
void
>
{
let
run
:
(
force
?:
boolean
)
=>
Promise
<
void
>
;
if
(
typeof
name
===
'
string
'
)
{
run
=
force
=>
this
.
model
.
deleteBranch
(
name
,
force
);
}
else
{
const
currentHead
=
this
.
model
.
HEAD
&&
this
.
model
.
HEAD
.
name
;
const
heads
=
this
.
model
.
refs
.
filter
(
ref
=>
ref
.
type
===
RefType
.
Head
&&
ref
.
name
!==
currentHead
)
.
map
(
ref
=>
new
BranchDeleteItem
(
ref
));
const
placeHolder
=
localize
(
'
select branch to delete
'
,
'
Select a branch to delete
'
);
const
choice
=
await
window
.
showQuickPick
<
BranchDeleteItem
>
(
heads
,
{
placeHolder
});
if
(
!
choice
||
!
choice
.
branchName
)
{
return
;
}
name
=
choice
.
branchName
;
run
=
force
=>
choice
.
run
(
this
.
model
,
force
);
}
try
{
await
run
(
force
);
}
catch
(
err
)
{
if
(
err
.
gitErrorCode
!==
GitErrorCodes
.
BranchNotFullyMerged
)
{
throw
err
;
}
const
message
=
localize
(
'
confirm force delete branch
'
,
"
The branch '{0}' is not fully merged. Delete anyway?
"
,
name
);
const
yes
=
localize
(
'
delete branch
'
,
"
Delete Branch
"
);
const
pick
=
await
window
.
showWarningMessage
(
message
,
yes
);
if
(
pick
===
yes
)
{
await
run
(
true
);
}
}
}
@
command
(
'
git.pull
'
)
async
pull
():
Promise
<
void
>
{
const
remotes
=
this
.
model
.
remotes
;
...
...
extensions/git/src/git.ts
浏览文件 @
d0bae42c
...
...
@@ -273,7 +273,8 @@ export const GitErrorCodes = {
CantCreatePipe
:
'
CantCreatePipe
'
,
CantAccessRemote
:
'
CantAccessRemote
'
,
RepositoryNotFound
:
'
RepositoryNotFound
'
,
RepositoryIsLocked
:
'
RepositoryIsLocked
'
RepositoryIsLocked
:
'
RepositoryIsLocked
'
,
BranchNotFullyMerged
:
'
BranchNotFullyMerged
'
};
function
getGitErrorCode
(
stderr
:
string
):
string
|
undefined
{
...
...
@@ -291,6 +292,8 @@ function getGitErrorCode(stderr: string): string | undefined {
return
GitErrorCodes
.
RepositoryNotFound
;
}
else
if
(
/unable to access/
.
test
(
stderr
))
{
return
GitErrorCodes
.
CantAccessRemote
;
}
else
if
(
/branch '.+' is not fully merged/
.
test
(
stderr
))
{
return
GitErrorCodes
.
BranchNotFullyMerged
;
}
return
void
0
;
...
...
@@ -650,6 +653,11 @@ export class Repository {
await
this
.
run
(
args
);
}
async
deleteBranch
(
name
:
string
,
force
?:
boolean
):
Promise
<
void
>
{
const
args
=
[
'
branch
'
,
force
?
'
-D
'
:
'
-d
'
,
name
];
await
this
.
run
(
args
);
}
async
clean
(
paths
:
string
[]):
Promise
<
void
>
{
const
pathsByGroup
=
groupBy
(
paths
,
p
=>
path
.
dirname
(
p
));
const
groups
=
Object
.
keys
(
pathsByGroup
).
map
(
k
=>
pathsByGroup
[
k
]);
...
...
extensions/git/src/model.ts
浏览文件 @
d0bae42c
...
...
@@ -210,7 +210,8 @@ export enum Operation {
Init
=
1
<<
12
,
Show
=
1
<<
13
,
Stage
=
1
<<
14
,
GetCommitTemplate
=
1
<<
15
GetCommitTemplate
=
1
<<
15
,
DeleteBranch
=
1
<<
16
}
// function getOperationName(operation: Operation): string {
...
...
@@ -453,6 +454,10 @@ export class Model implements Disposable {
await
this
.
run
(
Operation
.
Branch
,
()
=>
this
.
repository
.
branch
(
name
,
true
));
}
async
deleteBranch
(
name
:
string
,
force
?:
boolean
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
DeleteBranch
,
()
=>
this
.
repository
.
deleteBranch
(
name
,
force
));
}
async
checkout
(
treeish
:
string
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Checkout
,
()
=>
this
.
repository
.
checkout
(
treeish
,
[]));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录