You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

35 lines
1.2 KiB

import type { TextEditor, Uri } from 'vscode';
import { env, window } from 'vscode';
import { Commands } from '../constants';
import type { Container } from '../container';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
import { RepositoryPicker } from '../quickpicks/repositoryPicker';
import { command } from '../system/command';
import { ActiveEditorCommand, getCommandUri } from './base';
@command()
export class CopyCurrentBranchCommand extends ActiveEditorCommand {
constructor(private readonly container: Container) {
super(Commands.CopyCurrentBranch);
}
async execute(editor?: TextEditor, uri?: Uri) {
uri = getCommandUri(uri, editor);
const gitUri = uri != null ? await GitUri.fromUri(uri) : undefined;
const repository = await RepositoryPicker.getBestRepositoryOrShow(gitUri, editor, 'Copy Current Branch Name');
if (repository == null) return;
try {
const branch = await repository.getBranch();
if (branch?.name) {
await env.clipboard.writeText(branch.name);
}
} catch (ex) {
Logger.error(ex, 'CopyCurrentBranchCommand');
void window.showErrorMessage('Unable to copy current branch name. See output channel for more details');
}
}
}