Command added

This commit is contained in:
Harjyot Singh 2017-07-26 03:36:26 +05:30
parent 41f9e654b4
commit 3085d3ebd7
4 changed files with 54 additions and 0 deletions

View file

@ -217,6 +217,11 @@
"title": "%command.sync%",
"category": "Git"
},
{
"command": "git.syncRebase",
"title": "%command.syncRebase%",
"category": "Git"
},
{
"command": "git.publish",
"title": "%command.publish%",
@ -359,6 +364,10 @@
"command": "git.sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.syncRebase",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.publish",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
@ -389,6 +398,11 @@
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.syncRebase",
"group": "1_sync",
"when": "config.git.enabled && scmProvider == git && gitState == idle"
},
{
"command": "git.pull",
"group": "1_sync",

View file

@ -30,6 +30,7 @@
"command.push": "Push",
"command.pushTo": "Push to...",
"command.sync": "Sync",
"command.syncRebase": "Sync (Rebase)",
"command.publish": "Publish Branch",
"command.showOutput": "Show Git Output",
"command.ignore": "Add File to .gitignore",

View file

@ -956,6 +956,32 @@ export class CommandCenter {
await this.model.sync();
}
@command('git.syncRebase')
async syncRebase(): Promise<void> {
const HEAD = this.model.HEAD;
if (!HEAD || !HEAD.upstream) {
return;
}
const config = workspace.getConfiguration('git');
const shouldPrompt = config.get<boolean>('confirmSync') === true;
if (shouldPrompt) {
const message = localize('sync is unpredictable', "This action will push and pull commits to and from '{0}'.", HEAD.upstream);
const yes = localize('ok', "OK");
const neverAgain = localize('never again', "OK, Never Show Again");
const pick = await window.showWarningMessage(message, { modal: true }, yes, neverAgain);
if (pick === neverAgain) {
await config.update('confirmSync', false, true);
} else if (pick !== yes) {
return;
}
}
await this.model.syncRebase();
}
@command('git.publish')
async publish(): Promise<void> {
const remotes = this.model.remotes;

View file

@ -522,6 +522,19 @@ export class Model implements Disposable {
});
}
@throttle
async syncRebase(): Promise<void> {
await this.run(Operation.Sync, async () => {
await this.repository.pull(true);
const shouldPush = this.HEAD && typeof this.HEAD.ahead === 'number' ? this.HEAD.ahead > 0 : true;
if (shouldPush) {
await this.repository.push();
}
});
}
async show(ref: string, filePath: string): Promise<string> {
return await this.run(Operation.Show, async () => {
const relativePath = path.relative(this.repository.root, filePath).replace(/\\/g, '/');