7

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?

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

1 Answers1

3

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

linquize
  • 19,828
  • 10
  • 59
  • 83
  • Actually, there is a WIP (work in progress) branch containing a `git_merge` function. It seems relatively mature and I'm currently looking into using it. – Nathan Osman Mar 19 '13 at 18:01
  • anything new on this? – Tim Specht Nov 25 '13 at 18:47
  • mention libgit2 v0.20 – linquize Nov 26 '13 at 01:30
  • This is +/- correct; however, you should be careful in cases where local branches (i.e. master) map onto remote branches with different names (e.g. if your local "master" branch mapped to a "devel" branch on the remote.) The complete libgit2 implementation of "pull" would also want look into the config to get the mapping of remote to local branches. – tychoish Sep 02 '15 at 11:38