Browse Source

Fixes changing to Push command on HEAD commit

Previous commit a664073
main
Eric Amodio 3 years ago
parent
commit
3b7ea57f24
4 changed files with 33 additions and 5 deletions
  1. +12
    -2
      package.json
  2. +5
    -1
      src/views/nodes/commitNode.ts
  3. +5
    -1
      src/views/nodes/fileRevisionAsCommitNode.ts
  4. +11
    -1
      src/views/viewCommands.ts

+ 12
- 2
package.json View File

@ -7362,8 +7362,13 @@
"group": "inline@-2"
},
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+unpublished\\b)(?=.*?\\b\\+HEAD\\b)/",
"group": "inline@-1"
},
{
"command": "gitlens.views.pushToCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+unpublished\\b)/",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+unpublished\\b)(?!.*?\\b\\+HEAD\\b)/",
"group": "inline@-1"
},
{
@ -8113,8 +8118,13 @@
],
"gitlens/commit/file/commit": [
{
"command": "gitlens.views.push",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+unpublished\\b)(?=.*?\\b\\+HEAD\\b)/",
"group": "1_gitlens_actions@0"
},
{
"command": "gitlens.views.pushToCommit",
"when": "!gitlens:readonly && viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+unpublished\\b)/",
"when": "gitlens:hasRemotes && !gitlens:readonly && viewItem =~ /gitlens:file\\b(?=.*?\\b\\+committed\\b)(?=.*?\\b\\+current\\b)(?=.*?\\b\\+unpublished\\b)(?!.*?\\b\\+HEAD\\b)/",
"group": "1_gitlens_actions@0"
},
{

+ 5
- 1
src/views/nodes/commitNode.ts View File

@ -37,6 +37,10 @@ export class CommitNode extends ViewRefNode
return `${this.commit.shortSha}: ${message}`;
}
get isTip(): boolean {
return (this.branch?.current && this.branch.sha === this.commit.ref) ?? false;
}
get ref(): GitRevisionReference {
return this.commit;
}
@ -110,7 +114,7 @@ export class CommitNode extends ViewRefNode
);
item.contextValue = `${ContextValues.Commit}${this.branch?.current ? '+current' : ''}${
this.branch?.current && this.branch.sha === this.commit.ref ? '+HEAD' : ''
this.isTip ? '+HEAD' : ''
}${this.unpublished ? '+unpublished' : ''}`;
item.description = CommitFormatter.fromTemplate(this.view.config.formats.commits.description, this.commit, {

+ 5
- 1
src/views/nodes/fileRevisionAsCommitNode.ts View File

@ -49,6 +49,10 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode
return this.file.fileName;
}
get isTip(): boolean {
return (this._options.branch?.current && this._options.branch.sha === this.commit.ref) ?? false;
}
get ref(): GitRevisionReference {
return this.commit;
}
@ -142,7 +146,7 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode
protected get contextValue(): string {
if (!this.commit.isUncommitted) {
return `${ContextValues.File}+committed${this._options.branch?.current ? '+current' : ''}${
this._options.branch?.current && this._options.branch.sha === this.commit.ref ? '+HEAD' : ''
this.isTip ? '+HEAD' : ''
}${this._options.unpublished ? '+unpublished' : ''}`;
}

+ 11
- 1
src/views/viewCommands.ts View File

@ -449,11 +449,21 @@ export class ViewCommands {
}
@debug()
private push(node: RepositoryNode | BranchNode | BranchTrackingStatusNode, force?: boolean) {
private push(
node: RepositoryNode | BranchNode | BranchTrackingStatusNode | CommitNode | FileRevisionAsCommitNode,
force?: boolean,
) {
if (node instanceof RepositoryNode) 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);
}
return this.pushToCommit(node);
}
return Promise.resolve();
}

Loading…
Cancel
Save