From f86f8920d62f312e91fe7c8152725b4e73c77265 Mon Sep 17 00:00:00 2001 From: Andrew Gallagher Date: Thu, 26 Sep 2024 14:08:29 -0700 Subject: [PATCH] Format branch/tag refspecs for git-fetch as `:` 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. --- src/source/git_source.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/source/git_source.rs b/src/source/git_source.rs index acd442827..d80d4523b 100644 --- a/src/source/git_source.rs +++ b/src/source/git_source.rs @@ -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, }; @@ -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 {}", @@ -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)?; @@ -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)?; @@ -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() {