1
1
mirror of https://github.com/orhun/git-cliff.git synced 2024-11-25 13:22:17 +03:00

fix(remote): avoid setting multiple remotes (#885)

This commit is contained in:
Orhun Parmaksız 2024-09-25 10:35:06 +03:00 committed by GitHub
parent a5786bea61
commit a344c68238
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 42 deletions

View File

@ -146,6 +146,29 @@ pub struct RemoteConfig {
pub bitbucket: Remote,
}
impl RemoteConfig {
/// Returns `true` if any remote is set.
pub fn is_any_set(&self) -> bool {
#[cfg(feature = "github")]
if self.github.is_set() {
return true;
}
#[cfg(feature = "gitlab")]
if self.gitlab.is_set() {
return true;
}
#[cfg(feature = "gitea")]
if self.gitea.is_set() {
return true;
}
#[cfg(feature = "bitbucket")]
if self.bitbucket.is_set() {
return true;
}
false
}
}
/// A single remote.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct Remote {

View File

@ -123,52 +123,33 @@ fn process_repository<'a>(
count && !ignore
});
if !config.remote.github.is_set() {
if !config.remote.is_any_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No GitHub remote is set, using remote: {}", remote);
config.remote.github.owner = remote.owner;
config.remote.github.repo = remote.repo;
config.remote.github.is_custom = remote.is_custom;
if !config.remote.github.is_set() {
debug!("No GitHub remote is set, using remote: {}", remote);
config.remote.github.owner = remote.owner;
config.remote.github.repo = remote.repo;
config.remote.github.is_custom = remote.is_custom;
} else if !config.remote.gitlab.is_set() {
debug!("No GitLab remote is set, using remote: {}", remote);
config.remote.gitlab.owner = remote.owner;
config.remote.gitlab.repo = remote.repo;
config.remote.gitlab.is_custom = remote.is_custom;
} else if !config.remote.gitea.is_set() {
debug!("No Gitea remote is set, using remote: {}", remote);
config.remote.gitea.owner = remote.owner;
config.remote.gitea.repo = remote.repo;
config.remote.gitea.is_custom = remote.is_custom;
} else if !config.remote.bitbucket.is_set() {
debug!("No Bitbucket remote is set, using remote: {}", remote);
config.remote.bitbucket.owner = remote.owner;
config.remote.bitbucket.repo = remote.repo;
config.remote.bitbucket.is_custom = remote.is_custom;
}
}
Err(e) => {
debug!("Failed to get remote from GitHub repository: {:?}", e);
}
}
} else if !config.remote.gitlab.is_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No GitLab remote is set, using remote: {}", remote);
config.remote.gitlab.owner = remote.owner;
config.remote.gitlab.repo = remote.repo;
config.remote.gitlab.is_custom = remote.is_custom;
}
Err(e) => {
debug!("Failed to get remote from GitLab repository: {:?}", e);
}
}
} else if !config.remote.gitea.is_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No Gitea remote is set, using remote: {}", remote);
config.remote.gitea.owner = remote.owner;
config.remote.gitea.repo = remote.repo;
config.remote.gitea.is_custom = remote.is_custom;
}
Err(e) => {
debug!("Failed to get remote from Gitea repository: {:?}", e);
}
}
} else if !config.remote.bitbucket.is_set() {
match repository.upstream_remote() {
Ok(remote) => {
debug!("No Bitbucket remote is set, using remote: {}", remote);
config.remote.bitbucket.owner = remote.owner;
config.remote.bitbucket.repo = remote.repo;
config.remote.bitbucket.is_custom = remote.is_custom;
}
Err(e) => {
debug!("Failed to get remote from Bitbucket repository: {:?}", e);
debug!("Failed to get remote from repository: {:?}", e);
}
}
}