Tests/OrgAppTests/GitBranchTests.swift

c287e0efd3134207acd220e1f58667f182a0e726
orgstar/Tests/OrgAppTests/GitBranchTests.swift

31 lines · 1678 bytes

 1import Foundation
 2import Testing
 3@testable import OrgApp
 4
 5struct GitBranchTests {
 6    func folder() throws -> URL {
 7        let url = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-git-\(UUID().uuidString)")
 8        try FileManager.default.createDirectory(at: url.appendingPathComponent("notes/sub"), withIntermediateDirectories: true)
 9        return url
10    }
11
12    @Test func branchDetachedWorktreeAndNone() throws {
13        let root = try folder()
14        defer { try? FileManager.default.removeItem(at: root) }
15        let file = root.appendingPathComponent("notes/sub/a.org").path
16        #expect(GitBranch.current(for: file) == nil)
17
18        try FileManager.default.createDirectory(at: root.appendingPathComponent(".git"), withIntermediateDirectories: true)
19        try "ref: refs/heads/feature/x\n".write(to: root.appendingPathComponent(".git/HEAD"), atomically: true, encoding: .utf8)
20        #expect(GitBranch.current(for: file) == "feature/x")
21
22        try "0123456789abcdef0123456789abcdef01234567\n".write(to: root.appendingPathComponent(".git/HEAD"), atomically: true, encoding: .utf8)
23        #expect(GitBranch.current(for: file) == "0123456")
24
25        let worktree = root.appendingPathComponent("notes/.git")
26        try FileManager.default.createDirectory(at: root.appendingPathComponent(".git/worktrees/w"), withIntermediateDirectories: true)
27        try "ref: refs/heads/wt\n".write(to: root.appendingPathComponent(".git/worktrees/w/HEAD"), atomically: true, encoding: .utf8)
28        try "gitdir: ../.git/worktrees/w\n".write(to: worktree, atomically: true, encoding: .utf8)
29        #expect(GitBranch.current(for: file) == "wt")
30    }
31}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form