ReviewOS

also looking at this

stacks/gitlint

fix: support linked Git worktrees

#551
Merged chris wants to merge agent/worktree-git-paths into main
4 files +122 -13
src/utils.tsmodified+24-2
Changes to src/utils.ts
@@ -1,13 +1,35 @@
1import { execFileSync } from 'node:child_process'
12import fs from 'node:fs'
23import path from 'node:path'
34import process from 'node:process'
45
6/** Resolve a path below `.git` through Git so linked worktrees are supported. */
7export function resolveCommitMessagePath(filePath: string, cwd: string = process.cwd()): string {
8 const absolutePath = path.resolve(cwd, filePath)
9 const relativePath = path.relative(cwd, absolutePath).split(path.sep).join('/')
10 if (relativePath !== '.git' && !relativePath.startsWith('.git/')) return absolutePath
11
12 const gitPath = relativePath === '.git' ? '' : relativePath.slice('.git/'.length)
13 if (!gitPath) return absolutePath
14
15 try {
16 const resolved = execFileSync('git', ['rev-parse', '--git-path', gitPath], {
17 cwd,
18 encoding: 'utf8',
19 }).trim()
20 return path.resolve(cwd, resolved)
21 }
22 catch {
23 return absolutePath
24 }
25}
26
527/**
628 * Read the commit message from a file
729 */
8export function readCommitMessageFromFile(filePath: string): string {
30export function readCommitMessageFromFile(filePath: string, cwd: string = process.cwd()): string {
931 try {
10 return fs.readFileSync(path.resolve(process.cwd(), filePath), 'utf8')
32 return fs.readFileSync(resolveCommitMessagePath(filePath, cwd), 'utf8')
1133 }
1234 catch (error: unknown) {
1335 console.error(`Error reading commit message file: ${filePath}`)