Implementing 'git pull' with libgit2?

2019-04-27 16:52发布

I have a relatively short Gist which is supposed to use libgit2 to emulate the functionality of the git pull command. Unfortunately, it's not quite working.

In summary, the snippet:

According to git_remote_stats(), objects are indeed being fetched. But the working directory doesn't change to reflect the latest commit. I tried adding:

git_checkout_head(repo, NULL);

...but that made no difference.

Entering:

git checkout master

...in a terminal results in the following output:

Already on 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.

How do I fast-forward?

标签: c git libgit2
1条回答
我命由我不由天
2楼-- · 2019-04-27 17:34

You should run git pull origin master

or

git fetch origin + git merge origin/master

Then means you need the equivalent libgit2 merge function.

merge function is available in libgit2 v0.20

查看更多
登录 后发表回答