MCPcopy
hub / github.com/codeaashu/claude-code / updateGithubRepoPathMapping

Function updateGithubRepoPathMapping

src/utils/githubRepoPathMapping.ts:23–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21 * so the most recently used clone appears first.
22 */
23export async function updateGithubRepoPathMapping(): Promise<void> {
24 try {
25 const repo = await detectCurrentRepository()
26 if (!repo) {
27 logForDebugging(
28 'Not in a GitHub repository, skipping path mapping update',
29 )
30 return
31 }
32
33 // Use the git root as the canonical path for this repo clone.
34 // This ensures we always store the repo root, not an arbitrary subdirectory.
35 const cwd = getOriginalCwd()
36 const gitRoot = findGitRoot(cwd)
37 const basePath = gitRoot ?? cwd
38
39 // Resolve symlinks for canonical storage
40 let currentPath: string
41 try {
42 currentPath = (await realpath(basePath)).normalize('NFC')
43 } catch {
44 currentPath = basePath
45 }
46
47 // Normalize repo key to lowercase for case-insensitive matching
48 const repoKey = repo.toLowerCase()
49
50 const config = getGlobalConfig()
51 const existingPaths = config.githubRepoPaths?.[repoKey] ?? []
52
53 if (existingPaths[0] === currentPath) {
54 // Already at the front — nothing to do
55 logForDebugging(`Path ${currentPath} already tracked for repo ${repoKey}`)
56 return
57 }
58
59 // Remove if present elsewhere (to promote to front), then prepend
60 const withoutCurrent = existingPaths.filter(p => p !== currentPath)
61 const updatedPaths = [currentPath, ...withoutCurrent]
62
63 saveGlobalConfig(current => ({
64 ...current,
65 githubRepoPaths: {
66 ...current.githubRepoPaths,
67 [repoKey]: updatedPaths,
68 },
69 }))
70
71 logForDebugging(`Added ${currentPath} to tracked paths for repo ${repoKey}`)
72 } catch (error) {
73 logForDebugging(`Error updating repo path mapping: ${error}`)
74 // Silently fail - this is non-blocking startup work
75 }
76}
77
78/**
79 * Gets known local paths for a given GitHub repository.

Callers 1

showSetupScreensFunction · 0.85

Calls 5

detectCurrentRepositoryFunction · 0.85
logForDebuggingFunction · 0.85
getOriginalCwdFunction · 0.85
getGlobalConfigFunction · 0.85
saveGlobalConfigFunction · 0.85

Tested by

no test coverage detected