Skip to content

examples: checkout: implement guess heuristic for remote branches#5283

Merged
pks-t merged 1 commit into
libgit2:masterfrom
pks-t:pks/example-checkout-remote-branch
Dec 13, 2019
Merged

examples: checkout: implement guess heuristic for remote branches#5283
pks-t merged 1 commit into
libgit2:masterfrom
pks-t:pks/example-checkout-remote-branch

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Oct 24, 2019

This pull request implements the guess heuristic used by upstream's git-checkout(1) and git-switch(1), respectively. It will automatically create local branches from existing remote branches if any ref exists that matches. Honestly, I think that this is kind of complex as part of our examples, and I feel like it might be sensible to provide e.g. a flag in git_checkout that enables the guessing heuristic.

Fixes #5277, I guess?

@pks-t pks-t force-pushed the pks/example-checkout-remote-branch branch from 33aae29 to a9b5270 Compare October 25, 2019 06:11
Copy link
Copy Markdown
Contributor

@tiennou tiennou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me as a "first approximation", and example code is always good. I do have a feeling this belongs to the API as well, but at least this can be refined and adapted once some use cases appear 😉.

@ethomson
Copy link
Copy Markdown
Member

I feel like it might be sensible to provide e.g. a flag in git_checkout that enables the guessing heuristic.

Instead of a flag on checkout, I think a new API might be useful for callers to get the annotated commit from a "refish"? (Is there a better name than that?)

@tiennou
Copy link
Copy Markdown
Contributor

tiennou commented Nov 17, 2019

I think I'd stash this kind of function under branch, eg. git_branch_create_tracking (which I have some dead code for somewhere), and then let the checkout/switch part use that ? Because AFAIU there's no need to touch the working copy to create a tracking branch (says the guy who just read about locally-tracking branches 🙄) ?

annotated commit from a "refish"

I'm tempted to say that annotated commit actually are libgit2's "refish" — at least that's how the API felt when I needed to use merges/fetches/etc. Maybe I'm missing something though ?

@pks-t
Copy link
Copy Markdown
Member Author

pks-t commented Nov 28, 2019

I'm torn between both approaches. I honestly never quite got what annotated commits are about, but I guess describing them as "refish" which remembers where the actual commit was resolved from is probably kinda close. I can't quite imagine how branch creation would look like if we were to use annotated commits for this case, so on first sight git_branch_create_tracking sounds more obvious to me. Might just be me though for not having seen the approach @ethomson has in mind.

Anyway, can we merge this? Any future additions to the API can lift code out of the examples as required.

@tiennou
Copy link
Copy Markdown
Contributor

tiennou commented Nov 28, 2019

I didn't as well, until I wrote this example, and was enlightened about "how to convert refishs" in GitX. If that helps, this one is also a likely candidate for code-lifting.

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

Successfully merging this pull request may close these issues.

add a simple example to show how to switch to an branch

3 participants