Преглед на файлове

Fixes #1309 - fix fetch & pull of remote branches

main
Eric Amodio преди 3 години
родител
ревизия
c6a0593cb0
променени са 6 файла, в които са добавени 59 реда и са изтрити 31 реда
  1. +4
    -0
      CHANGELOG.md
  2. +1
    -1
      package.json
  3. +1
    -1
      src/commands/git/pull.ts
  4. +31
    -21
      src/git/git.ts
  5. +19
    -6
      src/git/gitService.ts
  6. +3
    -2
      src/git/models/repository.ts

+ 4
- 0
CHANGELOG.md Целия файл

@ -20,6 +20,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Renames _Browse from Here_ to _Repository from Here_ on the _Browse_ submenu of commits in the views
- Renames _Browse from Here in New Window_ to _Repository from Here in New Window_ on the _Browse_ submenu of commits in the views
### Fixed
- Fixes [#1309](https://github.com/eamodio/vscode-gitlens/issues/1309) - "Fetch" not working on remote branches
## [11.1.3] - 2021-01-05
### Fixed

+ 1
- 1
package.json Целия файл

@ -7046,7 +7046,7 @@
},
{
"command": "gitlens.views.fetch",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+tracking\\b)(?!.*?\\b\\+ahead\\b)(?!.*?\\b\\+behind\\b)/",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:branch\\b(?=.*?\\b\\+(remote|tracking)\\b)(?!.*?\\b\\+ahead\\b)(?!.*?\\b\\+behind\\b)/",
"group": "inline@8"
},
{

+ 1
- 1
src/commands/git/pull.ts Целия файл

@ -63,7 +63,7 @@ export class PullGitCommand extends QuickCommand {
if (!GitBranch.is(state.reference) || !state.reference.current) {
const currentBranch = await state.repos[0].getBranch();
if (currentBranch?.name !== state.reference.name) {
return state.repos[0].fetch({ branch: state.reference });
return state.repos[0].fetch({ branch: state.reference, pull: true });
}
}
}

+ 31
- 21
src/git/git.ts Целия файл

@ -671,34 +671,44 @@ export namespace Git {
repoPath: string,
options:
| { all?: boolean; branch?: undefined; prune?: boolean; remote?: string }
| { all?: undefined; branch: string; prune?: undefined; remote: string; upstream: string } = {},
| {
all?: undefined;
branch: string;
prune?: undefined;
pull?: boolean;
remote: string;
upstream: string;
} = {},
): Promise<void> {
const params = ['fetch'];
if (options.branch) {
params.push('-u', options.remote, `${options.upstream}:${options.branch}`);
try {
void (await git<string>({ cwd: repoPath }, ...params));
return;
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (GitErrors.noFastForward.test(msg)) {
void window.showErrorMessage(
`Unable to pull the '${options.branch}' branch, as it can't be fast-forwarded.`,
);
return;
}
throw ex;
}
}
if (options.prune) {
params.push('--prune');
}
if (options.remote) {
if (options.branch && options.remote) {
if (options.upstream && options.pull) {
params.push('-u', options.remote, `${options.upstream}:${options.branch}`);
try {
void (await git<string>({ cwd: repoPath }, ...params));
return;
} catch (ex) {
const msg: string = ex?.toString() ?? '';
if (GitErrors.noFastForward.test(msg)) {
void window.showErrorMessage(
`Unable to pull the '${options.branch}' branch, as it can't be fast-forwarded.`,
);
return;
}
throw ex;
}
} else {
params.push(options.remote, options.branch);
}
} else if (options.remote) {
params.push(options.remote);
} else if (options.all) {
params.push('--all');

+ 19
- 6
src/git/gitService.ts Целия файл

@ -627,18 +627,19 @@ export class GitService implements Disposable {
@log()
async fetch(
repoPath: string,
options: { all?: boolean; branch?: GitBranchReference; prune?: boolean; remote?: string } = {},
options: { all?: boolean; branch?: GitBranchReference; prune?: boolean; pull?: boolean; remote?: string } = {},
): Promise<void> {
const { branch: branchRef, ...opts } = options;
if (GitReference.isBranch(branchRef)) {
const repo = await this.getRepository(repoPath);
const branch = await repo?.getBranch(branchRef?.name);
if (branch?.tracking == null) return undefined;
if (!branch?.remote && branch?.tracking == null) return undefined;
return Git.fetch(repoPath, {
branch: branch.name,
branch: branch.getNameWithoutRemote(),
remote: branch.getRemoteName()!,
upstream: branch.getTrackingWithoutRemote()!,
pull: options.pull,
});
}
@ -1189,7 +1190,11 @@ export class GitService implements Disposable {
return undefined;
}
@log()
@log({
args: {
1: () => false,
},
})
async getBranches(
repoPath: string | undefined,
options: {
@ -1247,7 +1252,11 @@ export class GitService implements Disposable {
return branches;
}
@log()
@log({
args: {
1: () => false,
},
})
async getBranchesAndOrTags(
repoPath: string | undefined,
{
@ -3302,7 +3311,11 @@ export class GitService implements Disposable {
return status;
}
@log()
@log({
args: {
1: () => false,
},
})
async getTags(
repoPath: string | undefined,
options: { filter?: (t: GitTag) => boolean; sort?: boolean | { orderBy?: TagSorting } } = {},

+ 3
- 2
src/git/models/repository.ts Целия файл

@ -410,6 +410,7 @@ export class Repository implements Disposable {
branch?: GitBranchReference;
progress?: boolean;
prune?: boolean;
pull?: boolean;
remote?: string;
} = {},
) {
@ -421,7 +422,7 @@ export class Repository implements Disposable {
location: ProgressLocation.Notification,
title:
opts.branch != null
? `Pulling ${opts.branch.name}...`
? `${opts.pull ? 'Pulling' : 'Fetching'} ${opts.branch.name}...`
: `Fetching ${opts.remote ? `${opts.remote} of ` : ''}${this.formattedName}...`,
},
() => this.fetchCore(opts),
@ -429,7 +430,7 @@ export class Repository implements Disposable {
}
private async fetchCore(
options: { all?: boolean; branch?: GitBranchReference; prune?: boolean; remote?: string } = {},
options: { all?: boolean; branch?: GitBranchReference; prune?: boolean; pull?: boolean; remote?: string } = {},
) {
try {
void (await Container.git.fetch(this.path, options));

Зареждане…
Отказ
Запис