krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

Tests/OrgAppTests/GitBranchTests.swift

778058aafc7ddacee4a613b1da87c60aa0c8e113
orgstar/Tests/OrgAppTests/GitBranchTests.swift history · blame · raw

31 lines · 1678 bytes

3 symbols in this file
 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}