Objective-Git的拉/推问题

时间:2019-01-26 06:52:17

标签: ios swift git frameworks

我正在尝试使用iOS应用程序推送和推送存储库。我正在使用Objective-Git和Swift。

我做了一个简单的拉和推类:

class Push: NSObject {
    func push(_ url: URL?, options: NSDictionary?, progress: ((UInt32, UInt32, Int, UnsafeMutablePointer<ObjCBool>) -> Void)?) -> Bool {
        let repo = try? GTRepository(url: url!)
        let branches = try! repo?.branches()
        let remotes = try! repo?.remoteNames()
        let remote = try? GTRemote(name: (remotes?[0])!, in: repo!)
        do {
            try repo?.pushBranches(branches!, to: remote!, withOptions: options as? [AnyHashable : Any], progress: progress)
        } catch {
            print("Couldn't push")
        }
        return true
    }

    func pull(_ url: URL?, options: NSDictionary?, progress: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> ()) -> Bool {
        let repo = try? GTRepository(url: url!)
        let branches = try! repo?.branches()
        let remotes = try? repo?.remoteNames()
        let remote = try? GTRemote(name: remotes!![0], in: repo!)
        do {
            try repo?.pull(branches![0], from: remote!, withOptions: options as? [AnyHashable : Any], progress: progress)
        } catch {
            print("Couldn't pull")
        }

        return true
    }
    func creds(creds: GTCredential?) -> NSDictionary? {
        let gtcp = GTCredentialProvider { (type, a, b) -> GTCredential? in
            return creds
        }
        let d: NSDictionary = [
            "GTRepositoryRemoteOptionsCredentialProvider": gtcp
        ]
        return d
    }
}

不幸的是,当我尝试使用正确的凭据拉/推存储库时,它不起作用

有任何解决方法吗?我找不到执行此操作的任何示例,所以也许我的代码是完全错误的。

0 个答案:

没有答案