Browse Source

Fixes typing branch/tags names in ref picker

main
Eric Amodio 4 years ago
parent
commit
ccd4724680
3 changed files with 57 additions and 24 deletions
  1. +12
    -2
      src/commands/quickCommand.steps.ts
  2. +1
    -1
      src/git/git.ts
  3. +44
    -21
      src/git/gitService.ts

+ 12
- 2
src/commands/quickCommand.steps.ts View File

@ -283,6 +283,16 @@ export function getValidateGitReferenceFn(repos: Repository | Repository[]) {
return false;
}
if (!inRefMode) {
if (
await Container.git.hasBranchesAndOrTags(repos.path, {
filter: { branches: b => b.name.includes(value), tags: t => t.name.includes(value) },
})
) {
return false;
}
}
const commit = await Container.git.getCommit(repos.path, value);
quickpick.items = [CommitQuickPickItem.create(commit!, true, { alwaysShow: true, compact: true, icon: true })];
return true;
@ -308,7 +318,7 @@ export async function* inputBranchNameStep<
value = value.trim();
if (value.length === 0) return [false, 'Please enter a valid branch name'];
const valid = Boolean(await Container.git.validateBranchOrTagName(value));
const valid = await Container.git.validateBranchOrTagName(value);
return [valid, valid ? undefined : `'${value}' isn't a valid branch name`];
},
});
@ -343,7 +353,7 @@ export async function* inputTagNameStep<
value = value.trim();
if (value.length === 0) return [false, 'Please enter a valid tag name'];
const valid = Boolean(await Container.git.validateBranchOrTagName(value));
const valid = await Container.git.validateBranchOrTagName(value);
return [valid, valid ? undefined : `'${value}' isn't a valid tag name`];
},
});

+ 1
- 1
src/git/git.ts View File

@ -422,7 +422,7 @@ export namespace Git {
...params,
ref,
);
return data.trim();
return Boolean(data.trim());
} catch {
return false;
}

+ 44
- 21
src/git/gitService.ts View File

@ -2151,26 +2151,6 @@ export class GitService implements Disposable {
}
@log()
async hasRemotes(repoPath: string | undefined): Promise<boolean> {
if (repoPath == null) return false;
const repository = await this.getRepository(repoPath);
if (repository == null) return false;
return repository.hasRemotes();
}
@log()
async hasTrackingBranch(repoPath: string | undefined): Promise<boolean> {
if (repoPath == null) return false;
const repository = await this.getRepository(repoPath);
if (repository == null) return false;
return repository.hasTrackingBranch();
}
@log()
async getMergeBase(repoPath: string, ref1: string, ref2: string, options: { forkPoint?: boolean } = {}) {
const cc = Logger.getCorrelationContext();
@ -3186,6 +3166,49 @@ export class GitService implements Disposable {
return (await fsExists(uri.fsPath)) ? uri : undefined;
}
@log()
async hasBranchesAndOrTags(
repoPath: string | undefined,
{
filter,
}: {
filter?: { branches?: (b: GitBranch) => boolean; tags?: (t: GitTag) => boolean };
} = {},
) {
const [branches, tags] = await Promise.all<GitBranch[] | undefined, GitTag[] | undefined>([
this.getBranches(repoPath, {
filter: filter?.branches,
sort: false,
}),
this.getTags(repoPath, {
filter: filter?.tags,
sort: false,
}),
]);
return (branches != null && branches.length !== 0) || (tags != null && tags.length !== 0);
}
@log()
async hasRemotes(repoPath: string | undefined): Promise<boolean> {
if (repoPath == null) return false;
const repository = await this.getRepository(repoPath);
if (repository == null) return false;
return repository.hasRemotes();
}
@log()
async hasTrackingBranch(repoPath: string | undefined): Promise<boolean> {
if (repoPath == null) return false;
const repository = await this.getRepository(repoPath);
if (repository == null) return false;
return repository.hasTrackingBranch();
}
isTrackable(scheme: string): boolean;
isTrackable(uri: Uri): boolean;
isTrackable(schemeOruri: string | Uri): boolean {
@ -3362,7 +3385,7 @@ export class GitService implements Disposable {
}
@log()
validateBranchOrTagName(ref: string, repoPath?: string) {
validateBranchOrTagName(ref: string, repoPath?: string): Promise<boolean> {
return Git.check_ref_format(ref, repoPath);
}

Loading…
Cancel
Save