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:
git_repository_open()
to open the repository on diskgit_remote_load()
to get a git_remote *
to the remote named "origin"git_remote_connect()
with the GIT_DIRECTION_FETCH
flaggit_remote_download()
to fetch objects from the remoteAccording 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?
Libgit2 is a dependency-free implementation of Git, with a focus on having a nice API for use within other programs. You can find it at https://libgit2.org.
it modifies your working directory in unpredictable ways. pausing what you are doing to review someone else's work is annoying with git pull. it makes it hard to correctly rebase onto the remote branch. it doesn't clean up branches that were deleted in the remote repo.
To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With