examples: checkout: implement guess heuristic for remote branches#5283
Conversation
33aae29 to
a9b5270
Compare
tiennou
left a comment
There was a problem hiding this comment.
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 😉.
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?) |
|
I think I'd stash this kind of function under
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 ? |
|
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 Anyway, can we merge this? Any future additions to the API can lift code out of the examples as required. |
|
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. |
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_checkoutthat enables the guessing heuristic.Fixes #5277, I guess?