mirror of
https://github.com/gosticks/SwiftGit2.git
synced 2025-10-16 11:55:34 +00:00
validate success of git_status_list_new
This commit is contained in:
parent
253cf53d2e
commit
edb1906231
@ -671,7 +671,7 @@ final public class Repository {
|
||||
|
||||
// MARK: - Status
|
||||
|
||||
public func getRepositoryStatus() -> [StatusEntry] {
|
||||
public func getRepositoryStatus() -> Result<[StatusEntry], NSError> {
|
||||
|
||||
var returnArray = [StatusEntry]()
|
||||
|
||||
@ -681,13 +681,16 @@ final public class Repository {
|
||||
var options = pointer.move()
|
||||
pointer.deallocate(capacity: 1)
|
||||
|
||||
var status: OpaquePointer? = nil
|
||||
git_status_list_new(&status, self.pointer, &options)
|
||||
var unsafeStatus: OpaquePointer? = nil
|
||||
let statusResult = git_status_list_new(&unsafeStatus, self.pointer, &options)
|
||||
guard statusResult == GIT_OK.rawValue, let unwrapStatusResult = unsafeStatus else {
|
||||
return Result.failure(NSError(gitError: statusResult, pointOfFailure: "git_status_list_new"))
|
||||
}
|
||||
|
||||
let count = git_status_list_entrycount(status)
|
||||
let count = git_status_list_entrycount(unwrapStatusResult)
|
||||
|
||||
for i in 0..<count {
|
||||
let s = git_status_byindex(status, i)
|
||||
let s = git_status_byindex(unwrapStatusResult, i)
|
||||
if s?.pointee.status.rawValue == GIT_STATUS_CURRENT.rawValue {
|
||||
continue
|
||||
}
|
||||
@ -721,9 +724,9 @@ final public class Repository {
|
||||
}
|
||||
|
||||
headToIndex = DiffDelta(status: htoiStatus,
|
||||
flags: s?.pointee.head_to_index.pointee.flags,
|
||||
oldFile: htoiOldFile,
|
||||
newFile: htoiNewFile)
|
||||
flags: s?.pointee.head_to_index.pointee.flags,
|
||||
oldFile: htoiOldFile,
|
||||
newFile: htoiNewFile)
|
||||
}
|
||||
|
||||
// Index to Working Directory status and files
|
||||
@ -739,16 +742,16 @@ final public class Repository {
|
||||
}
|
||||
|
||||
indexToWorkDir = DiffDelta(status: itowStatus,
|
||||
flags: s?.pointee.index_to_workdir.pointee.flags,
|
||||
oldFile: itowOldFile,
|
||||
newFile: itowNewFile)
|
||||
flags: s?.pointee.index_to_workdir.pointee.flags,
|
||||
oldFile: itowOldFile,
|
||||
newFile: itowNewFile)
|
||||
}
|
||||
|
||||
let statusEntry = StatusEntry(status: status, headToIndex: headToIndex, indexToWorkDir: indexToWorkDir)
|
||||
returnArray.append(statusEntry)
|
||||
}
|
||||
|
||||
return returnArray
|
||||
return Result.success(returnArray)
|
||||
}
|
||||
|
||||
private func convertStatus(_ statusValue: UInt32) -> Status {
|
||||
|
||||
@ -651,7 +651,7 @@ class RepositorySpec: QuickSpec {
|
||||
|
||||
let status = repo.getRepositoryStatus()
|
||||
|
||||
expect(status.count).to(equal(0))
|
||||
expect(status.value?.count).to(equal(0))
|
||||
|
||||
let repoWithStatus = Fixtures.sharedInstance.repository(named: "repository-with-status")
|
||||
let branchWithStatus = repoWithStatus.localBranch(named: "master").value!
|
||||
@ -659,7 +659,7 @@ class RepositorySpec: QuickSpec {
|
||||
|
||||
let statusWithStatus = repoWithStatus.getRepositoryStatus()
|
||||
|
||||
expect(statusWithStatus.count).to(equal(5))
|
||||
expect(statusWithStatus.value?.count).to(equal(5))
|
||||
}
|
||||
|
||||
it("Should have accurate delta information") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user