Skip to content

Commit

Permalink
Fix .git being the CWD
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Dec 27, 2024
1 parent e0e6f05 commit 64ce7f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readdir } from 'node:fs/promises'
import { parse, relative, sep, join } from 'node:path'
import { parse, relative, sep, join, dirname } from 'node:path'
import pc from 'picocolors'
import { isGitIgnored } from 'globby'
import * as find from 'empathic/find'
Expand All @@ -11,7 +11,8 @@ import { ExitException } from './exit-exception'

/** The maximum Levenshtein distance between the input and the reference for the input to be considered a typo. */
const typoThreshold = 5
const isIgnored = await isGitIgnored({ cwd: find.up('.git') })
const gitFolder = find.up('.git')
const isIgnored = await isGitIgnored({ cwd: gitFolder ? dirname(gitFolder) : undefined })

/** Present the user with a choice of folders based on similarity to a given input. */
export async function chooseFromSimilar(input: string): Promise<string> {
Expand Down
5 changes: 3 additions & 2 deletions packages/steiger/src/features/transfer-fs-to-vfs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, sep } from 'node:path'
import { dirname, join, sep } from 'node:path'
import chokidar from 'chokidar'
import * as find from 'empathic/find'
import type { Folder } from '@steiger/types'
Expand All @@ -13,7 +13,8 @@ import { createVfsRoot } from '../models/vfs'
*/
export async function createWatcher(path: string) {
const vfs = createVfsRoot(path)
const isIgnored = await isGitIgnored({ cwd: find.up('.git', { cwd: path }) ?? path })
const gitFolder = find.up('.git', { cwd: path })
const isIgnored = await isGitIgnored({ cwd: gitFolder ? dirname(gitFolder) : path })

const watcher = chokidar.watch(path, {
ignored: (path) => path.split(sep).includes('node_modules') || path.split(sep).includes('.git') || isIgnored(path),
Expand Down

0 comments on commit 64ce7f2

Please sign in to comment.