Pārlūkot izejas kodu

Adds before option to browse repo at revision

main
Eric Amodio pirms 4 gadiem
vecāks
revīzija
0d0ab9090a
8 mainītis faili ar 156 papildinājumiem un 51 dzēšanām
  1. +10
    -1
      CHANGELOG.md
  2. +56
    -4
      package.json
  3. +22
    -4
      src/commands/browseRepoAtRevision.ts
  4. +2
    -0
      src/commands/common.ts
  5. +2
    -1
      src/commands/gitCommands.actions.ts
  6. +34
    -35
      src/commands/quickCommand.steps.ts
  7. +14
    -3
      src/quickpicks/commitQuickPickItems.ts
  8. +16
    -3
      src/views/viewCommands.ts

+ 10
- 1
CHANGELOG.md Parādīt failu

@ -9,7 +9,16 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Added
- Adds a new _Quick Open File History_ command to all places where _Open File History_ already exists — closes [#1156](https://github.com/eamodio/vscode-gitlens/issues/1156)
- Adds _Add Remote_ command to the branch status in the _Branches_, _Commits_, and _Repositories_ views when there are no Git remotes configured
- Adds the _Add Remote_ command to the branch status in the _Branches_, _Commits_, and _Repositories_ views when there are no Git remotes configured
- Adds a new _Browse Repository from Before Here_ (`gitlens.browseRepoBeforeRevision`) and _Browse Repository from Before Here in New Window_ (`gitlens.browseRepoBeforeRevisionInNewWindow`) commands
- Adds _Repository from Before Here_ and _Repository from Before Here in New Window_ to the _Browse_ submenu of commits in the views
### Changed
- Renames _Browse from Here_ command to _Browse Repository from Here_ in the command palette and quick pick menus
- Renames _Browse from Here in New Window_ command to _Browse Repository from Here in New Window_ in the command palette and quick pick menus
- 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
## [11.1.3] - 2021-01-05

+ 56
- 4
package.json Parādīt failu

@ -180,6 +180,8 @@
"onCommand:gitlens.inviteToLiveShare",
"onCommand:gitlens.browseRepoAtRevision",
"onCommand:gitlens.browseRepoAtRevisionInNewWindow",
"onCommand:gitlens.browseRepoBeforeRevision",
"onCommand:gitlens.browseRepoBeforeRevisionInNewWindow",
"onCommand:gitlens.fetchRepositories",
"onCommand:gitlens.pullRepositories",
"onCommand:gitlens.pushRepositories",
@ -3463,27 +3465,53 @@
},
{
"command": "gitlens.browseRepoAtRevision",
"title": "Browse from Revision",
"title": "Browse Repository from Revision",
"category": "GitLens",
"icon": "$(folder-opened)",
"enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git"
},
{
"command": "gitlens.browseRepoAtRevisionInNewWindow",
"title": "Browse from Revision in New Window",
"title": "Browse Repository from Revision in New Window",
"category": "GitLens",
"icon": "$(folder-opened)",
"enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git"
},
{
"command": "gitlens.browseRepoBeforeRevision",
"title": "Browse Repository from Before Revision",
"category": "GitLens",
"icon": "$(folder-opened)",
"enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git"
},
{
"command": "gitlens.browseRepoBeforeRevisionInNewWindow",
"title": "Browse Repository from Before Revision in New Window",
"category": "GitLens",
"icon": "$(folder-opened)",
"enablement": "gitlens:activeFileStatus =~ /revision/ && resourceScheme != git"
},
{
"command": "gitlens.views.browseRepoAtRevision",
"title": "Browse from Here",
"title": "Repository from Here",
"category": "GitLens",
"icon": "$(folder-opened)"
},
{
"command": "gitlens.views.browseRepoAtRevisionInNewWindow",
"title": "Browse from Here in New Window",
"title": "Repository from Here in New Window",
"category": "GitLens",
"icon": "$(folder-opened)"
},
{
"command": "gitlens.views.browseRepoBeforeRevision",
"title": "Repository from Before Here",
"category": "GitLens",
"icon": "$(folder-opened)"
},
{
"command": "gitlens.views.browseRepoBeforeRevisionInNewWindow",
"title": "Repository from Before Here in New Window",
"category": "GitLens",
"icon": "$(folder-opened)"
},
@ -5149,6 +5177,14 @@
"when": "gitlens:activeFileStatus =~ /revision/"
},
{
"command": "gitlens.browseRepoBeforeRevision",
"when": "gitlens:activeFileStatus =~ /revision/"
},
{
"command": "gitlens.browseRepoBeforeRevisionInNewWindow",
"when": "gitlens:activeFileStatus =~ /revision/"
},
{
"command": "gitlens.views.browseRepoAtRevision",
"when": "false"
},
@ -5157,6 +5193,14 @@
"when": "false"
},
{
"command": "gitlens.views.browseRepoBeforeRevision",
"when": "false"
},
{
"command": "gitlens.views.browseRepoBeforeRevisionInNewWindow",
"when": "false"
},
{
"command": "gitlens.fetchRepositories",
"when": "gitlens:hasRemotes && !gitlens:readonly"
},
@ -7972,7 +8016,15 @@
},
{
"command": "gitlens.views.browseRepoAtRevisionInNewWindow",
"group": "1_gitlens@3"
},
{
"command": "gitlens.views.browseRepoBeforeRevision",
"group": "1_gitlens@2"
},
{
"command": "gitlens.views.browseRepoBeforeRevisionInNewWindow",
"group": "1_gitlens@4"
}
],
"gitlens/commit/copy": [

+ 22
- 4
src/commands/browseRepoAtRevision.ts Parādīt failu

@ -7,22 +7,37 @@ import { toGitLensFSUri } from '../git/fsProvider';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { Messages } from '../messages';
import { Container } from '../container';
export interface BrowseRepoAtRevisionCommandArgs {
uri?: Uri;
before?: boolean;
openInNewWindow?: boolean;
}
@command()
export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
constructor() {
super([Commands.BrowseRepoAtRevision, Commands.BrowseRepoAtRevisionInNewWindow]);
super([
Commands.BrowseRepoAtRevision,
Commands.BrowseRepoAtRevisionInNewWindow,
Commands.BrowseRepoBeforeRevision,
Commands.BrowseRepoBeforeRevisionInNewWindow,
]);
}
protected preExecute(context: CommandContext, args?: BrowseRepoAtRevisionCommandArgs) {
if (context.command === Commands.BrowseRepoAtRevisionInNewWindow) {
args = { ...args, openInNewWindow: true };
switch (context.command) {
case Commands.BrowseRepoAtRevisionInNewWindow:
args = { ...args, before: false, openInNewWindow: true };
break;
case Commands.BrowseRepoBeforeRevision:
args = { ...args, before: true, openInNewWindow: false };
break;
case Commands.BrowseRepoBeforeRevisionInNewWindow:
args = { ...args, before: true, openInNewWindow: true };
break;
}
return this.execute(context.editor!, context.uri, args);
@ -42,7 +57,10 @@ export class BrowseRepoAtRevisionCommand extends ActiveEditorCommand {
let gitUri = await GitUri.fromUri(uri);
if (gitUri.sha == null) return;
uri = toGitLensFSUri(gitUri.sha, gitUri.repoPath!);
const sha = args?.before
? await Container.git.resolveReference(gitUri.repoPath!, `${gitUri.sha}^`)
: gitUri.sha;
uri = toGitLensFSUri(sha, gitUri.repoPath!);
gitUri = GitUri.fromRevisionUri(uri);
openWorkspace(uri, `${paths.basename(gitUri.repoPath!)} @ ${gitUri.shortSha}`, {

+ 2
- 0
src/commands/common.ts Parādīt failu

@ -30,6 +30,8 @@ export enum Commands {
AddAuthors = 'gitlens.addAuthors',
BrowseRepoAtRevision = 'gitlens.browseRepoAtRevision',
BrowseRepoAtRevisionInNewWindow = 'gitlens.browseRepoAtRevisionInNewWindow',
BrowseRepoBeforeRevision = 'gitlens.browseRepoBeforeRevision',
BrowseRepoBeforeRevisionInNewWindow = 'gitlens.browseRepoBeforeRevisionInNewWindow',
ClearFileAnnotations = 'gitlens.clearFileAnnotations',
CloseUnchangedFiles = 'gitlens.closeUnchangedFiles',
CloseUpdatesView = 'gitlens.closeUpdatesView',

+ 2
- 1
src/commands/gitCommands.actions.ts Parādīt failu

@ -39,9 +39,10 @@ async function ensureRepo(repo: string | Repository): Promise {
}
export namespace GitActions {
export async function browseAtRevision(uri: Uri, options?: { openInNewWindow?: boolean }) {
export async function browseAtRevision(uri: Uri, options?: { before?: boolean; openInNewWindow?: boolean }) {
void (await executeEditorCommand<BrowseRepoAtRevisionCommandArgs>(Commands.BrowseRepoAtRevision, undefined, {
uri: uri,
before: options?.before,
openInNewWindow: options?.openInNewWindow,
}));
}

+ 34
- 35
src/commands/quickCommand.steps.ts Parādīt failu

@ -1522,26 +1522,25 @@ async function getShowCommitOrStashStepItems<
);
}
if (isStash) {
items.push(
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, false),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, true),
new CommitCompareWithHEADCommandQuickPickItem(state.reference),
new CommitCompareWithWorkingCommandQuickPickItem(state.reference),
);
} else {
items.push(
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, false),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, true),
new CommitCompareWithHEADCommandQuickPickItem(state.reference),
new CommitCompareWithWorkingCommandQuickPickItem(state.reference),
items.push(
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, { openInNewWindow: false }),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, {
before: true,
openInNewWindow: false,
}),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, { openInNewWindow: true }),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, {
before: true,
openInNewWindow: true,
}),
new CommitCompareWithHEADCommandQuickPickItem(state.reference),
new CommitCompareWithWorkingCommandQuickPickItem(state.reference),
);
new CommitCopyIdQuickPickItem(state.reference),
);
if (!isStash) {
items.push(new CommitCopyIdQuickPickItem(state.reference));
}
items.push(new CommitCopyMessageQuickPickItem(state.reference));
if (remotes?.length) {
@ -1762,24 +1761,24 @@ async function getShowCommitOrStashFileStepItems<
);
}
if (isStash) {
items.push(
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, false),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, true),
new CommitCompareWithHEADCommandQuickPickItem(state.reference),
new CommitCompareWithWorkingCommandQuickPickItem(state.reference),
);
} else {
items.push(
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, false),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, true),
new CommitCompareWithHEADCommandQuickPickItem(state.reference),
new CommitCompareWithWorkingCommandQuickPickItem(state.reference),
items.push(
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, { openInNewWindow: false }),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, {
before: true,
openInNewWindow: false,
}),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, { openInNewWindow: true }),
new CommitBrowseRepositoryFromHereCommandQuickPickItem(state.reference, {
before: true,
openInNewWindow: true,
}),
new CommitCompareWithHEADCommandQuickPickItem(state.reference),
new CommitCompareWithWorkingCommandQuickPickItem(state.reference),
);
new CommitCopyIdQuickPickItem(state.reference),
);
if (!isStash) {
items.push(new CommitCopyIdQuickPickItem(state.reference));
}
items.push(new CommitCopyMessageQuickPickItem(state.reference));

