@ -33,7 +33,7 @@ import {
} from '../system/command' ;
import { configuration } from '../system/configuration' ;
import { setContext } from '../system/context' ;
import { debu g } from '../system/decorators/log' ;
import { lo g } from '../system/decorators/log' ;
import { sequentialize } from '../system/function' ;
import type { OpenWorkspaceLocation } from '../system/utils' ;
import { openWorkspace } from '../system/utils' ;
@ -61,7 +61,6 @@ import { StatusFileNode } from './nodes/statusFileNode';
import { TagNode } from './nodes/tagNode' ;
import type { TagsNode } from './nodes/tagsNode' ;
import {
canClearNode ,
canEditNode ,
canViewDismissNode ,
getNodeRepoPath ,
@ -122,7 +121,8 @@ export function registerViewCommand(
export class ViewCommands {
constructor ( private readonly container : Container ) {
registerViewCommand ( 'gitlens.views.clearNode' , ( n : ViewNode ) = > canClearNode ( n ) && n . clear ( ) , this ) ;
registerViewCommand ( 'gitlens.views.clearComparison' , n = > this . clearComparison ( n ) , this ) ;
registerViewCommand ( 'gitlens.views.clearReviewed' , n = > this . clearReviewed ( n ) , this ) ;
// Register independently as it already handles copying multiple nodes
registerCommand (
Commands . ViewsCopy ,
@ -312,12 +312,12 @@ export class ViewCommands {
) ;
}
@debu g ( )
@lo g ( )
private addAuthors ( node? : ViewNode ) {
return ContributorActions . addAuthors ( getNodeRepoPath ( node ) ) ;
}
@debu g ( )
@lo g ( )
private addAuthor ( node? : ContributorNode ) {
if ( node instanceof ContributorNode ) {
return ContributorActions . addAuthors (
@ -329,12 +329,12 @@ export class ViewCommands {
return Promise . resolve ( ) ;
}
@debu g ( )
@lo g ( )
private addRemote ( node? : ViewNode ) {
return RemoteActions . add ( getNodeRepoPath ( node ) ) ;
}
@debu g ( )
@lo g ( )
private applyChanges ( node : ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefFileNode ) ) return Promise . resolve ( ) ;
@ -351,12 +351,12 @@ export class ViewCommands {
return CommitActions . applyChanges ( node . file , node . ref ) ;
}
@debu g ( )
@lo g ( )
private applyStash() {
return StashActions . apply ( ) ;
}
@debu g ( )
@lo g ( )
private browseRepoAtRevision (
node : ViewRefNode | ViewRefFileNode ,
options ? : { before? : boolean ; openInNewWindow? : boolean } ,
@ -369,7 +369,7 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private cherryPick ( node : CommitNode , nodes? : CommitNode [ ] ) {
if ( ! ( node instanceof CommitNode ) ) return Promise . resolve ( ) ;
@ -383,14 +383,36 @@ export class ViewCommands {
return RepoActions . cherryPick ( node . repoPath , node . ref ) ;
}
@debug ( )
@log ( )
private clearComparison ( node : ViewNode ) {
if ( node . is ( 'compare-branch' ) ) {
void node . clear ( ) ;
}
}
@log ( )
private clearReviewed ( node : ViewNode ) {
let compareNode ;
if ( node . is ( 'results-files' ) ) {
compareNode = node . getParent ( ) ;
if ( compareNode == null ) return ;
} else {
compareNode = node ;
}
if ( compareNode . is ( 'compare-branch' ) || compareNode . is ( 'compare-results' ) ) {
compareNode . clearReviewed ( ) ;
}
}
@log ( )
private closeRepository ( node : RepositoryNode | RepositoryFolderNode ) {
if ( ! ( node instanceof RepositoryNode ) && ! ( node instanceof RepositoryFolderNode ) ) return ;
node . repo . closed = true ;
}
@debug ( )
@lo g ( )
private async createBranch ( node? : ViewRefNode | ViewRefFileNode | BranchesNode | BranchTrackingStatusNode ) {
let from =
node instanceof ViewRefNode || node instanceof ViewRefFileNode
@ -407,7 +429,7 @@ export class ViewCommands {
return BranchActions . create ( node ? . repoPath , from ) ;
}
@debu g ( )
@lo g ( )
private async createPullRequest ( node : BranchNode | BranchTrackingStatusNode ) {
if ( ! ( node instanceof BranchNode ) && ! ( node instanceof BranchTrackingStatusNode ) ) {
return Promise . resolve ( ) ;
@ -440,7 +462,7 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private async createTag ( node? : ViewRefNode | ViewRefFileNode | TagsNode | BranchTrackingStatusNode ) {
let from =
node instanceof ViewRefNode || node instanceof ViewRefFileNode
@ -457,7 +479,7 @@ export class ViewCommands {
return TagActions . create ( node ? . repoPath , from ) ;
}
@debu g ( )
@lo g ( )
private async createWorktree ( node? : BranchNode | WorktreesNode ) {
if ( node instanceof WorktreesNode ) {
node = undefined ;
@ -467,14 +489,14 @@ export class ViewCommands {
return WorktreeActions . create ( node ? . repoPath , undefined , node ? . ref ) ;
}
@debu g ( )
@lo g ( )
private deleteBranch ( node : BranchNode ) {
if ( ! ( node instanceof BranchNode ) ) return Promise . resolve ( ) ;
return BranchActions . remove ( node . repoPath , node . branch ) ;
}
@debu g ( )
@lo g ( )
private deleteStash ( node : StashNode , nodes? : StashNode [ ] ) {
if ( ! ( node instanceof StashNode ) ) return Promise . resolve ( ) ;
@ -490,28 +512,28 @@ export class ViewCommands {
return StashActions . drop ( node . repoPath , node . commit ) ;
}
@debu g ( )
@lo g ( )
private renameStash ( node : StashNode ) {
if ( ! ( node instanceof StashNode ) ) return Promise . resolve ( ) ;
return StashActions . rename ( node . repoPath , node . commit ) ;
}
@debu g ( )
@lo g ( )
private deleteTag ( node : TagNode ) {
if ( ! ( node instanceof TagNode ) ) return Promise . resolve ( ) ;
return TagActions . remove ( node . repoPath , node . tag ) ;
}
@debu g ( )
@lo g ( )
private async deleteWorktree ( node : WorktreeNode ) {
if ( ! ( node instanceof WorktreeNode ) ) return undefined ;
return WorktreeActions . remove ( node . repoPath , node . worktree . uri ) ;
}
@debu g ( )
@lo g ( )
private fetch ( node : RemoteNode | RepositoryNode | RepositoryFolderNode | BranchNode | BranchTrackingStatusNode ) {
if ( node instanceof RepositoryNode || node instanceof RepositoryFolderNode ) return RepoActions . fetch ( node . repo ) ;
if ( node instanceof RemoteNode ) return RemoteActions . fetch ( node . remote . repoPath , node . remote . name ) ;
@ -522,7 +544,7 @@ export class ViewCommands {
return Promise . resolve ( ) ;
}
@debu g ( )
@lo g ( )
private async highlightChanges ( node : CommitFileNode | StashFileNode | FileRevisionAsCommitNode | ResultsFileNode ) {
if (
! ( node instanceof CommitFileNode ) &&
@ -542,7 +564,7 @@ export class ViewCommands {
) ) ;
}
@debu g ( )
@lo g ( )
private async highlightRevisionChanges (
node : CommitFileNode | StashFileNode | FileRevisionAsCommitNode | ResultsFileNode ,
) {
@ -564,21 +586,21 @@ export class ViewCommands {
) ) ;
}
@debu g ( )
@lo g ( )
private merge ( node : BranchNode | TagNode ) {
if ( ! ( node instanceof BranchNode ) && ! ( node instanceof TagNode ) ) return Promise . resolve ( ) ;
return RepoActions . merge ( node . repoPath , node instanceof BranchNode ? node.branch : node.tag ) ;
}
@debu g ( )
@lo g ( )
private openInTerminal ( node : RepositoryNode | RepositoryFolderNode ) {
if ( ! ( node instanceof RepositoryNode ) && ! ( node instanceof RepositoryFolderNode ) ) return Promise . resolve ( ) ;
return executeCoreCommand ( 'openInTerminal' , Uri . file ( node . repo . path ) ) ;
}
@debu g ( )
@lo g ( )
private openPullRequest ( node : PullRequestNode ) {
if ( ! ( node instanceof PullRequestNode ) ) return Promise . resolve ( ) ;
@ -596,28 +618,28 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private openWorktree ( node : WorktreeNode , options ? : { location? : OpenWorkspaceLocation } ) {
if ( ! ( node instanceof WorktreeNode ) ) return ;
openWorkspace ( node . worktree . uri , options ) ;
}
@debu g ( )
@lo g ( )
private pruneRemote ( node : RemoteNode ) {
if ( ! ( node instanceof RemoteNode ) ) return Promise . resolve ( ) ;
return RemoteActions . prune ( node . remote . repoPath , node . remote . name ) ;
}
@debu g ( )
@lo g ( )
private async removeRemote ( node : RemoteNode ) {
if ( ! ( node instanceof RemoteNode ) ) return Promise . resolve ( ) ;
return RemoteActions . remove ( node . remote . repoPath , node . remote . name ) ;
}
@debu g ( )
@lo g ( )
private publishBranch ( node : BranchNode | BranchTrackingStatusNode ) {
if ( node instanceof BranchNode || node instanceof BranchTrackingStatusNode ) {
return RepoActions . push ( node . repoPath , undefined , node . branch ) ;
@ -625,7 +647,7 @@ export class ViewCommands {
return Promise . resolve ( ) ;
}
@debu g ( )
@lo g ( )
private publishRepository ( node : BranchNode | BranchTrackingStatusNode ) {
if ( node instanceof BranchNode || node instanceof BranchTrackingStatusNode ) {
return executeCoreGitCommand ( 'git.publish' , Uri . file ( node . repoPath ) ) ;
@ -633,7 +655,7 @@ export class ViewCommands {
return Promise . resolve ( ) ;
}
@debu g ( )
@lo g ( )
private pull ( node : RepositoryNode | RepositoryFolderNode | BranchNode | BranchTrackingStatusNode ) {
if ( node instanceof RepositoryNode || node instanceof RepositoryFolderNode ) return RepoActions . pull ( node . repo ) ;
if ( node instanceof BranchNode || node instanceof BranchTrackingStatusNode ) {
@ -643,7 +665,7 @@ export class ViewCommands {
return Promise . resolve ( ) ;
}
@debu g ( )
@lo g ( )
private push (
node :
| RepositoryNode
@ -673,14 +695,14 @@ export class ViewCommands {
return Promise . resolve ( ) ;
}
@debu g ( )
@lo g ( )
private pushToCommit ( node : CommitNode | FileRevisionAsCommitNode ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof FileRevisionAsCommitNode ) ) return Promise . resolve ( ) ;
return RepoActions . push ( node . repoPath , false , node . commit ) ;
}
@debu g ( )
@lo g ( )
private rebase ( node : BranchNode | CommitNode | FileRevisionAsCommitNode | TagNode ) {
if (
! ( node instanceof BranchNode ) &&
@ -694,7 +716,7 @@ export class ViewCommands {
return RepoActions . rebase ( node . repoPath , node . ref ) ;
}
@debu g ( )
@lo g ( )
private rebaseToRemote ( node : BranchNode | BranchTrackingStatusNode ) {
if ( ! ( node instanceof BranchNode ) && ! ( node instanceof BranchTrackingStatusNode ) ) return Promise . resolve ( ) ;
@ -711,14 +733,14 @@ export class ViewCommands {
) ;
}
@debu g ( )
@lo g ( )
private renameBranch ( node : BranchNode ) {
if ( ! ( node instanceof BranchNode ) ) return Promise . resolve ( ) ;
return BranchActions . rename ( node . repoPath , node . branch ) ;
}
@debu g ( )
@lo g ( )
private resetCommit ( node : CommitNode | FileRevisionAsCommitNode ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof FileRevisionAsCommitNode ) ) return Promise . resolve ( ) ;
@ -732,14 +754,14 @@ export class ViewCommands {
) ;
}
@debu g ( )
@lo g ( )
private resetToCommit ( node : CommitNode | FileRevisionAsCommitNode ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof FileRevisionAsCommitNode ) ) return Promise . resolve ( ) ;
return RepoActions . reset ( node . repoPath , node . ref ) ;
}
@debu g ( )
@lo g ( )
private resetToTip ( node : BranchNode ) {
if ( ! ( node instanceof BranchNode ) ) return Promise . resolve ( ) ;
@ -749,54 +771,54 @@ export class ViewCommands {
) ;
}
@debu g ( )
@lo g ( )
private restore ( node : ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefFileNode ) ) return Promise . resolve ( ) ;
return CommitActions . restoreFile ( node . file , node . ref ) ;
}
@debu g ( )
@lo g ( )
private revealRepositoryInExplorer ( node : RepositoryNode ) {
if ( ! ( node instanceof RepositoryNode ) ) return undefined ;
return RepoActions . revealInFileExplorer ( node . repo ) ;
}
@debu g ( )
@lo g ( )
private revealWorktreeInExplorer ( node : WorktreeNode ) {
if ( ! ( node instanceof WorktreeNode ) ) return undefined ;
return WorktreeActions . revealInFileExplorer ( node . worktree ) ;
}
@debu g ( )
@lo g ( )
private revert ( node : CommitNode | FileRevisionAsCommitNode ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof FileRevisionAsCommitNode ) ) return Promise . resolve ( ) ;
return RepoActions . revert ( node . repoPath , node . ref ) ;
}
@debu g ( )
@lo g ( )
private setAsDefault ( node : RemoteNode ) {
if ( ! ( node instanceof RemoteNode ) ) return Promise . resolve ( ) ;
return node . setAsDefault ( ) ;
}
@debu g ( )
@lo g ( )
private setBranchComparison ( node : ViewNode , comparisonType : Exclude < ViewShowBranchComparison , false > ) {
if ( ! ( node instanceof CompareBranchNode ) ) return undefined ;
return node . setComparisonType ( comparisonType ) ;
}
@debu g ( )
@lo g ( )
private setShowRelativeDateMarkers ( enabled : boolean ) {
return configuration . updateEffective ( 'views.showRelativeDateMarkers' , enabled ) ;
}
@debu g ( )
@lo g ( )
private async stageFile ( node : CommitFileNode | FileRevisionAsCommitNode | StatusFileNode ) {
if (
! ( node instanceof CommitFileNode ) &&
@ -810,7 +832,7 @@ export class ViewCommands {
void node . triggerChange ( ) ;
}
@debu g ( )
@lo g ( )
private async stageDirectory ( node : FolderNode ) {
if ( ! ( node instanceof FolderNode ) || ! node . relativePath ) return ;
@ -818,7 +840,7 @@ export class ViewCommands {
void node . triggerChange ( ) ;
}
@debu g ( )
@lo g ( )
private star ( node : BranchNode | RepositoryNode | RepositoryFolderNode ) {
if (
! ( node instanceof BranchNode ) &&
@ -831,12 +853,12 @@ export class ViewCommands {
return node . star ( ) ;
}
@debu g ( )
@lo g ( )
private switch ( node? : ViewNode ) {
return RepoActions . switchTo ( getNodeRepoPath ( node ) ) ;
}
@debu g ( )
@lo g ( )
private switchTo ( node? : ViewNode ) {
if ( node instanceof ViewRefNode ) {
return RepoActions . switchTo (
@ -848,7 +870,7 @@ export class ViewCommands {
return RepoActions . switchTo ( getNodeRepoPath ( node ) ) ;
}
@debu g ( )
@lo g ( )
private async undoCommit ( node : CommitNode | FileRevisionAsCommitNode ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof FileRevisionAsCommitNode ) ) return ;
@ -869,14 +891,14 @@ export class ViewCommands {
await executeCoreGitCommand ( 'git.undoCommit' , node . repoPath ) ;
}
@debu g ( )
@lo g ( )
private unsetAsDefault ( node : RemoteNode ) {
if ( ! ( node instanceof RemoteNode ) ) return Promise . resolve ( ) ;
return node . setAsDefault ( false ) ;
}
@debu g ( )
@lo g ( )
private async unstageFile ( node : CommitFileNode | FileRevisionAsCommitNode | StatusFileNode ) {
if (
! ( node instanceof CommitFileNode ) &&
@ -890,7 +912,7 @@ export class ViewCommands {
void node . triggerChange ( ) ;
}
@debu g ( )
@lo g ( )
private async unstageDirectory ( node : FolderNode ) {
if ( ! ( node instanceof FolderNode ) || ! node . relativePath ) return ;
@ -898,7 +920,7 @@ export class ViewCommands {
void node . triggerChange ( ) ;
}
@debu g ( )
@lo g ( )
private unstar ( node : BranchNode | RepositoryNode | RepositoryFolderNode ) {
if (
! ( node instanceof BranchNode ) &&
@ -911,7 +933,7 @@ export class ViewCommands {
return node . unstar ( ) ;
}
@debu g ( )
@lo g ( )
private compareHeadWith ( node : ViewRefNode | ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefNode ) && ! ( node instanceof ViewRefFileNode ) ) return Promise . resolve ( ) ;
@ -922,7 +944,7 @@ export class ViewCommands {
return this . container . searchAndCompareView . compare ( node . repoPath , 'HEAD' , node . ref ) ;
}
@debu g ( )
@lo g ( )
private compareWithUpstream ( node : BranchNode ) {
if ( ! ( node instanceof BranchNode ) ) return Promise . resolve ( ) ;
if ( node . branch . upstream == null ) return Promise . resolve ( ) ;
@ -930,7 +952,7 @@ export class ViewCommands {
return this . container . searchAndCompareView . compare ( node . repoPath , node . ref , node . branch . upstream . name ) ;
}
@debu g ( )
@lo g ( )
private compareWorkingWith ( node : ViewRefNode | ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefNode ) && ! ( node instanceof ViewRefFileNode ) ) return Promise . resolve ( ) ;
@ -941,7 +963,7 @@ export class ViewCommands {
return this . container . searchAndCompareView . compare ( node . repoPath , '' , node . ref ) ;
}
@debu g ( )
@lo g ( )
private async compareAncestryWithWorking ( node : BranchNode ) {
if ( ! ( node instanceof BranchNode ) ) return undefined ;
@ -961,14 +983,14 @@ export class ViewCommands {
) ;
}
@debu g ( )
@lo g ( )
private compareWithSelected ( node : ViewRefNode | ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefNode ) && ! ( node instanceof ViewRefFileNode ) ) return ;
this . container . searchAndCompareView . compareWithSelected ( node . repoPath , node . ref ) ;
}
@debu g ( )
@lo g ( )
private selectForCompare ( node : ViewRefNode | ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefNode ) && ! ( node instanceof ViewRefFileNode ) ) return ;
@ -999,7 +1021,7 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private compareFileWithSelected ( node : ViewRefFileNode ) {
if ( this . _selectedFile == null || ! ( node instanceof ViewRefFileNode ) || node . ref == null ) {
return Promise . resolve ( ) ;
@ -1020,7 +1042,7 @@ export class ViewCommands {
private _selectedFile : CompareSelectedInfo | undefined ;
@debu g ( )
@lo g ( )
private selectFileForCompare ( node : ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefFileNode ) || node . ref == null ) return ;
@ -1032,7 +1054,7 @@ export class ViewCommands {
void setContext ( 'gitlens:views:canCompare:file' , true ) ;
}
@debu g ( )
@lo g ( )
private async openAllChanges ( node : CommitNode | StashNode | ResultsFilesNode , options? : TextDocumentShowOptions ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof StashNode ) && ! ( node instanceof ResultsFilesNode ) ) {
return undefined ;
@ -1056,7 +1078,7 @@ export class ViewCommands {
return CommitActions . openAllChanges ( node . commit , options ) ;
}
@debu g ( )
@lo g ( )
private openChanges ( node : ViewRefFileNode | MergeConflictFileNode | StatusFileNode ) {
if (
! ( node instanceof ViewRefFileNode ) &&
@ -1114,7 +1136,7 @@ export class ViewCommands {
// });
}
@debu g ( )
@lo g ( )
private async openAllChangesWithWorking (
node : CommitNode | StashNode | ResultsFilesNode ,
options? : TextDocumentShowOptions ,
@ -1179,7 +1201,7 @@ export class ViewCommands {
// }
}
@debu g ( )
@lo g ( )
private async openChangesWithWorking ( node : ViewRefFileNode | MergeConflictFileNode | StatusFileNode ) {
if (
! ( node instanceof ViewRefFileNode ) &&
@ -1224,7 +1246,7 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private async openPreviousChangesWithWorking ( node : ViewRefFileNode ) {
if ( ! ( node instanceof ViewRefFileNode ) ) return Promise . resolve ( ) ;
@ -1234,7 +1256,7 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private openFile (
node : ViewRefFileNode | MergeConflictFileNode | StatusFileNode | FileHistoryNode | LineHistoryNode ,
options? : TextDocumentShowOptions ,
@ -1256,7 +1278,7 @@ export class ViewCommands {
} ) ;
}
@debu g ( )
@lo g ( )
private async openFiles ( node : CommitNode | StashNode | ResultsFilesNode ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof StashNode ) && ! ( node instanceof ResultsFilesNode ) ) {
return undefined ;
@ -1272,7 +1294,7 @@ export class ViewCommands {
return CommitActions . openFiles ( node . commit ) ;
}
@debu g ( )
@lo g ( )
private async openRevision (
node :
| CommitFileNode
@ -1315,7 +1337,7 @@ export class ViewCommands {
return CommitActions . openFileAtRevision ( uri , options . showOptions ? ? { preserveFocus : true , preview : false } ) ;
}
@debu g ( )
@lo g ( )
private async openRevisions ( node : CommitNode | StashNode | ResultsFilesNode , _options? : TextDocumentShowOptions ) {
if ( ! ( node instanceof CommitNode ) && ! ( node instanceof StashNode ) && ! ( node instanceof ResultsFilesNode ) ) {
return undefined ;
@ -1331,7 +1353,7 @@ export class ViewCommands {
return CommitActions . openFilesAtRevision ( node . commit ) ;
}
@debu g ( )
@lo g ( )
private async setResultsCommitsFilter ( node : ViewNode , filter : boolean ) {
if ( ! node ? . is ( 'compare-results' ) && ! node ? . is ( 'compare-branch' ) ) return ;