Skip to content

Commit

Permalink
feat: Add support for fetching specific refspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 9, 2024
1 parent ffe90f9 commit 57d04f8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/engines/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl GitEngine {

let original_head = repository.head_id().ok();

let default_refspecs = vec!["+refs/heads/*:refs/remotes/origin/*".to_string()];

trace!(
"Configuring fetch operation for repository {}",
target.display()
Expand All @@ -150,7 +152,12 @@ impl GitEngine {
)
})?
.with_fetch_tags(Tags::All)
.with_refspecs(["+refs/heads/*:refs/remotes/origin/*"], gix::remote::Direction::Fetch)
.with_refspecs(
repo.refspecs.as_ref().unwrap_or(&default_refspecs)
.iter()
.map(|s| gix::bstr::BString::from(s.as_str()))
.collect::<Vec<gix::bstr::BString>>(),
gix::remote::Direction::Fetch)
.map_err(|e| {
errors::user_with_internal(
&format!(
Expand Down Expand Up @@ -319,6 +326,7 @@ mod tests {
let repo = GitRepo::new(
"SierraSoftworks/grey",
"https://github.com/sierrasoftworks/grey.git",
None,
);

let state1 = agent
Expand Down
2 changes: 1 addition & 1 deletion src/entities/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ entity!(HttpFile(url: U => String) {
with_content_type => content_type: Option<String>,
});

entity!(GitRepo(clone_url: U => String) {
entity!(GitRepo(clone_url: U => String, refspecs: R => Option<Vec<String>>) {
with_credentials => credentials: Credentials,
});
10 changes: 8 additions & 2 deletions src/sources/github_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ impl BackupSource<GitRepo> for GitHubRepoSource {
async_stream::try_stream! {
if matches!(target, GitHubRepoSourceKind::Repo(_)) {
let repo = self.client.get::<GitHubRepo>(url, &policy.credentials, cancel).await?;
yield GitRepo::new(repo.full_name.as_str(), repo.clone_url.as_str())
yield GitRepo::new(
repo.full_name.as_str(),
repo.clone_url.as_str(),
policy.properties.get("refspecs").map(|r| r.split(",").map(|r| r.to_string()).collect::<Vec<String>>()))
.with_credentials(policy.credentials.clone())
.with_metadata_source(&repo);
} else {
for await repo in self.client.get_paginated::<GitHubRepo>(url, &policy.credentials, cancel) {
let repo = repo?;
yield GitRepo::new(repo.full_name.as_str(), repo.clone_url.as_str())
yield GitRepo::new(
repo.full_name.as_str(),
repo.clone_url.as_str(),
policy.properties.get("refspecs").map(|r| r.split(",").map(|r| r.to_string()).collect::<Vec<String>>()))
.with_credentials(policy.credentials.clone())
.with_metadata_source(&repo);
}
Expand Down

0 comments on commit 57d04f8

Please sign in to comment.