diff options
author | Dan Davison <dandavison7@gmail.com> | 2021-08-20 12:39:19 -0700 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2021-08-20 19:58:07 -0700 |
commit | 98485fcfec8edff271dd5df5413f6809cc003825 (patch) | |
tree | 35c79f9f5313dbaae2b681b563804d2df2dc3e42 /src | |
parent | 2c0b35f89cc00073ee0cca1aa8e4d629bb3be1e7 (diff) |
Support `insteadOf` replacements in git remote URLs
Use libgit2 to query remote URL instead of querying remote.origin.url
directly. This has the consequence that `insteadOf` replacements are
honored.
See https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf
Fixes #693
Diffstat (limited to 'src')
-rw-r--r-- | src/options/set.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/options/set.rs b/src/options/set.rs index 4fc0a1fd..c80be822 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -574,8 +574,13 @@ fn set_git_config_entries(opt: &mut cli::Opt, git_config: &mut GitConfig) { // Strings for key in &["remote.origin.url"] { - if let Some(string) = git_config.get::<String>(key) { - if let Ok(repo) = GitRemoteRepo::from_str(&string) { + // We use libgit2 Repository::find_remote() instead of using the value + // of remote.origin.url directly, in order that "insteadOf" replacements + // are honored. + // See https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf + // and #693 + if let Some(url) = get_remote_url(git_config) { + if let Ok(repo) = GitRemoteRepo::from_str(&url) { opt.git_config_entries .insert(key.to_string(), GitConfigEntry::GitRemote(repo)); } @@ -592,6 +597,18 @@ fn set_git_config_entries(opt: &mut cli::Opt, git_config: &mut GitConfig) { } } +fn get_remote_url(git_config: &GitConfig) -> Option<String> { + Some( + git_config + .repo + .as_ref()? + .find_remote("origin") + .ok()? + .url()? + .to_owned(), + ) +} + #[cfg(test)] pub mod tests { use std::fs::remove_file; |