+ 14
- 3
src/quickpicks/commitQuickPickItems.ts Parādīt failu

@ -74,14 +74,25 @@ export class CommitFileQuickPickItem extends CommandQuickPickItem {
export class CommitBrowseRepositoryFromHereCommandQuickPickItem extends CommandQuickPickItem {
constructor(
private readonly commit: GitLogCommit,
private readonly openInNewWindow: boolean,
private readonly executeOptions?: {
before?: boolean;
openInNewWindow: boolean;
},
item?: QuickPickItem,
) {
super(item ?? `$(folder-opened) Browse from Here${openInNewWindow ? ' in New Window' : ''}`);
super(
item ??
`$(folder-opened) Browse Repository from${executeOptions?.before ? ' Before' : ''} Here${
executeOptions?.openInNewWindow ? ' in New Window' : ''
}`,
);
}
execute(_options: { preserveFocus?: boolean; preview?: boolean }): Promise<void> {
return GitActions.browseAtRevision(this.commit.toGitUri(), { openInNewWindow: this.openInNewWindow });
return GitActions.browseAtRevision(this.commit.toGitUri(), {
before: this.executeOptions?.before,
openInNewWindow: this.executeOptions?.openInNewWindow,
});
}
}

+ 16
- 3
src/views/viewCommands.ts Parādīt failu

@ -134,7 +134,17 @@ export class ViewCommands {
commands.registerCommand('gitlens.views.browseRepoAtRevision', this.browseRepoAtRevision, this);
commands.registerCommand(
'gitlens.views.browseRepoAtRevisionInNewWindow',
n => this.browseRepoAtRevision(n, true),
n => this.browseRepoAtRevision(n, { openInNewWindow: true }),
this,
);
commands.registerCommand(
'gitlens.views.browseRepoBeforeRevision',
n => this.browseRepoAtRevision(n, { before: true }),
this,
);
commands.registerCommand(
'gitlens.views.browseRepoBeforeRevisionInNewWindow',
n => this.browseRepoAtRevision(n, { before: true, openInNewWindow: true }),
this,
);
@ -315,10 +325,13 @@ export class ViewCommands {
}
@debug()
private browseRepoAtRevision(node: ViewRefNode, openInNewWindow: boolean = false) {
private browseRepoAtRevision(node: ViewRefNode, options?: { before?: boolean; openInNewWindow?: boolean }) {
if (!(node instanceof ViewRefNode)) return Promise.resolve();
return GitActions.browseAtRevision(node.uri, { openInNewWindow: openInNewWindow });
return GitActions.browseAtRevision(node.uri, {
before: options?.before,
openInNewWindow: options?.openInNewWindow,
});
}
@debug()

Notiek ielāde…
Atcelt
Saglabāt