restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -0,0 +1,20 @@
import Foundation
public enum GitDirectory {
/// The real git directory: `<root>/.git`, or the `gitdir:` target when `.git` is a file (worktrees, submodules).
public static func resolve(root: URL) -> URL {
let dot = root.appendingPathComponent(".git")
var isDir: ObjCBool = false
guard FileManager.default.fileExists(atPath: dot.path, isDirectory: &isDir), !isDir.boolValue,
let text = try? String(contentsOf: dot, encoding: .utf8) else { return dot }
let line = text.trimmingCharacters(in: .whitespacesAndNewlines)
guard line.hasPrefix("gitdir:") else { return dot }
let target = line.dropFirst("gitdir:".count).trimmingCharacters(in: .whitespaces)
return URL(fileURLWithPath: target, relativeTo: root).standardizedFileURL
}
/// The entries whose change means "git state moved": branch switch, staging, commits, pushes, merges.
public static func watchedEntries(gitDirectory dir: URL) -> [URL] {
["HEAD", "index", "refs/heads", "refs/remotes", "logs/HEAD", "MERGE_HEAD"].map { dir.appendingPathComponent($0) }
}
}