提交 e7a96243 编写于 作者: J Joao Moreno

improve pull/push specificity

上级 c40385ad
......@@ -1345,7 +1345,7 @@ export class CommandCenter {
return;
}
await repository.pull(repository.HEAD && repository.HEAD.upstream);
await repository.pull(repository.HEAD);
}
@command('git.pullRebase', { repository: true })
......@@ -1357,7 +1357,7 @@ export class CommandCenter {
return;
}
await repository.pullWithRebase(repository.HEAD && repository.HEAD.upstream);
await repository.pullWithRebase(repository.HEAD);
}
@command('git.push', { repository: true })
......@@ -1375,7 +1375,7 @@ export class CommandCenter {
}
try {
await repository.push(repository.HEAD.upstream);
await repository.push(repository.HEAD);
} catch (err) {
if (err.gitErrorCode !== GitErrorCodes.NoUpstreamBranch) {
throw err;
......@@ -1456,9 +1456,9 @@ export class CommandCenter {
}
if (rebase) {
await repository.syncRebase(HEAD.upstream);
await repository.syncRebase(HEAD);
} else {
await repository.sync(HEAD.upstream);
await repository.sync(HEAD);
}
}
......@@ -1476,7 +1476,7 @@ export class CommandCenter {
return;
}
await repository.sync(HEAD.upstream);
await repository.sync(HEAD);
}));
}
......
......@@ -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, Ref, Branch, Remote, Commit, GitErrorCodes, Stash, RefType, GitError, Submodule, DiffOptions, UpstreamRef } from './git';
import { Repository as BaseRepository, Ref, Branch, Remote, Commit, GitErrorCodes, Stash, RefType, GitError, Submodule, DiffOptions } 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';
......@@ -728,26 +728,26 @@ export class Repository implements Disposable {
}
@throttle
async pullWithRebase(upstream?: UpstreamRef): Promise<void> {
async pullWithRebase(head: Branch | undefined): Promise<void> {
let remote: string | undefined;
let branch: string | undefined;
if (upstream) {
remote = upstream.remote;
branch = upstream.name;
if (head && head.name && head.upstream) {
remote = head.upstream.remote;
branch = `${head.upstream.name}`;
}
await this.run(Operation.Pull, () => this.repository.pull(true, remote, branch));
}
@throttle
async pull(upstream?: UpstreamRef): Promise<void> {
async pull(head: Branch | undefined): Promise<void> {
let remote: string | undefined;
let branch: string | undefined;
if (upstream) {
remote = upstream.remote;
branch = upstream.name;
if (head && head.name && head.upstream) {
remote = head.upstream.remote;
branch = `${head.upstream.name}`;
}
await this.run(Operation.Pull, () => this.repository.pull(false, remote, branch));
......@@ -758,13 +758,13 @@ export class Repository implements Disposable {
}
@throttle
async push(upstream?: UpstreamRef): Promise<void> {
async push(head: Branch): Promise<void> {
let remote: string | undefined;
let branch: string | undefined;
if (upstream) {
remote = upstream.remote;
branch = upstream.name;
if (head && head.name && head.upstream) {
remote = head.upstream.remote;
branch = `${head.name}:${head.upstream.name}`;
}
await this.run(Operation.Push, () => this.repository.push(remote, branch));
......@@ -778,28 +778,38 @@ export class Repository implements Disposable {
await this.run(Operation.Push, () => this.repository.push(remote, undefined, false, true));
}
private async _sync(upstream: UpstreamRef, rebase: boolean): Promise<void> {
@throttle
sync(head: Branch): Promise<void> {
return this._sync(head, false);
}
@throttle
async syncRebase(head: Branch): Promise<void> {
return this._sync(head, true);
}
private async _sync(head: Branch, rebase: boolean): Promise<void> {
let remote: string | undefined;
let pullBranch: string | undefined;
let pushBranch: string | undefined;
if (head.name && head.upstream) {
remote = head.upstream.remote;
pullBranch = `${head.upstream.name}`;
pushBranch = `${head.name}:${head.upstream.name}`;
}
await this.run(Operation.Sync, async () => {
await this.repository.pull(rebase, upstream.remote, upstream.name);
await this.repository.pull(rebase, remote, pullBranch);
const shouldPush = this.HEAD && typeof this.HEAD.ahead === 'number' ? this.HEAD.ahead > 0 : true;
if (shouldPush) {
await this.repository.push(upstream.remote, upstream.name);
await this.repository.push(remote, pushBranch);
}
});
}
@throttle
sync(upstream: UpstreamRef): Promise<void> {
return this._sync(upstream, false);
}
@throttle
async syncRebase(upstream: UpstreamRef): Promise<void> {
return this._sync(upstream, true);
}
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, '/');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册