Get latest commit hash from remote URL #930
-
Is it possible to get the latest commit hash from a remote URL with For example, here's how this would be done using let url = format!("https://github.com/{}/{}.git", GITHUB_USER, GITHUB_REPO_NAME);
let mut repo = git2::Remote::create_detached(url).expect("Cannot create remote repo instance");
repo.connect(git2::Direction::Fetch).expect("Cannot connect to remote repo");
let remote_heads = repo.list().expect("Cannot get remote head list from remote repo");
let commit_map: HashMap<String, String> = remote_heads
.iter()
.map(|rh| (rh.name().to_string(), rh.oid().to_string()))
.collect();
repo.disconnect().expect("Cannot disconnect to remote repo");
// get /refs/heads/{branch} or HEAD from commit_map So this can easily be done using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
It is, and what you are looking for seems to be what's implemented in |
Beta Was this translation helpful? Give feedback.
The real answer is that even though one can query remote references, one can't do so without a 'real'
Repository
instance.Thanks so much for pointing this out! Clearly that's a hole in the API as currently there is no way to get a Remote without a
Repository
, nor is it possible to get an in-memory repository. Right now the only workaround would be to have a physical repo on disk, but that's probably not really a workaround anyway.It seems that the only reasonable thing to do with a Remote without Repository is to list remote references, and that could be put into its own utility function. After all,
gitoxide
's plumbing crates are made to operate with only the bare minimum of informatio…