Skip to content

Repository

Repository is the root object in Gitty. All operations start from a repository instance.

let repo = try Repository.open(at: URL(fileURLWithPath: "/path/to/repo"))

Throws GittyError if the path is not a valid Git repository.

// Standard repository
let repo = try Repository.initialize(at: URL(fileURLWithPath: "/path/to/new-repo"))
// Bare repository (no working directory)
let bare = try Repository.initialize(at: URL(fileURLWithPath: "/path/to/new-repo.git"), bare: true)
let isRepo = Repository.exists(at: URL(fileURLWithPath: "/some/path"))

Clone is async — it performs network I/O.

let repo = try await Repository.clone(
from: URL(string: "https://github.com/user/repo")!,
to: URL(fileURLWithPath: "/local/path")
)
let repo = try await Repository.clone(
from: URL(string: "https://github.com/user/private-repo")!,
to: URL(fileURLWithPath: "/local/path"),
credentials: .token("ghp_yourtoken")
)
let repo = try await Repository.clone(
from: remoteURL,
to: localURL,
credentials: .token("ghp_yourtoken"),
progress: { p in
print("Received \(p.receivedObjects) / \(p.totalObjects)")
}
)

See Credentials for all authentication options.