Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
583f9e19
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,发现更多精彩内容 >>
提交
583f9e19
编写于
9月 13, 2018
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'pr/53286'
上级
5eb9eb94
4d46fb70
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
157 addition
and
53 deletion
+157
-53
extensions/git/package.json
extensions/git/package.json
+42
-0
extensions/git/package.nls.json
extensions/git/package.nls.json
+7
-1
extensions/git/src/commands.ts
extensions/git/src/commands.ts
+89
-44
extensions/git/src/git.ts
extensions/git/src/git.ts
+12
-1
extensions/git/src/repository.ts
extensions/git/src/repository.ts
+7
-7
未找到文件。
extensions/git/package.json
浏览文件 @
583f9e19
...
...
@@ -285,16 +285,31 @@
"title"
:
"%command.push%"
,
"category"
:
"Git"
},
{
"command"
:
"git.pushForce"
,
"title"
:
"%command.pushForce%"
,
"category"
:
"Git"
},
{
"command"
:
"git.pushTo"
,
"title"
:
"%command.pushTo%"
,
"category"
:
"Git"
},
{
"command"
:
"git.pushToForce"
,
"title"
:
"%command.pushToForce%"
,
"category"
:
"Git"
},
{
"command"
:
"git.pushWithTags"
,
"title"
:
"%command.pushWithTags%"
,
"category"
:
"Git"
},
{
"command"
:
"git.pushWithTagsForce"
,
"title"
:
"%command.pushWithTagsForce%"
,
"category"
:
"Git"
},
{
"command"
:
"git.sync"
,
"title"
:
"%command.sync%"
,
...
...
@@ -517,14 +532,26 @@
"command"
:
"git.push"
,
"when"
:
"config.git.enabled && gitOpenRepositoryCount != 0"
},
{
"command"
:
"git.pushForce"
,
"when"
:
"config.git.enabled && config.git.allowForcePush && gitOpenRepositoryCount != 0"
},
{
"command"
:
"git.pushTo"
,
"when"
:
"config.git.enabled && gitOpenRepositoryCount != 0"
},
{
"command"
:
"git.pushToForce"
,
"when"
:
"config.git.enabled && config.git.allowForcePush && gitOpenRepositoryCount != 0"
},
{
"command"
:
"git.pushWithTags"
,
"when"
:
"config.git.enabled && gitOpenRepositoryCount != 0"
},
{
"command"
:
"git.pushWithTagsForce"
,
"when"
:
"config.git.enabled && config.git.allowForcePush && gitOpenRepositoryCount != 0"
},
{
"command"
:
"git.sync"
,
"when"
:
"config.git.enabled && gitOpenRepositoryCount != 0"
...
...
@@ -1127,6 +1154,21 @@
"scope"
:
"resource"
,
"default"
:
false
,
"description"
:
"%config.fetchOnPull%"
},
"git.allowForcePush"
:
{
"type"
:
"boolean"
,
"default"
:
false
,
"description"
:
"%config.allowForcePush%"
},
"git.useForcePushWithLease"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%config.useForcePushWithLease%"
},
"git.confirmForcePush"
:
{
"type"
:
"boolean"
,
"default"
:
true
,
"description"
:
"%config.confirmForcePush%"
}
}
},
...
...
extensions/git/package.nls.json
浏览文件 @
583f9e19
...
...
@@ -41,8 +41,11 @@
"command.pullRebase"
:
"Pull (Rebase)"
,
"command.pullFrom"
:
"Pull from..."
,
"command.push"
:
"Push"
,
"command.pushForce"
:
"Push (Force)"
,
"command.pushTo"
:
"Push to..."
,
"command.pushToForce"
:
"Push to... (Force)"
,
"command.pushWithTags"
:
"Push With Tags"
,
"command.pushWithTagsForce"
:
"Push With Tags (Force)"
,
"command.sync"
:
"Sync"
,
"command.syncRebase"
:
"Sync (Rebase)"
,
"command.publish"
:
"Publish Branch"
,
...
...
@@ -89,7 +92,6 @@
"config.showPushSuccessNotification"
:
"Controls whether to show a notification when a push is successful."
,
"config.inputValidation"
:
"Controls when to show commit message input validation."
,
"config.detectSubmodules"
:
"Controls whether to automatically detect git submodules."
,
"colors.added"
:
"Color for added resources."
,
"config.detectSubmodulesLimit"
:
"Controls the limit of git submodules detected."
,
"config.alwaysShowStagedChangesResourceGroup"
:
"Always show the Staged Changes resource group."
,
"config.alwaysSignOff"
:
"Controls the signoff flag for all commits."
,
...
...
@@ -98,6 +100,10 @@
"config.rebaseWhenSync"
:
"Use rebase instead of merge when running the sync command."
,
"config.confirmEmptyCommits"
:
"Always confirm the creation of empty commits."
,
"config.fetchOnPull"
:
"Fetch all branches when pulling or just the current one."
,
"config.allowForcePush"
:
"Controls whether force push (with or without lease) is enabled."
,
"config.useForcePushWithLease"
:
"Controls whether force pushing uses the safer force-with-lease variant."
,
"config.confirmForcePush"
:
"Controls whether to ask for confirmation before force-pushing."
,
"colors.added"
:
"Color for added resources."
,
"colors.modified"
:
"Color for modified resources."
,
"colors.deleted"
:
"Color for deleted resources."
,
"colors.untracked"
:
"Color for untracked resources."
,
...
...
extensions/git/src/commands.ts
浏览文件 @
583f9e19
...
...
@@ -6,7 +6,7 @@
'
use strict
'
;
import
{
Uri
,
commands
,
Disposable
,
window
,
workspace
,
QuickPickItem
,
OutputChannel
,
Range
,
WorkspaceEdit
,
Position
,
LineChange
,
SourceControlResourceState
,
TextDocumentShowOptions
,
ViewColumn
,
ProgressLocation
,
TextEditor
,
MessageOptions
}
from
'
vscode
'
;
import
{
Git
,
CommitOptions
,
Stash
}
from
'
./git
'
;
import
{
Git
,
CommitOptions
,
Stash
,
ForcePushMode
}
from
'
./git
'
;
import
{
Repository
,
Resource
,
Status
,
ResourceGroupType
}
from
'
./repository
'
;
import
{
Model
}
from
'
./model
'
;
import
{
toGitUri
,
fromGitUri
}
from
'
./uri
'
;
...
...
@@ -152,6 +152,17 @@ async function categorizeResourceByResolution(resources: Resource[]): Promise<{
return
{
merge
,
resolved
,
unresolved
};
}
enum
PushType
{
Push
,
PushTo
,
PushTags
,
}
interface
PushOptions
{
pushType
:
PushType
;
forcePush
?:
boolean
;
}
export
class
CommandCenter
{
private
disposables
:
Disposable
[];
...
...
@@ -1486,8 +1497,7 @@ export class CommandCenter {
await
repository
.
pullWithRebase
(
repository
.
HEAD
);
}
@
command
(
'
git.push
'
,
{
repository
:
true
})
async
push
(
repository
:
Repository
):
Promise
<
void
>
{
private
async
_push
(
repository
:
Repository
,
pushOptions
:
PushOptions
)
{
const
remotes
=
repository
.
remotes
;
if
(
remotes
.
length
===
0
)
{
...
...
@@ -1495,13 +1505,46 @@ export class CommandCenter {
return
;
}
const
config
=
workspace
.
getConfiguration
(
'
git
'
,
Uri
.
file
(
repository
.
root
));
let
forcePushMode
:
ForcePushMode
|
undefined
=
undefined
;
if
(
pushOptions
.
forcePush
)
{
if
(
!
config
.
get
<
boolean
>
(
'
allowForcePush
'
))
{
await
window
.
showErrorMessage
(
localize
(
'
force push not allowed
'
,
"
Force push is not allowed, please enable it with the 'git.allowForcePush' setting.
"
));
return
;
}
forcePushMode
=
config
.
get
<
boolean
>
(
'
useForcePushWithLease
'
)
===
true
?
ForcePushMode
.
ForceWithLease
:
ForcePushMode
.
Force
;
if
(
config
.
get
<
boolean
>
(
'
confirmForcePush
'
))
{
const
message
=
localize
(
'
confirm force push
'
,
"
You are about to force push your changes, this can be destructive and could inadvertedly overwrite changes made by others.
\n\n
Are you sure to continue?
"
);
const
yes
=
localize
(
'
ok
'
,
"
OK
"
);
const
neverAgain
=
localize
(
'
never ask again
'
,
"
OK, Don't Ask Again
"
);
const
pick
=
await
window
.
showWarningMessage
(
message
,
{
modal
:
true
},
yes
,
neverAgain
);
if
(
pick
===
neverAgain
)
{
config
.
update
(
'
confirmForcePush
'
,
false
,
true
);
}
else
if
(
pick
!==
yes
)
{
return
;
}
}
}
if
(
pushOptions
.
pushType
===
PushType
.
PushTags
)
{
await
repository
.
pushTags
(
undefined
,
forcePushMode
);
window
.
showInformationMessage
(
localize
(
'
push with tags success
'
,
"
Successfully pushed with tags.
"
));
return
;
}
if
(
!
repository
.
HEAD
||
!
repository
.
HEAD
.
name
)
{
window
.
showWarningMessage
(
localize
(
'
nobranch
'
,
"
Please check out a branch to push to a remote.
"
));
return
;
}
if
(
pushOptions
.
pushType
===
PushType
.
Push
)
{
try
{
await
repository
.
push
(
repository
.
HEAD
);
await
repository
.
push
(
repository
.
HEAD
,
forcePushMode
);
}
catch
(
err
)
{
if
(
err
.
gitErrorCode
!==
GitErrorCodes
.
NoUpstreamBranch
)
{
throw
err
;
...
...
@@ -1516,46 +1559,48 @@ export class CommandCenter {
await
this
.
publish
(
repository
);
}
}
}
@
command
(
'
git.pushWithTags
'
,
{
repository
:
true
})
async
pushWithTags
(
repository
:
Repository
):
Promise
<
void
>
{
const
remotes
=
repository
.
remotes
;
}
else
{
const
branchName
=
repository
.
HEAD
.
name
;
const
picks
=
remotes
.
filter
(
r
=>
r
.
pushUrl
!==
undefined
).
map
(
r
=>
({
label
:
r
.
name
,
description
:
r
.
pushUrl
!
}));
const
placeHolder
=
localize
(
'
pick remote
'
,
"
Pick a remote to publish the branch '{0}' to:
"
,
branchName
);
const
pick
=
await
window
.
showQuickPick
(
picks
,
{
placeHolder
})
;
if
(
remotes
.
length
===
0
)
{
window
.
showWarningMessage
(
localize
(
'
no remotes to push
'
,
"
Your repository has no remotes configured to push to.
"
));
if
(
!
pick
)
{
return
;
}
await
repository
.
pushTags
();
window
.
showInformationMessage
(
localize
(
'
push with tags success
'
,
"
Successfully pushed with tags.
"
));
await
repository
.
pushTo
(
pick
.
label
,
branchName
,
undefined
,
forcePushMode
);
}
}
@
command
(
'
git.pushTo
'
,
{
repository
:
true
})
async
pushTo
(
repository
:
Repository
):
Promise
<
void
>
{
const
remotes
=
repository
.
remotes
;
@
command
(
'
git.push
'
,
{
repository
:
true
})
async
push
(
repository
:
Repository
):
Promise
<
void
>
{
await
this
.
_push
(
repository
,
{
pushType
:
PushType
.
Push
});
}
if
(
remotes
.
length
===
0
)
{
window
.
showWarningMessage
(
localize
(
'
no remotes to push
'
,
"
Your repository has no remotes configured to push to.
"
));
return
;
@
command
(
'
git.pushForce
'
,
{
repository
:
true
})
async
pushForce
(
repository
:
Repository
):
Promise
<
void
>
{
await
this
.
_push
(
repository
,
{
pushType
:
PushType
.
Push
,
forcePush
:
true
})
;
}
if
(
!
repository
.
HEAD
||
!
repository
.
HEAD
.
name
)
{
window
.
showWarningMessage
(
localize
(
'
nobranch
'
,
"
Please check out a branch to push to a remote.
"
));
return
;
@
command
(
'
git.pushWithTags
'
,
{
repository
:
true
})
async
pushWithTags
(
repository
:
Repository
):
Promise
<
void
>
{
await
this
.
_push
(
repository
,
{
pushType
:
PushType
.
PushTags
})
;
}
const
branchName
=
repository
.
HEAD
.
name
;
const
picks
=
remotes
.
filter
(
r
=>
r
.
pushUrl
!==
undefined
).
map
(
r
=>
({
label
:
r
.
name
,
description
:
r
.
pushUrl
!
}));
const
placeHolder
=
localize
(
'
pick remote
'
,
"
Pick a remote to publish the branch '{0}' to:
"
,
branchName
);
const
pick
=
await
window
.
showQuickPick
(
picks
,
{
placeHolder
});
@
command
(
'
git.pushWithTagsForce
'
,
{
repository
:
true
})
async
pushWithTagsForce
(
repository
:
Repository
):
Promise
<
void
>
{
await
this
.
_push
(
repository
,
{
pushType
:
PushType
.
PushTags
,
forcePush
:
true
}
);
}
if
(
!
pick
)
{
return
;
@
command
(
'
git.pushTo
'
,
{
repository
:
true
})
async
pushTo
(
repository
:
Repository
):
Promise
<
void
>
{
await
this
.
_push
(
repository
,
{
pushType
:
PushType
.
PushTo
});
}
await
repository
.
pushTo
(
pick
.
label
,
branchName
);
@
command
(
'
git.pushToForce
'
,
{
repository
:
true
})
async
pushToForce
(
repository
:
Repository
):
Promise
<
void
>
{
await
this
.
_push
(
repository
,
{
pushType
:
PushType
.
PushTo
,
forcePush
:
true
});
}
private
async
_sync
(
repository
:
Repository
,
rebase
:
boolean
):
Promise
<
void
>
{
...
...
extensions/git/src/git.ts
浏览文件 @
583f9e19
...
...
@@ -631,6 +631,11 @@ export interface CommitOptions {
empty
?:
boolean
;
}
export
enum
ForcePushMode
{
Force
,
ForceWithLease
}
export
class
Repository
{
constructor
(
...
...
@@ -1198,9 +1203,15 @@ export class Repository {
}
}
async
push
(
remote
?:
string
,
name
?:
string
,
setUpstream
:
boolean
=
false
,
tags
=
false
):
Promise
<
void
>
{
async
push
(
remote
?:
string
,
name
?:
string
,
setUpstream
:
boolean
=
false
,
tags
=
false
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
const
args
=
[
'
push
'
];
if
(
forcePushMode
===
ForcePushMode
.
ForceWithLease
)
{
args
.
push
(
'
--force-with-lease
'
);
}
else
if
(
forcePushMode
===
ForcePushMode
.
Force
)
{
args
.
push
(
'
--force
'
);
}
if
(
setUpstream
)
{
args
.
push
(
'
-u
'
);
}
...
...
extensions/git/src/repository.ts
浏览文件 @
583f9e19
...
...
@@ -6,7 +6,7 @@
'
use strict
'
;
import
{
commands
,
Uri
,
Command
,
EventEmitter
,
Event
,
scm
,
SourceControl
,
SourceControlInputBox
,
SourceControlResourceGroup
,
SourceControlResourceState
,
SourceControlResourceDecorations
,
SourceControlInputBoxValidation
,
Disposable
,
ProgressLocation
,
window
,
workspace
,
WorkspaceEdit
,
ThemeColor
,
DecorationData
,
Memento
,
SourceControlInputBoxValidationType
}
from
'
vscode
'
;
import
{
Repository
as
BaseRepository
,
Commit
,
Stash
,
GitError
,
Submodule
,
CommitOptions
}
from
'
./git
'
;
import
{
Repository
as
BaseRepository
,
Commit
,
Stash
,
GitError
,
Submodule
,
CommitOptions
,
ForcePushMode
}
from
'
./git
'
;
import
{
anyEvent
,
filterEvent
,
eventToPromise
,
dispose
,
find
,
isDescendant
,
IDisposable
,
onceEvent
,
EmptyDisposable
,
debounceEvent
}
from
'
./util
'
;
import
{
memoize
,
throttle
,
debounce
}
from
'
./decorators
'
;
import
{
toGitUri
}
from
'
./uri
'
;
...
...
@@ -961,7 +961,7 @@ export class Repository implements Disposable {
}
@
throttle
async
push
(
head
:
Branch
):
Promise
<
void
>
{
async
push
(
head
:
Branch
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
let
remote
:
string
|
undefined
;
let
branch
:
string
|
undefined
;
...
...
@@ -970,15 +970,15 @@ export class Repository implements Disposable {
branch
=
`
${
head
.
name
}
:
${
head
.
upstream
.
name
}
`
;
}
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
branch
));
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
branch
,
undefined
,
undefined
,
forcePushMode
));
}
async
pushTo
(
remote
?:
string
,
name
?:
string
,
setUpstream
:
boolean
=
false
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
name
,
setUpstream
));
async
pushTo
(
remote
?:
string
,
name
?:
string
,
setUpstream
:
boolean
=
false
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
name
,
setUpstream
,
undefined
,
forcePushMode
));
}
async
pushTags
(
remote
?:
string
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
undefined
,
false
,
true
));
async
pushTags
(
remote
?:
string
,
forcePushMode
?:
ForcePushMode
):
Promise
<
void
>
{
await
this
.
run
(
Operation
.
Push
,
()
=>
this
.
repository
.
push
(
remote
,
undefined
,
false
,
true
,
forcePushMode
));
}
@
throttle
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录