Skip to content

Commit 85cc3f5

Browse files
committed
Add shared fallback environments
1 parent 3d23be4 commit 85cc3f5

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.skills/swift-git/SKILL.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ _ = try await git.clone([.progress], repository: url, directory: "/tmp/repo") {
5151
}
5252
```
5353

54+
Shared fallback configuration (manual)
55+
```swift
56+
import SwiftGit
57+
import SwiftGitArm64
58+
59+
Git.configureShared(environments: [.embed(.arm64), .system])
60+
let git = try Git.shared
61+
```
62+
5463
Repository constraints (MUST follow)
5564
- Do NOT create commits or push to remote on behalf of a user unless explicitly authorized.
5665
- Do NOT modify the embedded git bundle at Sources/SwiftGit/Resource/git-instance.bundle.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ Important modules (quick code map)
8383

8484
- `Git` (`Sources/SwiftGit/Custom/Git.swift`)
8585
- High-level entrypoint. Use `Git(environment:)` or `try Git.shared` (throws if environment fails).
86+
- Configure shared fallback environments with `Git.configureShared(environments:)`.
8687
- Methods: `run`, `runPublisher`, `data` with variants for arrays of args and string commands.
8788

8889
- `Repository` (`Sources/SwiftGit/Custom/Repository.swift` + `Repository+*.swift`)
@@ -108,6 +109,16 @@ import SwiftGitArm64
108109

109110
let git = Git(environments: [.embed(.arm64), .system])
110111
```
112+
113+
Shared configuration (arm64):
114+
115+
```swift
116+
import SwiftGit
117+
import SwiftGitArm64
118+
119+
Git.configureShared(environments: [.embed(.arm64), .system])
120+
let git = try Git.shared
121+
```
111122
- Agents and tests should not modify files under the bundles. Use `GitEnvironment.Style.custom(URL)` to point to an alternate git distribution.
112123
- To generate updated bundles, run `tools/update-git-bundle.sh` with the desired `--archs` and copy the result into the corresponding `Sources/SwiftGitResources*/Resource/` directory.
113124
- If a bundle looks unusually large, run `tools/fix-git-bundle-links.sh` to relink duplicate `git-*` binaries and shrink the footprint.

Sources/SwiftGit/Custom/Git.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ import Foundation
1111
public class Git {
1212

1313
public static var _shared: Git?
14+
private static var _sharedEnvironments: [GitEnvironment]?
15+
16+
public static func configureShared(environments: [GitEnvironment]) {
17+
precondition(!environments.isEmpty, "Git.shared requires at least one GitEnvironment")
18+
_sharedEnvironments = environments
19+
_shared = nil
20+
}
21+
1422
public static var shared: Git {
1523
get throws {
1624
if let git = _shared { return git }
17-
let git = try Git(environment: .shared)
25+
let environments = _sharedEnvironments ?? [try GitEnvironment.shared]
26+
let git = Git(environments: environments)
1827
_shared = git
1928
return git
2029
}

0 commit comments

Comments
 (0)