mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
Merge develop to master
This commit is contained in:
commit
66866049ee
@ -729,7 +729,7 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "if which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint is not installed\"\nfi";
|
||||
shellScript = "if which swiftlint >/dev/null; then\n swiftlint --lenient\nelse\n echo \"warning: SwiftLint is not installed\"\nfi";
|
||||
};
|
||||
/* End PBXShellScriptBuildPhase section */
|
||||
|
||||
|
||||
@ -64,7 +64,6 @@ extension Reference: Hashable {
|
||||
|
||||
/// A git branch.
|
||||
public struct Branch: ReferenceType {
|
||||
|
||||
/// The full name of the reference (e.g., `refs/heads/master`).
|
||||
public let longName: String
|
||||
|
||||
@ -103,9 +102,9 @@ public struct Branch: ReferenceType {
|
||||
return nil
|
||||
}
|
||||
name = String(validatingUTF8: namePointer!)!
|
||||
|
||||
|
||||
longName = String(validatingUTF8: git_reference_name(pointer))!
|
||||
|
||||
|
||||
var oid: OID
|
||||
if git_reference_type(pointer).rawValue == GIT_REF_SYMBOLIC.rawValue {
|
||||
var resolved: OpaquePointer? = nil
|
||||
@ -120,27 +119,6 @@ public struct Branch: ReferenceType {
|
||||
}
|
||||
commit = PointerTo<Commit>(oid)
|
||||
}
|
||||
|
||||
public func allCommits(in repo: Repository) -> [Commit] {
|
||||
var commits: [Commit] = []
|
||||
var walker: OpaquePointer? = nil
|
||||
var unsafeCommit: OpaquePointer? = nil
|
||||
var oid = self.oid.oid
|
||||
git_revwalk_new(&walker, repo.pointer)
|
||||
git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL.rawValue)
|
||||
git_revwalk_push(walker, &oid)
|
||||
while git_revwalk_next(&oid, walker) == GIT_OK.rawValue {
|
||||
guard
|
||||
git_commit_lookup(&unsafeCommit, repo.pointer, &oid) == GIT_OK.rawValue,
|
||||
let commit = unsafeCommit else {
|
||||
return commits
|
||||
}
|
||||
commits += [Commit(commit)]
|
||||
git_commit_free(unsafeCommit)
|
||||
}
|
||||
git_revwalk_free(walker)
|
||||
return commits
|
||||
}
|
||||
}
|
||||
|
||||
extension Branch: Hashable {
|
||||
|
||||
@ -509,4 +509,35 @@ final public class Repository {
|
||||
progress: CheckoutProgressBlock? = nil) -> Result<(), NSError> {
|
||||
return setHEAD(reference).flatMap { self.checkout(strategy: strategy, progress: progress) }
|
||||
}
|
||||
|
||||
|
||||
/// Load all commits in the specified branch in topological & time order
|
||||
///
|
||||
/// :param: branch The branch to get all commits from
|
||||
/// :returns: Returns a result with array of branches or the error that occurred
|
||||
public func allCommits(in branch: Branch) -> Result<[Commit], NSError> {
|
||||
var commits: [Commit] = []
|
||||
var walker: OpaquePointer? = nil
|
||||
var unsafeCommit: OpaquePointer? = nil
|
||||
var oid = branch.oid.oid
|
||||
git_revwalk_new(&walker, self.pointer)
|
||||
defer {
|
||||
git_revwalk_free(walker)
|
||||
}
|
||||
git_revwalk_sorting(walker, GIT_SORT_TOPOLOGICAL.rawValue)
|
||||
git_revwalk_sorting(walker, GIT_SORT_TIME.rawValue)
|
||||
git_revwalk_push(walker, &oid)
|
||||
while git_revwalk_next(&oid, walker) == GIT_OK.rawValue {
|
||||
let result = git_commit_lookup(&unsafeCommit, self.pointer, &oid)
|
||||
guard result == GIT_OK.rawValue else {
|
||||
return Result.failure(NSError(gitError: result, pointOfFailure: "git_commit_lookup"))
|
||||
}
|
||||
guard let commit = unsafeCommit else {
|
||||
continue
|
||||
}
|
||||
commits += [Commit(commit)]
|
||||
git_commit_free(unsafeCommit)
|
||||
}
|
||||
return Result.success(commits)
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,17 +116,6 @@ class BranchSpec: QuickSpec {
|
||||
expect(branch1.hashValue).to(equal(branch2.hashValue))
|
||||
}
|
||||
}
|
||||
|
||||
describe("Branch.allCommits(in:)") {
|
||||
it("should return all (9) commits") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
var count = 0
|
||||
for branch in repo.localBranches().value! {
|
||||
count += branch.allCommits(in: repo).count
|
||||
}
|
||||
expect(count).to(equal(9))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -600,6 +600,17 @@ class RepositorySpec: QuickSpec {
|
||||
expect(repo.HEAD().value?.longName).to(equal("HEAD"))
|
||||
}
|
||||
}
|
||||
|
||||
fdescribe("Repository.allCommits(in:)") {
|
||||
it("should return all (9) commits") {
|
||||
let repo = Fixtures.simpleRepository
|
||||
let branches = repo.localBranches().value!
|
||||
let commits = branches.map { repo.allCommits(in: $0).value!.map { $0 } }
|
||||
let count = commits.reduce(0) { $0 + $1.count }
|
||||
let expected = 9
|
||||
expect(count).to(equal(expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func temporaryURL(forPurpose purpose: String) -> URL {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user