美文网首页
ObjectiveGit(二)push & pull

ObjectiveGit(二)push & pull

作者: XPorter | 来源:发表于2018-04-26 20:09 被阅读24次

push

生成一个commit之后,接下来就可以推送到远端了。push之前需要获取到远端仓库信息。由于一个本地仓库可以设置多个远端仓库,这里默认就取第一个远端仓库。

GTConfiguration *conf = [_repo configurationWithError:NULL];
NSError *error = nil;
GTRemote *remote = [conf.remotes firstObject];

由于push操作是需要权限的,所以要配置用户名和密码。注意这里的key值和clone的时候不一样。

GTCredentialProvider *provider = [GTCredentialProvider providerWithBlock:^GTCredential * _Nullable(GTCredentialType type, NSString * _Nonnull URL, NSString * _Nonnull userName) {
   GTCredential *cre = [GTCredential credentialWithUserName:@"xporter" password:@"12345678" error:NULL];
   return cre;
}];

 NSDictionary *remoteOptions = @{GTRepositoryRemoteOptionsCredentialProvider:provider};

获取分支信息

GTBranch *curretntBarch = [_repo currentBranchWithError:&error];

开始向远端推送

BOOL r = [_repo pushBranch:curretntBarch toRemote:remote withOptions:pushOptions error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL * _Nonnull stop) {
    NSLog(@"%d/%d",current,total);
}];

如果没有报错的话就是推送成功了,可以到远端仓库进行验证。

pull

要同步远端的指定分支的信息,就需要用到pull方法。先获取需要更新的分支

GTBranch *brach = [_repo currentBranchWithError:NULL];

pull 也是需要权限信息的,要设置用户信息

GTCredentialProvider *provider = [GTCredentialProvider providerWithBlock:^GTCredential * _Nullable(GTCredentialType type, NSString * _Nonnull URL, NSString * _Nonnull userName) {
   GTCredential *cre = [GTCredential credentialWithUserName:@"xporter" password:@"12345678" error:NULL];
   return cre;
}];

NSDictionary *remoteOptions = @{GTRepositoryRemoteOptionsCredentialProvider:provider};

获取远端分支信息

GTConfiguration *conf = [_repo configurationWithError:NULL];
NSError *error = nil;
GTRemote *remote = [conf.remotes firstObject];

拉取远端信息

BOOL r = [_repo pullBranch:brach fromRemote:remote withOptions:pullOptions error:&error progress:^(const git_transfer_progress * _Nonnull progress, BOOL * _Nonnull stop) {

}];

相关文章

  • ObjectiveGit(二)push & pull

    push 生成一个commit之后,接下来就可以推送到远端了。push之前需要获取到远端仓库信息。由于一个本地仓库...

  • Push or Pull?

    采用Pull模型还是Push模型是很多中间件都会面临的一个问题。消息中间件、配置管理中心等都会需要考虑Client...

  • adb pull 与 adb push命令

    adb pull db pull <手机端文件> 把SD卡上拷贝到PC adb push adb push ...

  • RocketMQ源码之长轮询实现

    Push or Pull MQ中消息传递的模式有Push和Pull两种。Pull: 消费者主动从Broker拉取P...

  • coding.net使用git

    pull 本机git版本 push git push origin master 如果报错,使用git push ...

  • 常用反义词

    1. push & pull(推、拉) People PUSH their shopping cart aroun...

  • RocketMQ的push模式机制

    RocketMQ的push模式 我们都知道RocketMQ在消费端有push和pull两种模式,pull模式需要我...

  • ssh: connect to git@gitlab.xxxxx

    git pull和push时报错

  • ObjectiveGit(一)clone & commi

    ObjectiveGit 是对 libgit2 的上层封装。在项目中如果要使用 ObjectiveGit 的话需要...

  • 陀螺仪

    陀螺仪也是包含在CoreMotion框架中的 push采样 pull采样 同样的,pull和push的区别在于pu...

网友评论

      本文标题:ObjectiveGit(二)push & pull

      本文链接:https://www.haomeiwen.com/subject/kagmlftx.html