Skip to content

Commit

Permalink
Adds ref range input into history/log git command
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 16, 2020
1 parent 297d165 commit 281249c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- Adds ability to enter reference ranges (e.g. `main...release/1.0`) to the _Git Command Palette_'s _history_ command

### Fixed

- Fixes [#1148](https://github.com/eamodio/vscode-gitlens/issues/1148) - Follow renames on File History cannot load more history
Expand Down
1 change: 1 addition & 0 deletions src/commands/git/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class LogGitCommand extends QuickCommand<State> {
placeholder: 'Choose a branch or tag to show its commit history',
picked: context.selectedBranchOrTag?.ref,
value: context.selectedBranchOrTag == null ? state.reference?.ref : undefined,
ranges: true,
});
if (result === StepResult.Break) {
// If we skipped the previous step, make sure we back up past it
Expand Down
14 changes: 12 additions & 2 deletions src/commands/quickCommand.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import {
OpenChangedFilesCommandQuickPickItem,
OpenRemoteResourceCommandQuickPickItem,
ReferencesQuickPickItem,
RefQuickPickItem,
RepositoryQuickPickItem,
RevealInSideBarQuickPickItem,
SearchForCommitQuickPickItem,
Expand Down Expand Up @@ -255,7 +256,7 @@ export async function getBranchesAndOrTags(
]);
}

export function getValidateGitReferenceFn(repos: Repository | Repository[]) {
export function getValidateGitReferenceFn(repos: Repository | Repository[], options?: { ranges?: boolean }) {
return async (quickpick: QuickPick<any>, value: string) => {
let inRefMode = false;
if (value.startsWith('#')) {
Expand All @@ -269,6 +270,13 @@ export function getValidateGitReferenceFn(repos: Repository | Repository[]) {
repos = repos[0];
}

if (inRefMode && options?.ranges && GitRevision.isRange(value)) {
quickpick.items = [
RefQuickPickItem.create(value, repos.path, true, { alwaysShow: true, ref: false, icon: false }),
];
return true;
}

if (!(await Container.git.validateReference(repos.path, value))) {
if (inRefMode) {
quickpick.items = [
Expand Down Expand Up @@ -510,13 +518,15 @@ export async function* pickBranchOrTagStep<
titleContext,
value,
additionalButtons,
ranges,
}: {
filter?: { branches?: (b: GitBranch) => boolean; tags?: (t: GitTag) => boolean };
picked: string | string[] | undefined;
placeholder: string | ((context: Context) => string);
titleContext?: string;
value: string | undefined;
additionalButtons?: QuickInputButton[];
ranges?: boolean;
},
): StepResultGenerator<GitReference> {
context.showTags = true;
Expand Down Expand Up @@ -606,7 +616,7 @@ export async function* pickBranchOrTagStep<
void GitActions.Commit.reveal(item, { select: true, focus: false, expand: true });
}
},
onValidateValue: getValidateGitReferenceFn(state.repo),
onValidateValue: getValidateGitReferenceFn(state.repo, { ranges: ranges }),
});
const selection: StepSelection<typeof step> = yield step;
return QuickCommand.canPickStepContinue(step, state, selection) ? selection[0].item : StepResult.Break;
Expand Down
13 changes: 13 additions & 0 deletions src/quickpicks/gitQuickPickItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ export namespace RefQuickPickItem {

const gitRef = GitReference.create(ref, repoPath);

if (GitRevision.isRange(ref)) {
return {
label: `Range ${gitRef.name}`,
description: '',
alwaysShow: options.alwaysShow,
picked: picked,
item: gitRef,
current: false,
ref: ref,
remote: false,
};
}

const item: RefQuickPickItem = {
label: `Commit ${gitRef.name}`,
description: options.ref ? `$(git-commit) ${ref}` : '',
Expand Down

0 comments on commit 281249c

Please sign in to comment.