mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-27 00:14:52 +03:00
cred: check pushurl before checking url (#967)
* cred: check pushurl before checking url if a remote has both a pushurl and a url, need_username_password should check the pushurl before checking the url since we might not need credentials for the former
This commit is contained in:
parent
9eb30ecb4c
commit
5550415e3c
@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
- Keep commit message when pre-commit hook fails ([#1035](https://github.com/extrawurst/gitui/issues/1035))
|
||||
- honor `pushurl` when checking whether we need username and password for pushing ([#953](https://github.com/extrawurst/gitui/issues/953))
|
||||
|
||||
## [0.19] - 2021-12-08 - Bare Repo Support
|
||||
|
||||
|
@ -32,9 +32,11 @@ impl BasicAuthCredential {
|
||||
/// know if username and password are needed for this url
|
||||
pub fn need_username_password(repo_path: &RepoPath) -> Result<bool> {
|
||||
let repo = repo(repo_path)?;
|
||||
let url = repo
|
||||
.find_remote(&get_default_remote_in_repo(&repo)?)?
|
||||
.url()
|
||||
let remote =
|
||||
repo.find_remote(&get_default_remote_in_repo(&repo)?)?;
|
||||
let url = remote
|
||||
.pushurl()
|
||||
.or_else(|| remote.url())
|
||||
.ok_or(Error::UnknownRemote)?
|
||||
.to_owned();
|
||||
let is_http = url.starts_with("http");
|
||||
@ -188,6 +190,25 @@ mod tests {
|
||||
assert_eq!(need_username_password(repo_path).unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn test_dont_need_username_password_if_pushurl_ssh() {
|
||||
let (_td, repo) = repo_init().unwrap();
|
||||
let root = repo.path().parent().unwrap();
|
||||
let repo_path: &RepoPath =
|
||||
&root.as_os_str().to_str().unwrap().into();
|
||||
|
||||
repo.remote(DEFAULT_REMOTE_NAME, "http://user@github.com")
|
||||
.unwrap();
|
||||
repo.remote_set_pushurl(
|
||||
DEFAULT_REMOTE_NAME,
|
||||
Some("git@github.com:user/repo"),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(need_username_password(repo_path).unwrap(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
#[should_panic]
|
||||
|
Loading…
Reference in New Issue
Block a user