Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify git packages without branch name #207

Closed
eliocamp opened this issue Jun 24, 2024 · 6 comments
Closed

Specify git packages without branch name #207

eliocamp opened this issue Jun 24, 2024 · 6 comments

Comments

@eliocamp
Copy link
Contributor

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.

@b-rodrigues
Copy link
Contributor

b-rodrigues commented Jun 24, 2024

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.

@eliocamp
Copy link
Contributor Author

eliocamp commented Jun 24, 2024

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.

@eliocamp
Copy link
Contributor Author

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.

@b-rodrigues
Copy link
Contributor

thanks, but I think we'll stick to the recommended Nix way, at least for now

@eliocamp
Copy link
Contributor Author

Indeed. I was thinking that automatically getting the branch name might be needed to complete a migration helper from renv to nix (#5 ).

@b-rodrigues
Copy link
Contributor

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

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

No branches or pull requests

2 participants