From 89d67328f3682c49db296831538c8638fcfe53fe Mon Sep 17 00:00:00 2001 From: Dylan Griffin Date: Sat, 21 Mar 2015 18:37:00 -0400 Subject: Add support for libgit2's git_reset. Adds a new method to *Repository called ResetToCommit as well as constants for the three reset modes that libgit2 currently supports. This does not need to be limited to Commit, we actually just need something with a gitObject, which blobs and other Objects have, they will just require different methods. I only need to be able to reset to commits, so that's all I'm implementing right now. Also adds a test which updates the test repository README twice and then resets to the first commit. --- reset.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 reset.go (limited to 'reset.go') diff --git a/reset.go b/reset.go new file mode 100644 index 0000000..b5b7435 --- /dev/null +++ b/reset.go @@ -0,0 +1,26 @@ +package git + +/* +#include +*/ +import "C" +import "runtime" + +type ResetType int + +const ( + ResetSoft ResetType = C.GIT_RESET_SOFT + ResetMixed ResetType = C.GIT_RESET_MIXED + ResetHard ResetType = C.GIT_RESET_HARD +) + +func (r *Repository) ResetToCommit(commit *Commit, resetType ResetType, opts *CheckoutOpts) error { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + ret := C.git_reset(r.ptr, commit.gitObject.ptr, C.git_reset_t(resetType), opts.toC()) + + if ret < 0 { + return MakeGitError(ret) + } + return nil +} -- cgit v1.2.3