Skip to content

Commit

Permalink
Format branch/tag refspecs for git-fetch as <src>:<dst>
Browse files Browse the repository at this point in the history
This fixes a bug where new branches, added after `src_cache` was
originally cloned, wouldn't be abled to be successfully checkout out.
Fix by using a refspec which creates and destination branch/tag.
  • Loading branch information
andrewjcg committed Sep 27, 2024
1 parent efe4acd commit f86f892
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/source/git_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{

use crate::system_tools::{SystemTools, Tool};
use crate::{
recipe::parser::{GitSource, GitUrl},
recipe::parser::{GitRev, GitSource, GitUrl},
system_tools::ToolError,
};

Expand All @@ -19,7 +19,7 @@ pub fn fetch_repo(
system_tools: &SystemTools,
repo_path: &Path,
url: &str,
rev: &str,
rev: &GitRev,
) -> Result<(), SourceError> {
tracing::info!(
"Fetching repository from {} at {} into {}",
Expand All @@ -33,8 +33,13 @@ pub fn fetch_repo(
}

let mut command = git_command(system_tools, "fetch")?;
let refspec = match rev {
GitRev::Branch(_) => format!("{0}:{0}", rev),
GitRev::Tag(_) => format!("{0}:{0}", rev),
_ => format!("{}", rev),
};
let output = command
.args([url, rev])
.args(["-f", url, refspec.as_str()])
.current_dir(repo_path)
.output()
.map_err(|_err| SourceError::ValidationFailed)?;
Expand Down Expand Up @@ -66,7 +71,7 @@ pub fn fetch_repo(
}

let output = git_command(system_tools, "checkout")?
.args([rev])
.arg(rev.to_string())
.current_dir(repo_path)
.output()
.map_err(|_err| SourceError::ValidationFailed)?;
Expand Down Expand Up @@ -187,7 +192,7 @@ pub fn git_src(
}

assert!(cache_path.exists());
fetch_repo(system_tools, &cache_path, &url.to_string(), &rev)?;
fetch_repo(system_tools, &cache_path, &url.to_string(), source.rev())?;
}
GitUrl::Path(path) => {
if cache_path.exists() {
Expand Down

0 comments on commit f86f892

Please sign in to comment.