MCPcopy Create free account
hub / github.com/arctic-cli/interface / fromDirectory

Function fromDirectory

packages/arctic/src/project/project.ts:44–128  ·  view source on GitHub ↗
(directory: string)

Source from the content-addressed store, hash-verified

42 }
43
44 export async function fromDirectory(directory: string) {
45 log.info("fromDirectory", { directory })
46
47 const { id, worktree, vcs } = await iife(async () => {
48 const matches = Filesystem.up({ targets: [".git"], start: directory })
49 const git = await matches.next().then((x) => x.value)
50 await matches.return()
51 if (git) {
52 let worktree = path.dirname(git)
53 let id = await Bun.file(path.join(git, "arctic"))
54 .text()
55 .then((x) => x.trim())
56 .catch(() => {})
57 if (!id) {
58 const roots = await $`git rev-list --max-parents=0 --all`
59 .quiet()
60 .nothrow()
61 .cwd(worktree)
62 .text()
63 .then((x) =>
64 x
65 .split("\n")
66 .filter(Boolean)
67 .map((x) => x.trim())
68 .toSorted(),
69 )
70 id = roots[0]
71 if (id) Bun.file(path.join(git, "arctic")).write(id)
72 }
73 if (!id)
74 return {
75 id: "global",
76 worktree,
77 vcs: "git",
78 }
79 worktree = await $`git rev-parse --show-toplevel`
80 .quiet()
81 .nothrow()
82 .cwd(worktree)
83 .text()
84 .then((x) => path.resolve(worktree, x.trim()))
85 return { id, worktree, vcs: "git" }
86 }
87
88 return {
89 id: "global",
90 worktree: "/",
91 vcs: Info.shape.vcs.parse(Flag.ARCTIC_FAKE_VCS),
92 }
93 })
94
95 let existing = await Storage.read<Info>(["project", id]).catch(() => undefined)
96 if (!existing) {
97 existing = {
98 id,
99 worktree,
100 vcs: vcs as Info["vcs"],
101 time: {

Callers

nothing calls this directly

Calls 8

iifeFunction · 0.90
migrateFromGlobalFunction · 0.85
discoverFunction · 0.85
quietMethod · 0.80
textMethod · 0.65
cwdMethod · 0.65
nothrowMethod · 0.65
nextMethod · 0.45

Tested by

no test coverage detected