native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #112 from supabitapp/fix/bare-repo-name-and-base-dir

Fix bare repository naming and base-dir collisions

authored by

khoi and committed by
GitHub
060c6038 0ae81a0d

+67 -10
+6
supacode/Domain/Repository.swift
··· 13 13 14 14 static func name(for rootURL: URL) -> String { 15 15 let name = rootURL.lastPathComponent 16 + if name == ".bare" || name == ".git" { 17 + let parentName = rootURL.deletingLastPathComponent().lastPathComponent 18 + if !parentName.isEmpty, parentName != "/" { 19 + return parentName 20 + } 21 + } 16 22 if name.isEmpty { 17 23 return rootURL.path(percentEncoded: false) 18 24 }
+14 -3
supacode/Support/SupacodePaths.swift
··· 11 11 } 12 12 13 13 static func repositoryDirectory(for rootURL: URL) -> URL { 14 - let repoName = rootURL.lastPathComponent 15 - let fallback = rootURL.path(percentEncoded: false).replacing("/", with: "_") 16 - let name = repoName.isEmpty ? fallback : repoName 14 + let name = repositoryDirectoryName(for: rootURL) 17 15 return reposDirectory.appending(path: name, directoryHint: .isDirectory) 18 16 } 19 17 20 18 static var settingsURL: URL { 21 19 baseDirectory.appending(path: "settings.json", directoryHint: .notDirectory) 20 + } 21 + 22 + private static func repositoryDirectoryName(for rootURL: URL) -> String { 23 + let repoName = rootURL.lastPathComponent 24 + if repoName.isEmpty || repoName == ".bare" || repoName == ".git" { 25 + let path = rootURL.standardizedFileURL.path(percentEncoded: false) 26 + let trimmed = path.trimmingCharacters(in: CharacterSet(charactersIn: "/")) 27 + if trimmed.isEmpty { 28 + return "_" 29 + } 30 + return trimmed.replacing("/", with: "_") 31 + } 32 + return repoName 22 33 } 23 34 }
+3 -7
supacodeTests/AppShortcutsTests.swift
··· 18 18 } 19 19 } 20 20 21 - @Test func worktreeSelectionUsesCommandNumberShortcuts() { 21 + @Test func worktreeSelectionUsesControlNumberShortcuts() { 22 22 expectNoDifference( 23 23 AppShortcuts.worktreeSelection.map(\.display), 24 - ["⌘1", "⌘2", "⌘3", "⌘4", "⌘5", "⌘6", "⌘7", "⌘8", "⌘9", "⌘0"] 24 + ["⌃1", "⌃2", "⌃3", "⌃4", "⌃5", "⌃6", "⌃7", "⌃8", "⌃9", "⌃0"] 25 25 ) 26 26 27 27 for shortcut in AppShortcuts.worktreeSelection { 28 - #expect(shortcut.modifiers == .command) 28 + #expect(shortcut.modifiers == .control) 29 29 } 30 30 } 31 31 ··· 66 66 67 67 for argument in AppShortcuts.tabSelectionGhosttyKeybindArguments { 68 68 #expect(arguments.contains(argument)) 69 - } 70 - 71 - for argument in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"].map({ "--keybind=ctrl+\($0)=unbind" }) { 72 - #expect(arguments.contains(argument) == false) 73 69 } 74 70 75 71 for argument in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"].map({ "--keybind=ctrl+digit_\($0)=unbind" }) {
+44
supacodeTests/RepositoryPathsTests.swift
··· 1 + import Foundation 2 + import Testing 3 + 4 + @testable import supacode 5 + 6 + struct RepositoryNameTests { 7 + @Test func usesParentDirectoryNameForBareRepositoryRoots() { 8 + let root = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare") 9 + 10 + #expect(Repository.name(for: root) == "repo-alpha") 11 + } 12 + 13 + @Test func preservesNormalRepositoryName() { 14 + let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") 15 + 16 + #expect(Repository.name(for: root) == "repo-alpha") 17 + } 18 + } 19 + 20 + struct SupacodePathsTests { 21 + @Test func repositoryDirectoryUsesRepoNameForNormalRoots() { 22 + let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") 23 + let directory = SupacodePaths.repositoryDirectory(for: root) 24 + 25 + #expect(directory.lastPathComponent == "repo-alpha") 26 + } 27 + 28 + @Test func repositoryDirectoryUsesSanitizedPathForBareRoots() { 29 + let root = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare") 30 + let directory = SupacodePaths.repositoryDirectory(for: root) 31 + 32 + #expect(directory.lastPathComponent == "tmp_work_repo-alpha_.bare") 33 + } 34 + 35 + @Test func repositoryDirectoryDoesNotCollideForDifferentBareRoots() { 36 + let firstRoot = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare") 37 + let secondRoot = URL(fileURLWithPath: "/tmp/work/repo-beta/.bare") 38 + 39 + let firstDirectory = SupacodePaths.repositoryDirectory(for: firstRoot) 40 + let secondDirectory = SupacodePaths.repositoryDirectory(for: secondRoot) 41 + 42 + #expect(firstDirectory != secondDirectory) 43 + } 44 + }