Skip to content

Sync (Rebase) Command added #31416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@
"title": "%command.sync%",
"category": "Git"
},
{
"command": "git.syncRebase",
"title": "%command.syncRebase%",
"category": "Git"
},
{
"command": "git.publish",
"title": "%command.publish%",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions extensions/git/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions extensions/git/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand Down