ソースを参照

Adds more commands to repo nodes

main
Eric Amodio 3年前
コミット
266608e8a2
4個のファイルの変更166行の追加95行の削除
  1. +51
    -0
      package.json
  2. +4
    -77
      src/views/commitsView.ts
  3. +95
    -12
      src/views/nodes/viewNode.ts
  4. +16
    -6
      src/views/viewCommands.ts

+ 51
- 0
package.json ファイルの表示

@ -8053,6 +8053,22 @@
"group": "8_gitlens_actions_@2"
},
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b(?=.*?\\b\\+ahead\\b)(?!.*?\\b\\+behind\\b)/",
"group": "inline@96",
"alt": "gitlens.views.pushWithForce"
},
{
"command": "gitlens.views.pull",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b(?=.*?\\b\\+behind\\b)/",
"group": "inline@97"
},
{
"command": "gitlens.views.fetch",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b(?!.*?\\b\\+ahead\\b)(?!.*?\\b\\+behind\\b)/",
"group": "inline@98"
},
{
"command": "gitlens.views.star",
"when": "viewItem =~ /gitlens:repo-folder\\b(?!.*?\\b\\+starred\\b)/",
"group": "inline@99"
@ -8063,6 +8079,26 @@
"group": "inline@99"
},
{
"command": "gitlens.views.fetch",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.pull",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b/",
"group": "1_gitlens_actions@1"
},
{
"command": "gitlens.views.pushWithForce",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b/",
"group": "1_gitlens_actions@2"
},
{
"command": "gitlens.views.openInTerminal",
"when": "viewItem =~ /gitlens:repo-folder\\b/",
"group": "2_gitlens_quickopen@1"
@ -8074,6 +8110,21 @@
"alt": "gitlens.copyRemoteRepositoryUrl"
},
{
"command": "gitlens.showCommitSearch",
"when": "viewItem =~ /gitlens:repo-folder\\b/",
"group": "3_gitlens_explore@1"
},
{
"command": "gitlens.stashSave",
"when": "!gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b/",
"group": "1_gitlens_actions_1@1"
},
{
"command": "gitlens.stashApply",
"when": "!gitlens:readonly && viewItem =~ /gitlens:repo-folder\\b/",
"group": "1_gitlens_actions_1@2"
},
{
"command": "gitlens.views.star",
"when": "viewItem =~ /gitlens:repo-folder\\b(?!.*?\\b\\+starred\\b)/",
"group": "8_gitlens_actions_@1"

+ 4
- 77
src/views/commitsView.ts ファイルの表示

@ -4,7 +4,6 @@ import {
commands,
ConfigurationChangeEvent,
Disposable,
MarkdownString,
ProgressLocation,
TreeItem,
TreeItemCollapsibleState,
@ -16,7 +15,6 @@ import { Container } from '../container';
import {
GitLogCommit,
GitReference,
GitRemote,
GitRevisionReference,
Repository,
RepositoryChange,
@ -27,7 +25,6 @@ import { GitUri } from '../git/gitUri';
import {
BranchNode,
BranchTrackingStatusNode,
ContextValues,
RepositoryFolderNode,
RepositoryNode,
unknownGitUri,
@ -68,79 +65,6 @@ export class CommitsRepositoryNode extends RepositoryFolderNode
return this.child.getChildren();
}
async getTreeItem(): Promise<TreeItem> {
this.splatted = false;
let expand = this.repo.starred;
const [active, branch] = await Promise.all([
expand ? undefined : Container.git.isActiveRepoPath(this.uri.repoPath),
this.repo.getBranch(),
]);
if (!expand && (active || (branch?.state.ahead ?? 0) > 0 || (branch?.state.behind ?? 0) > 0)) {
expand = true;
}
const item = new TreeItem(
this.repo.formattedName ?? this.uri.repoPath ?? '',
expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
);
item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`;
if (branch != null) {
const lastFetched = (await this.repo.getLastFetched()) ?? 0;
const status = branch?.getTrackingStatus();
item.description = `${this.repo.supportsChangeEvents ? '' : Strings.pad(GlyphChars.Warning, 1, 2)}${
status ? `${status}${Strings.pad(GlyphChars.Dot, 1, 1)}` : ''
}${branch.name}${
lastFetched
? `${Strings.pad(GlyphChars.Dot, 1, 1)}Last fetched ${Repository.formatLastFetched(lastFetched)}`
: ''
}`;
let providerName;
if (branch.tracking != null) {
const providers = GitRemote.getHighlanderProviders(await Container.git.getRemotes(branch.repoPath));
providerName = providers?.length ? providers[0].name : undefined;
} else {
const remote = await branch.getRemote();
providerName = remote?.provider?.name;
}
item.tooltip = new MarkdownString(
`${this.repo.formattedName ?? this.uri.repoPath ?? ''}${
lastFetched
? `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched ${Repository.formatLastFetched(
lastFetched,
false,
)}`
: ''
}${this.repo.formattedName ? `\n${this.uri.repoPath}` : ''}\n\nCurrent branch $(git-branch) ${
branch.name
}${
branch.tracking
? ` is ${branch.getTrackingStatus({
empty: `up to date with $(git-branch) ${branch.tracking}${
providerName ? ` on ${providerName}` : ''
}`,
expand: true,
icons: true,
separator: ', ',
suffix: ` $(git-branch) ${branch.tracking}${providerName ? ` on ${providerName}` : ''}`,
})}`
: `hasn't been published to ${providerName ?? 'a remote'}`
}${
this.repo.supportsChangeEvents
? ''
: `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`
}`,
true,
);
}
return item;
}
@gate()
@debug()
async refresh(reset: boolean = false) {
@ -213,7 +137,10 @@ export class CommitsViewNode extends ViewNode {
const splat = repositories.length === 1;
this.children = repositories.map(
r => new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat),
r =>
new CommitsRepositoryNode(GitUri.fromRepoPath(r.path), this.view, this, r, splat, {
showBranchAndLastFetched: true,
}),
);
}

+ 95
- 12
src/views/nodes/viewNode.ts ファイルの表示

@ -1,10 +1,19 @@
'use strict';
import { Command, Disposable, Event, TreeItem, TreeItemCollapsibleState, TreeViewVisibilityChangeEvent } from 'vscode';
import {
Command,
Disposable,
Event,
MarkdownString,
TreeItem,
TreeItemCollapsibleState,
TreeViewVisibilityChangeEvent,
} from 'vscode';
import { GlyphChars } from '../../constants';
import { Container } from '../../container';
import {
GitFile,
GitReference,
GitRemote,
GitRevisionReference,
Repository,
RepositoryChange,
@ -319,7 +328,14 @@ export abstract class RepositoryFolderNode<
protected splatted = true;
protected child: TChild | undefined;
constructor(uri: GitUri, view: TView, parent: ViewNode, public readonly repo: Repository, splatted: boolean) {
constructor(
uri: GitUri,
view: TView,
parent: ViewNode,
public readonly repo: Repository,
splatted: boolean,
private readonly options?: { showBranchAndLastFetched?: boolean },
) {
super(uri, view, parent);
this.splatted = splatted;
@ -337,8 +353,16 @@ export abstract class RepositoryFolderNode<
this.splatted = false;
let expand = this.repo.starred;
if (!expand) {
expand = await Container.git.isActiveRepoPath(this.uri.repoPath);
const [active, branch] = await Promise.all([
expand ? undefined : Container.git.isActiveRepoPath(this.uri.repoPath),
this.repo.getBranch(),
]);
const ahead = (branch?.state.ahead ?? 0) > 0;
const behind = (branch?.state.behind ?? 0) > 0;
if (!expand && (active || ahead || behind)) {
expand = true;
}
const item = new TreeItem(
@ -346,14 +370,73 @@ export abstract class RepositoryFolderNode<
expand ? TreeItemCollapsibleState.Expanded : TreeItemCollapsibleState.Collapsed,
);
item.contextValue = `${ContextValues.RepositoryFolder}${this.repo.starred ? '+starred' : ''}`;
item.description = this.repo.supportsChangeEvents ? undefined : Strings.pad(GlyphChars.Warning, 1, 0);
item.tooltip = `${
this.repo.formattedName ? `${this.repo.formattedName}\n${this.uri.repoPath}` : this.uri.repoPath ?? ''
}${
this.repo.supportsChangeEvents
? ''
: `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`
}`;
if (ahead) {
item.contextValue += '+ahead';
}
if (behind) {
item.contextValue += '+behind';
}
if (branch != null && this.options?.showBranchAndLastFetched) {
const lastFetched = (await this.repo.getLastFetched()) ?? 0;
const status = branch.getTrackingStatus();
item.description = `${this.repo.supportsChangeEvents ? '' : Strings.pad(GlyphChars.Warning, 1, 2)}${
status ? `${status}${Strings.pad(GlyphChars.Dot, 1, 1)}` : ''
}${branch.name}${
lastFetched
? `${Strings.pad(GlyphChars.Dot, 1, 1)}Last fetched ${Repository.formatLastFetched(lastFetched)}`
: ''
}`;
let providerName;
if (branch.tracking != null) {
const providers = GitRemote.getHighlanderProviders(await Container.git.getRemotes(branch.repoPath));
providerName = providers?.length ? providers[0].name : undefined;
} else {
const remote = await branch.getRemote();
providerName = remote?.provider?.name;
}
item.tooltip = new MarkdownString(
`${this.repo.formattedName ?? this.uri.repoPath ?? ''}${
lastFetched
? `${Strings.pad(GlyphChars.Dash, 2, 2)}Last fetched ${Repository.formatLastFetched(
lastFetched,
false,
)}`
: ''
}${this.repo.formattedName ? `\n${this.uri.repoPath}` : ''}\n\nCurrent branch $(git-branch) ${
branch.name
}${
branch.tracking
? ` is ${branch.getTrackingStatus({
empty: `up to date with $(git-branch) ${branch.tracking}${
providerName ? ` on ${providerName}` : ''
}`,
expand: true,
icons: true,
separator: ', ',
suffix: ` $(git-branch) ${branch.tracking}${providerName ? ` on ${providerName}` : ''}`,
})}`
: `hasn't been published to ${providerName ?? 'a remote'}`
}${
this.repo.supportsChangeEvents
? ''
: `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`
}`,
true,
);
} else {
item.description = this.repo.supportsChangeEvents ? undefined : Strings.pad(GlyphChars.Warning, 1, 0);
item.tooltip = `${
this.repo.formattedName ? `${this.repo.formattedName}\n${this.uri.repoPath}` : this.uri.repoPath ?? ''
}${
this.repo.supportsChangeEvents
? ''
: `\n\n${GlyphChars.Warning} Unable to automatically detect repository changes`
}`;
}
return item;
}

+ 16
- 6
src/views/viewCommands.ts ファイルの表示

@ -344,8 +344,8 @@ export class ViewCommands {
}
@debug()
private fetch(node: RemoteNode | RepositoryNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode) return GitActions.fetch(node.repo);
private fetch(node: RemoteNode | RepositoryNode | RepositoryFolderNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode || node instanceof RepositoryFolderNode) return GitActions.fetch(node.repo);
if (node instanceof RemoteNode) return GitActions.Remote.fetch(node.remote.repoPath, node.remote.name);
if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
return GitActions.fetch(node.repoPath, node.root ? undefined : node.branch);
@ -459,8 +459,8 @@ export class ViewCommands {
}
@debug()
private pull(node: RepositoryNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode) return GitActions.pull(node.repo);
private pull(node: RepositoryNode | RepositoryFolderNode | BranchNode | BranchTrackingStatusNode) {
if (node instanceof RepositoryNode || node instanceof RepositoryFolderNode) return GitActions.pull(node.repo);
if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
return GitActions.pull(node.repoPath, node.root ? undefined : node.branch);
}
@ -470,13 +470,23 @@ export class ViewCommands {
@debug()
private push(
node: RepositoryNode | BranchNode | BranchTrackingStatusNode | CommitNode | FileRevisionAsCommitNode,
node:
| RepositoryNode
| RepositoryFolderNode
| BranchNode
| BranchTrackingStatusNode
| CommitNode
| FileRevisionAsCommitNode,
force?: boolean,
) {
if (node instanceof RepositoryNode) return GitActions.push(node.repo, force);
if (node instanceof RepositoryNode || node instanceof RepositoryFolderNode) {
return GitActions.push(node.repo, force);
}
if (node instanceof BranchNode || node instanceof BranchTrackingStatusNode) {
return GitActions.push(node.repoPath, undefined, node.root ? undefined : node.branch);
}
if (node instanceof CommitNode || node instanceof FileRevisionAsCommitNode) {
if (node.isTip) {
return GitActions.push(node.repoPath, force);

読み込み中…
キャンセル
保存