Repository - SwiftDocOrg/Git GitHub Wiki

Repository

public final class Repository

Properties

commonDirectory

The repository's working directory.

var commonDirectory:​ URL?

For example, path/to/repository/.git.

workingDirectory

The repository's working directory, or nil if the repository is bare.

var workingDirectory:​ URL?

For example, path/to/repository.

index

The repository index, if any.

var index:​ Index?

head

The HEAD of the repository.

var head:​ Head?

attributes

var attributes:​ Attributes

Methods

open(at:​)

public class func open(at url:​ URL) throws -> Repository

create(at:​bare:​)

public class func create(at url:​ URL, bare:​ Bool = false) throws -> Repository

discover(at:​acrossFileSystems:​stoppingAt:​)

public class func discover(at url:​ URL, acrossFileSystems:​ Bool = true, stoppingAt ceilingDirectories:[String] = []) throws -> Repository

clone(from:​to:​configuration:​)

@discardableResult public static func clone(from remoteURL:​ URL, to localURL:​ URL, configuration:​ Clone.Configuration = .default) throws -> Repository

branch(named:​)

Returns a branch by name.

public func branch(named name:​ String) throws -> Branch?

revision(matching:​)

Returns the revision matching the provided specification.

public func revision(matching specification:​ String) throws -> (Commit?, Reference?)

Parameters

  • specification:​ A revision specification.
  • Returns:​ A tuple containing the commit and/or reference matching the specification.

distance(from:​to:​)

Calculates the number of unique revisions between two commits.

public func distance(from local:​ Commit, to upstream:​ Commit) throws -> (ahead:​ Int, behind:​ Int)

Parameters

  • local:​ The local commit.
  • upstream:​ The upstream commit.
  • Returns:​ A tuple with the number of commits ahead and behind.

createCommit(message:​author:​committer:​)

@discardableResult public func createCommit(message:​ String, author:​ Signature? = nil, committer:​ Signature? = nil) throws -> Commit

createLightweightTag(named:​target:​force:​)

Creates a lightweight tag.

public func createLightweightTag(named name:​ String, target:​ Object, force:​ Bool = false) throws

createAnnotatedTag(named:​target:​tagger:​message:​force:​)

Creates an annotated tag.

public func createAnnotatedTag(named name:​ String, target:​ Object, tagger:​ Signature? = nil, message:​ String, force:​ Bool = false) throws

tagNames()

public func tagNames() throws -> [String]

tagNames(matching:​)

public func tagNames(matching pattern:​ String) throws -> [String]

revisions(with:​)

Returns a sequence of revisions according to the specified configuration.

public func revisions(with configuration:(RevisionWalker) throws -> Void) throws -> AnySequence<Commit>

Parameters

  • configuration:​ A closure whose argument can be modified to change which revisions are returned by the sequence, and the order in which they appear.

Throws

Any error that occured during configuration.

Returns

A sequence of revisions.

⚠️ **GitHub.com Fallback** ⚠️