Conversation
| {"R_git_worktree_lock", (DL_FUNC) &R_git_worktree_lock, 2}, | ||
| {"R_git_worktree_unlock", (DL_FUNC) &R_git_worktree_unlock, 2}, | ||
| {"R_git_worktree_add", (DL_FUNC) &R_git_worktree_add, 6}, | ||
| {"R_git_worktree_is_prunable",(DL_FUNC) &R_git_worktree_is_prunable,4}, |
There was a problem hiding this comment.
&R_git_worktree_is_prunable,4}, could probably use a space before the 4, but I didn't want to have to realign everything to do so. I'll let you do this if you want to.
| // Throws away reason for why it is not valid. Could add | ||
| // `git_worktree_check_valid()` to propagate the reason up. | ||
| SEXP R_git_worktree_is_valid(SEXP ptr, SEXP name) { |
There was a problem hiding this comment.
A few functions like R_git_worktree_is_valid() currently throw away a bit of info to be more R-like.
For example, the git function git_worktree_validate() returns 0 or an error code. We just return TRUE or FALSE so we lose the error information here.
An R level git_worktree_check_valid() would retain that error info as part of an error message, but I don't think it is worth it right now.
|
Sorry about breaking up the CI :| Now fixed in the main branch and merged here. |
|
Debian 11 fails but not 10 or 12? Fun 😬 |
|
We can ignore it, not many people use Debian 10/11 anymore. Let's skip the test for old versions of libgit2; as long as it at least can be built on Debian 11 it is fine, for some old servers that pull this package in as a dependency. skip_if_not(libgit2_config()$version > "1.1.0") |
|
I think all other R functions have Would it make sense to change the order of parameters in |
|
Done! |
|
Thanks! |
|
This has landed on CRAN now so you can depend on it (but feel free to do further tweaking). |
|
thanks! |
|
FWI cran ASAN found a bug in the |
|
Darn sorry about that, would you be able to fix it for me? 😞 |
|
Yes I don't think it will lead to crashes, it's just a warning about declaration mismatch. So not urgent. |
@jeroen can we fix the failing tests on main first? I think if you run CI on
mainright now, it will fail?Closes #251
Being used in DavisVaughan/cross#9
libgit2 C API for worktrees:
https://libgit2.org/docs/reference/main/worktree/index.html
Also exposed on the R side are:
git_worktree_exists(), which returnsTRUEorFALSEbased on the result ofgit_worktree_lookup()git_worktree_remove(), agit_worktree_prune()wrapper with more aggressive defaults, mimickinggit worktree remove. More on this below.All functions use a worktree's
nameas the way to uniquely identify it and interact with it, rather than handing out some kind of S3 object for a worktree (i.e. it follows the gert model of using simple R objects).The main useful functions for working with worktrees are:
git_worktree_list()git_worktree_add()git_worktree_remove()git_worktree_add()The libgit2 version of this function is quite complicated and confusing because both libgit2 and command line git mix worktree creation and branch creation together into a single
git worktree addutility. This ends up being extremely confusing, becausegit worktree addwill sometimes create a new branch for you in addition to the worktree, butgit worktree removewill never delete that branch.I have written notes about this above the C signature of
R_git_worktree_add(). I'd encourage you to read those notes then come back here:https://github.com/r-lib/gert/pull/252/changes#diff-901344d7a8b2466c8b7d4f499b8dde3f78c2cb02eac92c193d86f5b156f39db5R116-R143
Basically, if we mimicked libgit2 exactly then our defaults would encourage writing code that creates temporary worktrees like this:
I found that extremely confusing. If you forget the
git_branch_delete()then you can'tgit_worktree_add("foo")a second time, because the"foo"branch already exists.IMO it is much cleaner if we force
branchto be provided - meaning thatgit_worktree_add()'s sole job is worktree creation. So instead I ended up with:This made wayyyyyyyy more sense to me.
git_worktree_remove()Command line git has both
git worktree pruneandgit worktree removeWhen you are "done with" a worktree, you are ideally supposed to
removeit. This removes the git metadata for it in the main working tree and throws away the whole folder that the worktree was in (thepatharg from above). That's nice!If you manually deleted the worktree folder but forgot to run
remove, then git metadata for the worktree is left lying around in the main working tree. This is automatically cleaned up by git by runninggit worktree pruneat regular intervals. Sogit_worktree_prune()is really more of a gentle "behind the scenes" way to clean up old worktrees. It isn't meant for interactively removing them.libgit2 exposed these
git worktreefeatures in a weird way. Rather than exposing bothgit_worktree_prune()andgit_worktree_remove(), the libgit2 API only hasgit_worktree_prune(), but you can set a bunch of options to make it work likegit worktree remove. I've chosen to exposegit_worktree_remove()on the R side as a wrapper aroundgit_worktree_prune()that makes it actually useful for interactive invocations.