2015-01-20 91 views
4

如何使用libgit2進行推送? (像控制檯git push origin master如何推送(使用libgit2)

我想用Ç版本。克隆,打開,添加文件索引和提交工作就像一個魅力(見code)。

test-bare-repository是本地的。

不幸的是,參考和文檔沒有幫助我。例子非常少見,大多數已經過時(like thisgit_push_new()函數似乎不見了)。

我在猜測現在幾個小時,我想我嘗試了referenceexamples的代碼片段的所有有意義的組合。

編輯:我擔心根本不可能用libgit2來做到這一點。 任何人都可以建議我參考,非常/僞造我的恐懼?

有一些源([1][2])在互聯網/郵件列表是說,這是不可能的libgit2 推動現在,但將有可能soonish。 但是,這些來源相當過時。

引用包含一些與推式相關的功能(至少按名稱)。但沒有一個似乎工作,我想:(

回答

3

,做的伎倆的代碼是這樣的:

bool push(git_repository *repository) 
{ 
    // get the remote. 
    git_remote* remote = NULL; 
    git_remote_lookup(&remote, repository, "origin"); 

    // connect to remote 
    git_remote_connect(remote, GIT_DIRECTION_PUSH) 

    // add a push refspec 
    git_remote_add_push(remote, "refs/heads/master:refs/heads/master"); 
    // configure options 
    git_push_options options; 
    git_push_init_options(&options, GIT_PUSH_OPTIONS_VERSION); 

    // do the push 
    git_remote_upload(remote, NULL, &options); 
    return true; 
} 

當然,你應該做一些錯誤檢查,我省略了簡潔