(
repository_url: &Url,
commit_id: &str,
file_path: &Path,
into_dir: P,
get_credentials: &impl Fn(&str) -> Vec<(CredentialType, Cred)>,
)
| 123 | } |
| 124 | |
| 125 | pub fn fetch_file_at_commit<P>( |
| 126 | repository_url: &Url, |
| 127 | commit_id: &str, |
| 128 | file_path: &Path, |
| 129 | into_dir: P, |
| 130 | get_credentials: &impl Fn(&str) -> Vec<(CredentialType, Cred)>, |
| 131 | ) -> Result<Vec<u8>, BuildError> |
| 132 | where |
| 133 | P: AsRef<Path>, |
| 134 | { |
| 135 | let repo = fetch(repository_url, into_dir, get_credentials, commit_id).map_err(|error| BuildError::GitError { |
| 136 | application: "".to_string(), |
| 137 | git_cmd: GitCmd::Fetch, |
| 138 | context: format!("url: {repository_url}/ commit id: {commit_id}"), |
| 139 | raw_error: error, |
| 140 | })?; |
| 141 | |
| 142 | file_content_at_commit(&repo, commit_id, file_path).map_err(|error| BuildError::GitError { |
| 143 | application: "".to_string(), |
| 144 | git_cmd: GitCmd::Checkout, |
| 145 | context: format!("commit id: {commit_id}, file path: {}", file_path.display()), |
| 146 | raw_error: error, |
| 147 | }) |
| 148 | } |
| 149 | |
| 150 | // Credentials callback is called endlessly until the server return Auth Ok (or a definitive error) |
| 151 | // If auth is denied, it up to us to return a new credential to try different auth method |
no test coverage detected