Change:
Testing One can copy links to & github & azure repos even though I just created the file and copying such a link will result in empty or 404 on GH. Seeing links to just created file : <img width="451" alt="image" src="https://user-"
No progress on this one yet, but would you expect the actions to be hidden, or would you want to be prompted to commit the file to the remote when the command is invoked?
I think users could be confused if the actions wouldn't appear (eg they might've forgotten the file isn't pushed), so the latter sounds better. But I wonder whether checking whether the file is available on remote would be slow

Discussion:
async function copyVscodeDevLink(gitAPI: GitAPI, useSelection: boolean, context: LinkContext, includeRange = true) { try { <del> const permalink = getLink(gitAPI, useSelection, getVscodeDevHost(), 'headlink', context, includeRange); </del> <ins> const permalink = await getLink(gitAPI, useSelection, getVscodeDevHost(), 'headlink', context, includeRange); </ins> if (permalink) { return vscode.env.clipboard.writeText(permalink); } } catch (err) { <del> vscode.window.showErrorMessage(err.message); </del> <ins> if (!(err instanceof vscode.CancellationError)) { vscode.window.showErrorMessage(err.message); } </ins> } } async function openVscodeDevLink(gitAPI: GitAPI): Promise<vscode.Uri | undefined> { try { <del> const headlink = getLink(gitAPI, true, getVscodeDevHost(), 'headlink'); </del> <ins> const headlink = await getLink(gitAPI, true, getVscodeDevHost(), 'headlink'); </ins> return headlink ? vscode.Uri.parse(headlink) : undefined; } catch (err) { <del> vscode.window.showErrorMessage(err.message); </del> <ins> if (!(err instanceof vscode.CancellationError)) { vscode.window.showErrorMessage(err.message); } </ins> return undefined; } }

*--------------------------------------------------------------------------------------------*/ import * as vscode from 'vscode'; <del> import { API as GitAPI, Repository } from './typings/git'; </del> <ins> import { API as GitAPI, RefType, Repository } from './typings/git'; </ins> import { getRepositoryFromUrl } from './util'; export function isFileInRepo(repository: Repository, file: vscode.Uri): boolean {

return path.split('/').map((segment) => encodeURIComponent(segment)).join('/'); } <del> export function getLink(gitAPI: GitAPI, useSelection: boolean, hostPrefix?: string, linkType: 'permalink' | 'headlink' = 'permalink', context?: LinkContext, useRange?: boolean): string | undefined { </del> <ins> export async function getLink(gitAPI: GitAPI, useSelection: boolean, hostPrefix?: string, linkType: 'permalink' | 'headlink' = 'permalink', context?: LinkContext, useRange?: boolean): Promise<string | undefined> { </ins> hostPrefix = hostPrefix ?? 'https://github.com'; const fileAndPosition = getFileAndPosition(context); if (!fileAndPosition) {

if (!gitRepo) { return; } <ins> await ensurePublished(gitRepo, uri); </ins> let repo: { owner: string; repo: string } | undefined; gitRepo.state.remotes.find(remote => { if (remote.fetchUrl) {

export function getVscodeDevHost(): string { return `https://${vscode.env.appName.toLowerCase().includes('insiders') ? 'insiders.' : ''}vscode.dev/github`; } <ins> export async function ensurePublished(repository: Repository, file: vscode.Uri) { if ((repository.state.HEAD?.type === RefType.Head || repository.state.HEAD?.type === RefType.Tag) // If HEAD is not published, make sure it is && !repository?.state.HEAD?.upstream ) { const publishBranch = vscode.l10n.t('Publish Branch'); const selection = await vscode.window.showInformationMessage( vscode.l10n.t('The current branch is not published to the remote. Would you like to publish your branch before copying a link?'), { modal: true }, publishBranch ); if (selection !== publishBranch) { throw new vscode.CancellationError(); } await vscode.commands.executeCommand('git.publish'); } const uncommittedChanges = [...repository.state.workingTreeChanges, ...repository.state.indexChanges]; if (uncommittedChanges.find((c) => c.uri.toString() === file.toString())) { const commitChanges = vscode.l10n.t('Commit Changes'); const copyAnyway = vscode.l10n.t('Copy Anyway'); const selection = await vscode.window.showWarningMessage( vscode.l10n.t('The current file has uncommitted changes. Please commit your changes before copying a link.'), { modal: true }, commitChanges, copyAnyway ); if (selection !== copyAnyway) { // Focus the SCM view vscode.commands.executeCommand('workbench.view.scm'); throw new vscode.CancellationError(); } } else if (repository.state.HEAD?.ahead) { const pushCommits = vscode.l10n.t('Push Commits'); const selection = await vscode.window.showInformationMessage( vscode.l10n.t('The current branch has unpublished commits. Would you like to push your commits before copying a link?'), { modal: true }, pushCommits ); if (selection !== pushCommits) { throw new vscode.CancellationError(); } await repository.push(); } await repository.status(); } </ins>

import * as vscode from 'vscode'; import { API } from './typings/git'; import { getRepositoryFromUrl, repositoryHasGitHubRemote } from './util'; <del> import { encodeURIComponentExceptSlashes, getRepositoryForFile, notebookCellRangeString, rangeString } from './links'; </del> <ins> import { encodeURIComponentExceptSlashes, ensurePublished, getRepositoryForFile, notebookCellRangeString, rangeString } from './links'; </ins> export class VscodeDevShareProvider implements vscode.ShareProvider, vscode.Disposable { readonly id: string = 'copyVscodeDevLink';

} } <del> provideShare(item: vscode.ShareableItem, _token: vscode.CancellationToken): vscode.ProviderResult<vscode.Uri> { </del> <ins> async provideShare(item: vscode.ShareableItem, _token: vscode.CancellationToken): Promise<vscode.Uri | undefined> { </ins> const repository = getRepositoryForFile(this.gitAPI, item.resourceUri); if (!repository) { return; } <ins> await ensurePublished(repository, item.resourceUri); </ins> let repo: { owner: string; repo: string } | undefined; repository.state.remotes.find(remote => { if (remote.fetchUrl) {