Skip to content

Commit

Permalink
use VS Code git extension to get remote URL instead of exec'ing (#426)
Browse files Browse the repository at this point in the history
This is more portable (to the web) and compatible (to non-web platforms
where git is not installed, not in `$PATH`, or not configured, which has
been the source of many user bug reports).



## Test plan

Open a workspace with no `cody.codebase` setting and ensure the chat
sidebar shows the correct repository at the bottom in the context
indicator.
  • Loading branch information
sqs authored Jul 28, 2023
1 parent 12416e0 commit f094de3
Show file tree
Hide file tree
Showing 3 changed files with 420 additions and 6 deletions.
10 changes: 4 additions & 6 deletions vscode/src/chat/ContextProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { spawnSync } from 'child_process'

import * as vscode from 'vscode'

import { ChatClient } from '@sourcegraph/cody-shared/src/chat/chat'
Expand All @@ -17,6 +15,7 @@ import { FilenameContextFetcher } from '../local-context/filename-context-fetche
import { LocalKeywordContextFetcher } from '../local-context/local-keyword-context-fetcher'
import { debug } from '../log'
import { getRerankWithLog } from '../logged-rerank'
import { repositoryRemoteUrl } from '../repository/repositoryHelpers'
import { AuthProvider } from '../services/AuthProvider'
import { LocalStorage } from '../services/LocalStorageProvider'
import { SecretStorage } from '../services/SecretStorageProvider'
Expand Down Expand Up @@ -250,14 +249,13 @@ export async function getCodebaseContext(
telemetryService: TelemetryService
): Promise<CodebaseContext | null> {
const client = new SourcegraphGraphQLAPIClient(config)
const workspaceRoot = editor.getWorkspaceRootPath()
const workspaceRoot = editor.getWorkspaceRootUri()
if (!workspaceRoot) {
return null
}
const gitCommand = spawnSync('git', ['remote', 'get-url', 'origin'], { cwd: workspaceRoot })
const gitOutput = gitCommand.stdout?.toString().trim() || null
const remoteUrl = repositoryRemoteUrl(workspaceRoot)
// Get codebase from config or fallback to getting repository name from git clone URL
const codebase = config.codebase || (gitOutput && convertGitCloneURLToCodebaseName(gitOutput))
const codebase = config.codebase || (remoteUrl ? convertGitCloneURLToCodebaseName(remoteUrl) : null)
if (!codebase) {
return null
}
Expand Down
Loading

0 comments on commit f094de3

Please sign in to comment.