Skip to content

Commit

Permalink
Ensures open changes only added to file commits
Browse files Browse the repository at this point in the history
Updates CHANGELOG & README
Refs: #2641
  • Loading branch information
eamodio committed Aug 11, 2023
1 parent d2052eb commit 03f5092
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- Adds an _Open Changes_ button to commits in the file history quick pick menu — closes [#2641](https://github.com/gitkraken/vscode-gitlens/issues/2641) thanks to [PR #2800](https://github.com/gitkraken/vscode-gitlens/pull/2800) by Omar Ghazi ([@omarfesal](https://github.com/omarfesal))

## [14.2.1] - 2023-08-10

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -345,6 +345,7 @@ A big thanks to the people that have contributed to this project 🙏❤️:
- Cory Forsyth ([@bantic](https://github.com/bantic)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=bantic)
- John Gee ([@shadowspawn](https://github.com/shadowspawn)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=shadowspawn)
- Geoffrey ([@g3offrey](https://github.com/g3offrey)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=g3offrey)
- Omar Ghazi ([@omarfesal](https://github.com/omarfesal)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=omarfesal)
- Neil Ghosh ([@neilghosh](https://github.com/neilghosh)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=neilghosh)
- Guillaume Rozan ([@grozan](https://github.com/grozan)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=grozan)
- Guillem González Vela ([@guillemglez](https://github.com/guillemglez)) — [contributions](https://github.com/gitkraken/vscode-gitlens/commits?author=guillemglez)
Expand Down
58 changes: 33 additions & 25 deletions src/commands/quickCommand.steps.ts
Expand Up @@ -98,7 +98,7 @@ import { isSubscriptionPaidPlan, isSubscriptionPreviewTrialExpired } from '../su
import { filterMap, intersection, isStringArray } from '../system/array';
import { configuration } from '../system/configuration';
import { formatPath } from '../system/formatPath';
import { map } from '../system/iterable';
import { first, map } from '../system/iterable';
import { getSettledValue } from '../system/promise';
import { pad, pluralize, truncate } from '../system/string';
import { openWorkspace, OpenWorkspaceLocation } from '../system/utils';
Expand Down Expand Up @@ -1059,27 +1059,32 @@ export async function* pickCommitStep<
},
): AsyncStepResultGenerator<GitCommit> {
function getItems(log: GitLog | undefined) {
return log == null
? [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)]
: [
...map(log.commits.values(), commit =>
createCommitQuickPickItem(
commit,
picked != null &&
(typeof picked === 'string' ? commit.ref === picked : picked.includes(commit.ref)),
{
buttons: [
ShowDetailsViewQuickInputButton,
RevealInSideBarQuickInputButton,
OpenChangesViewQuickInputButton,
],
compact: true,
icon: true,
},
),
),
...(log?.hasMore ? [createDirectiveQuickPickItem(Directive.LoadMore)] : []),
];
if (log == null) {
return [createDirectiveQuickPickItem(Directive.Back, true), createDirectiveQuickPickItem(Directive.Cancel)];
}

const buttons = [ShowDetailsViewQuickInputButton, RevealInSideBarQuickInputButton];

// If these are "file" commits, then add an Open Changes button
if (first(log.commits)?.[1].file != null) {
buttons.splice(0, 0, OpenChangesViewQuickInputButton);
}

return [
...map(log.commits.values(), commit =>
createCommitQuickPickItem(
commit,
picked != null &&
(typeof picked === 'string' ? commit.ref === picked : picked.includes(commit.ref)),
{
buttons: buttons,
compact: true,
icon: true,
},
),
),
...(log?.hasMore ? [createDirectiveQuickPickItem(Directive.LoadMore)] : []),
];
}

const step = createPickStep<CommandQuickPickItem | CommitQuickPickItem>({
Expand All @@ -1106,7 +1111,6 @@ export async function* pickCommitStep<
],
onDidClickItemButton: (quickpick, button, item) => {
if (CommandQuickPickItem.is(item)) return;
const fileName = `${item.item.file?.path}`;

switch (button) {
case ShowDetailsViewQuickInputButton:
Expand All @@ -1120,9 +1124,13 @@ export async function* pickCommitStep<
expand: true,
});
break;
case OpenChangesViewQuickInputButton:
void CommitActions.openChanges(fileName, item.item, {});
case OpenChangesViewQuickInputButton: {
const path = item.item.file?.path;
if (path != null) {
void CommitActions.openChanges(path, item.item);
}
break;
}
}
},
onDidClickButton: (quickpick, button) => {
Expand Down

0 comments on commit 03f5092

Please sign in to comment.