首页 > 解决方案 > Objective-Git 的拉/推问题

问题描述

我正在尝试使用 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
    }
}

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

有什么想法可以解决这个问题吗?我找不到任何做这种事情的例子,所以也许我的代码完全错误。

标签: iosswiftgitframeworks

解决方案


推荐阅读