Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the equivalent of git checkout some_branch #7

Closed
thaljef opened this issue Jan 23, 2013 · 2 comments
Closed

What is the equivalent of git checkout some_branch #7

thaljef opened this issue Jan 23, 2013 · 2 comments

Comments

@thaljef
Copy link
Contributor

thaljef commented Jan 23, 2013

I'm loving Git::Raw. But so far, it isn't clear to me how to do the moral equivalent of git checkout some_branch. None of the various checkout strategies seem to "do the right thing". In particular, they don't seem to remove files from the work dir that are not in the new tree.

I think part of the problem may be that HEAD needs to be changed to point to the new tree before starting the checkout. So perhaps a binding to git_repository_set_head() is also needed.

Or am I just looking at this in the wrong way entirely?

@ghedo ghedo closed this as completed in 1ff3824 Jan 23, 2013
@ghedo
Copy link
Collaborator

ghedo commented Jan 23, 2013

You are right. I just implement the equivalent of git_repository_set_head(), and this is what you should do to simulate git checkout some_branch now:

my $branch = Git::Raw::Branch -> lookup($repo, 'some_branch', 1);
$repo -> checkout($branch -> target, { 'checkout_strategy' => { 'safe' => 1 } });
$repo -> head($branch);

(I just tried and it seems to work)

Note that I also took the opportunity to sync the checkout strategies in Git::Raw with the new ones in libgit2, so "update_unmodified", "update_missing", "update_modified" and "update_untracked" were removed (but you can now use the "safe" strategy, which is what git checkout does).

Also note that, as of now, the checkout implementation in Git::Raw is quite incomplete (e.g. there's no support for resolving conflicts), so only simple use cases are currently possible.

@thaljef
Copy link
Contributor Author

thaljef commented Jan 23, 2013

That seems to have done the trick. Ship it!

By the way, yours is the first XS code I've actually been able to understand. Well done! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants