Reuse native macOS Git credentials
Some checks failed
Dependency security audit / rustsec (push) Has been cancelled
Some checks failed
Dependency security audit / rustsec (push) Has been cancelled
This commit is contained in:
@@ -1587,7 +1587,7 @@ struct RawGit {
|
||||
remotes: Vec<RawGitRemote>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Clone, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct RawGitRemote {
|
||||
name: String,
|
||||
@@ -1700,7 +1700,7 @@ fn validate_config(
|
||||
};
|
||||
let configured_git_remotes = raw.git.remotes;
|
||||
#[cfg(not(any(target_os = "ios", target_os = "watchos")))]
|
||||
let git_remotes = match repository_git_remotes(&vault)? {
|
||||
let git_remotes = match repository_git_remotes(&vault, &configured_git_remotes, base)? {
|
||||
Some(remotes) => remotes,
|
||||
None => validate_remotes(configured_git_remotes, Some(base))?,
|
||||
};
|
||||
@@ -1727,7 +1727,11 @@ fn validate_config(
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "ios", target_os = "watchos")))]
|
||||
fn repository_git_remotes(vault: &Path) -> Result<Option<Vec<GitRemote>>, ConfigError> {
|
||||
fn repository_git_remotes(
|
||||
vault: &Path,
|
||||
configured_remotes: &[RawGitRemote],
|
||||
config_base: &Path,
|
||||
) -> Result<Option<Vec<GitRemote>>, ConfigError> {
|
||||
let path = vault.join(".git/config");
|
||||
if !path.is_file() {
|
||||
return Ok(None);
|
||||
@@ -1760,21 +1764,45 @@ fn repository_git_remotes(vault: &Path) -> Result<Option<Vec<GitRemote>>, Config
|
||||
name: name.to_owned(),
|
||||
})?;
|
||||
let remote = match endpoint {
|
||||
RemoteEndpoint::Https(ref endpoint) => GitRemote::https(
|
||||
name,
|
||||
&url,
|
||||
stable_identifier(
|
||||
"server",
|
||||
format!(
|
||||
"{}://{}:{}",
|
||||
endpoint.scheme(),
|
||||
endpoint.host_str().unwrap_or_default(),
|
||||
endpoint.port_or_known_default().unwrap_or(443)
|
||||
)
|
||||
.as_bytes(),
|
||||
),
|
||||
stable_identifier("repository", url.as_bytes()),
|
||||
)?,
|
||||
RemoteEndpoint::Https(ref https_endpoint) => {
|
||||
let credential_ids = configured_remotes
|
||||
.iter()
|
||||
.find(|configured| {
|
||||
RemoteEndpoint::parse(&configured.url)
|
||||
.is_ok_and(|configured| configured == endpoint)
|
||||
})
|
||||
.map(|configured| {
|
||||
let mut validated =
|
||||
validate_remotes(vec![configured.clone()], Some(config_base))?;
|
||||
let configured = validated.remove(0);
|
||||
let (server, application) = configured.https_credentials().ok_or(
|
||||
ConfigError::InvalidField {
|
||||
field: "git.remotes.https_credentials",
|
||||
},
|
||||
)?;
|
||||
Ok::<_, ConfigError>((
|
||||
server.as_str().to_owned(),
|
||||
application.as_str().to_owned(),
|
||||
))
|
||||
})
|
||||
.transpose()?
|
||||
.unwrap_or_else(|| {
|
||||
(
|
||||
stable_identifier(
|
||||
"server",
|
||||
format!(
|
||||
"{}://{}:{}",
|
||||
https_endpoint.scheme(),
|
||||
https_endpoint.host_str().unwrap_or_default(),
|
||||
https_endpoint.port_or_known_default().unwrap_or(443)
|
||||
)
|
||||
.as_bytes(),
|
||||
),
|
||||
stable_identifier("repository", https_endpoint.as_str().as_bytes()),
|
||||
)
|
||||
});
|
||||
GitRemote::https(name, &url, credential_ids.0, credential_ids.1)?
|
||||
}
|
||||
RemoteEndpoint::Ssh(_) => GitRemote::ssh(name, &url)?,
|
||||
};
|
||||
remotes.push(remote);
|
||||
|
||||
Reference in New Issue
Block a user