librelist archives

« back to archive

Checking out a branch...

Checking out a branch...

From:
Dan Petitt
Date:
2013-03-31 @ 20:16
I am having difficulty finding out what I need to do to checkout a branch;
I have found references that it can be done, but I am unsure what APIs i 
need to use to do the actual operation.

Looking at the tests, I believe I can get an OID to the branch name using 
something like:
	int giterror = git_reference_name_to_id( &oid, open_repo, 
"refs/heads/mynewbranch" ) );

But dont know how i get an index from that oid and then check it out.

Or should I do something like:
	int giterror = git_index_get_bypath( &index, "refs/heads/mynewbranch", 0 ) );

and then:
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
opts.checkout_strategy = GIT_CHECKOUT_SAFE; 
giterror = git_checkout_index( m_open_repo, index, &opts );

Can someone point me to the right APIs or some examples?

Thanks
Dan

Re: [libgit2] Checking out a branch...

From:
Emeric Fermas
Date:
2013-03-31 @ 20:22
Hello Dan,

Have you peeked at the libgit2\tests-clar\checkout\tree.c test suite?
It should get you started.

Cheers,
Em.


On Sun, Mar 31, 2013 at 10:16 PM, Dan Petitt <coderangerdan@me.com> wrote:

> I am having difficulty finding out what I need to do to checkout a branch;
> I have found references that it can be done, but I am unsure what APIs i
> need to use to do the actual operation.
>
> Looking at the tests, I believe I can get an OID to the branch name using
> something like:
> int giterror = git_reference_name_to_id( &oid, open_repo,
> "refs/heads/mynewbranch" ) );
>
> But dont know how i get an index from that oid and then check it out.
>
> Or should I do something like:
> int giterror = git_index_get_bypath( &index, "refs/heads/mynewbranch", 0 )
> );
>
> and then:
> git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
> opts.checkout_strategy = GI T_CHECKOUT_SAFE;
> giterror = git_checkout_index( m_open_repo, index, &opts );
>
> Can someone point me to the right APIs or some examples?
>
> Thanks
> Dan
>

Re: [libgit2] Checking out a branch...

From:
Dan Petitt
Date:
2013-03-31 @ 20:34
Have you peeked at the libgit2\tests-clar\checkout\tree.c test suite? 
It should get you started.
 
Thanks, I looked at head.c and index.c which didnt really help; didnt look
at tree.c as I presumed that if the others didnt help then  that file 
wouldnt either; doh! Silly me there was an exact example.

Cheers, I am sure I will be back ... I need to write a Git plugin for my 
source editor so this is all new to me!
Dan

Re: [libgit2] Checking out a branch...

From:
Emeric Fermas
Date:
2013-03-31 @ 20:49
>Cheers, I am sure I will be back ...

BTW, the mlist is a bit deprecated (see
https://github.com/libgit2/libgit2/commit/a8182d495d3cf9f29b3339db7d6320a680a84690
).

I'd recommend you to rather use StackOverflow (
http://stackoverflow.com/questions/tagged/libgit2) for development/usage
related questions or open issues in the libgit2 tracker (
https://github.com/libgit2/libgit2/issues)

Cheers,
Em.


On Sun, Mar 31, 2013 at 10:34 PM, Dan Petitt <coderangerdan@me.com> wrote:

> Have you peeked at the libgit2\tests-clar\checkout\tree.c test suite?
> It should get you started.
>
>
> Thanks, I looked at head.c and index.c which didnt really help; didnt look
> at tree.c as I presumed that if the others didnt help then  that file
> wouldnt either; doh! Silly me there was an exact example.
>
> Cheers, I am sure I will be back ... I need to write a Git plugin for my
> source editor so this is all new to me!
> Dan
>