@ -27,11 +27,19 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
super ( Commands . CopyMessageToClipboard ) ;
}
protected override preExecute ( context : CommandContext , args? : CopyMessageToClipboardCommandArgs ) {
protected override async preExecute ( context : CommandContext , args? : CopyMessageToClipboardCommandArgs ) {
if ( isCommandContextViewNodeHasCommit ( context ) ) {
args = { . . . args } ;
args . sha = context . node . commit . sha ;
return this . execute ( context . editor , context . node . commit . file ? . uri , args ) ;
if ( context . node . commit . message != null ) {
await context . node . commit . ensureFullDetails ( ) ;
}
args . message = context . node . commit . message ;
return this . execute (
context . editor ,
context . node . commit . file ? . uri ? ? context . node . commit . getRepository ( ) ? . uri ,
args ,
) ;
} else if ( isCommandContextViewNodeHasBranch ( context ) ) {
args = { . . . args } ;
args . sha = context . node . branch . sha ;
@ -50,43 +58,45 @@ export class CopyMessageToClipboardCommand extends ActiveEditorCommand {
args = { . . . args } ;
try {
let repoPath ;
if ( ! args . message ) {
let repoPath ;
// If we don't have an editor then get the message of the last commit to the branch
if ( uri == null ) {
repoPath = this . container . git . getBestRepository ( editor ) ? . path ;
if ( ! repoPath ) return ;
// If we don't have an editor then get the message of the last commit to the branch
if ( uri == null ) {
repoPath = this . container . git . getBestRepository ( editor ) ? . path ;
if ( ! repoPath ) return ;
const log = await this . container . git . getLog ( repoPath , { limit : 1 } ) ;
if ( log == null ) return ;
const log = await this . container . git . getLog ( repoPath , { limit : 1 } ) ;
if ( log == null ) return ;
const commit = first ( log . commits . values ( ) ) ;
if ( commit ? . message == null ) return ;
const commit = first ( log . commits . values ( ) ) ;
if ( commit ? . message == null ) return ;
args . message = commit . message ;
} else if ( args . message == null ) {
const gitUri = await GitUri . fromUri ( uri ) ;
repoPath = gitUri . repoPath ;
args . message = commit . message ;
} else if ( args . message == null ) {
const gitUri = await GitUri . fromUri ( uri ) ;
repoPath = gitUri . repoPath ;
if ( args . sha == null ) {
const blameline = editor ? . selection . active . line ? ? 0 ;
if ( blameline < 0 ) return ;
if ( args . sha == null ) {
const blameline = editor ? . selection . active . line ? ? 0 ;
if ( blameline < 0 ) return ;
try {
const blame = await this . container . git . getBlameForLine ( gitUri , blameline , editor ? . document ) ;
if ( blame == null || blame . commit . isUncommitted ) return ;
try {
const blame = await this . container . git . getBlameForLine ( gitUri , blameline , editor ? . document ) ;
if ( blame == null || blame . commit . isUncommitted ) return ;
void ( await GitActions . Commit . copyMessageToClipboard ( blame . commit ) ) ;
return ;
} catch ( ex ) {
Logger . error ( ex , 'CopyMessageToClipboardCommand' , ` getBlameForLine( ${ blameline } ) ` ) ;
void Messages . showGenericErrorMessage ( 'Unable to copy message' ) ;
void ( await GitActions . Commit . copyMessageToClipboard ( blame . commit ) ) ;
return ;
} catch ( ex ) {
Logger . error ( ex , 'CopyMessageToClipboardCommand' , ` getBlameForLine( ${ blameline } ) ` ) ;
void Messages . showGenericErrorMessage ( 'Unable to copy message' ) ;
return ;
}
} else {
void ( await GitActions . Commit . copyMessageToClipboard ( { ref : args.sha , repoPath : repoPath ! } ) ) ;
return ;
}
} else {
void ( await GitActions . Commit . copyMessageToClipboard ( { ref : args.sha , repoPath : repoPath ! } ) ) ;
return ;
}
}