Closed eliocamp closed 5 days ago
Yes indeed, and this is a point that was raised by the r-opensci reviewers as well. However, the Nix Manual advises to specify the branch each time: https://nix.dev/manual/nix/2.22/language/builtins.html#builtins-fetchgit
It is tedious, but I can understand their POV on this.
Weird. The sha uniquely identifies the commit, so I don't understand why the need to specify the branch. Well, I guess I'll need to do some digging to get the branch of a particular commit.
EDIT: After a bit of digging, it seems that the question of which branch a particular commit belongs to, technically doesn't make sense in git, although you can hack ways to get some answer.
Ok, here's a very ugly and slow way of getting the branch name adapted from here.
get_branch_name <- function(repo, sha) {
dir <- tempfile()
dir.create(dir)
old <- setwd(dir)
on.exit(setwd(old))
gitr::git("clone", repo, ".")
branch <- gitr::git("name-rev --refs=\"refs/heads/*\" --name-only", sha)$stdout
strsplit(branch, "~")[[1]][1]
}
It is absolutely disgusting, but it works.
thanks, but I think we'll stick to the recommended Nix way, at least for now
Indeed. I was thinking that automatically getting the branch name might be needed to complete a migration helper from renv to nix (#5 ).
Indeed. I was thinking that automatically getting the branch name might be needed to complete a migration helper from renv to nix (#5 ).
we might indeed need to come back to this idea at that point
I noticed that you need to specify the name of the branch and the sha in the
git_pkgs
argument. I think it should be possible to identify the commit without the name of the branch and only with the commit sha. For example, https://github.com/eliocamp/metR/archive/1dd5d391d5da6a80fde03301671aea5582643914.zip will get you the contents of a particular commit without needing to know the branch name.I'm coming up to this because I'm trying to recreate an environment recorded in renv, which doesn't record the branch name.