Skip to content

Commit a344c68

Browse files
authored
fix(remote): avoid setting multiple remotes (#885)
1 parent a5786be commit a344c68

File tree

2 files changed

+46
-42
lines changed

2 files changed

+46
-42
lines changed

git-cliff-core/src/config.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,29 @@ pub struct RemoteConfig {
146146
pub bitbucket: Remote,
147147
}
148148

149+
impl RemoteConfig {
150+
/// Returns `true` if any remote is set.
151+
pub fn is_any_set(&self) -> bool {
152+
#[cfg(feature = "github")]
153+
if self.github.is_set() {
154+
return true;
155+
}
156+
#[cfg(feature = "gitlab")]
157+
if self.gitlab.is_set() {
158+
return true;
159+
}
160+
#[cfg(feature = "gitea")]
161+
if self.gitea.is_set() {
162+
return true;
163+
}
164+
#[cfg(feature = "bitbucket")]
165+
if self.bitbucket.is_set() {
166+
return true;
167+
}
168+
false
169+
}
170+
}
171+
149172
/// A single remote.
150173
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
151174
pub struct Remote {

git-cliff/src/lib.rs

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -123,52 +123,33 @@ fn process_repository<'a>(
123123
count && !ignore
124124
});
125125

126-
if !config.remote.github.is_set() {
126+
if !config.remote.is_any_set() {
127127
match repository.upstream_remote() {
128128
Ok(remote) => {
129-
debug!("No GitHub remote is set, using remote: {}", remote);
130-
config.remote.github.owner = remote.owner;
131-
config.remote.github.repo = remote.repo;
132-
config.remote.github.is_custom = remote.is_custom;
133-
}
134-
Err(e) => {
135-
debug!("Failed to get remote from GitHub repository: {:?}", e);
136-
}
137-
}
138-
} else if !config.remote.gitlab.is_set() {
139-
match repository.upstream_remote() {
140-
Ok(remote) => {
141-
debug!("No GitLab remote is set, using remote: {}", remote);
142-
config.remote.gitlab.owner = remote.owner;
143-
config.remote.gitlab.repo = remote.repo;
144-
config.remote.gitlab.is_custom = remote.is_custom;
145-
}
146-
Err(e) => {
147-
debug!("Failed to get remote from GitLab repository: {:?}", e);
148-
}
149-
}
150-
} else if !config.remote.gitea.is_set() {
151-
match repository.upstream_remote() {
152-
Ok(remote) => {
153-
debug!("No Gitea remote is set, using remote: {}", remote);
154-
config.remote.gitea.owner = remote.owner;
155-
config.remote.gitea.repo = remote.repo;
156-
config.remote.gitea.is_custom = remote.is_custom;
157-
}
158-
Err(e) => {
159-
debug!("Failed to get remote from Gitea repository: {:?}", e);
160-
}
161-
}
162-
} else if !config.remote.bitbucket.is_set() {
163-
match repository.upstream_remote() {
164-
Ok(remote) => {
165-
debug!("No Bitbucket remote is set, using remote: {}", remote);
166-
config.remote.bitbucket.owner = remote.owner;
167-
config.remote.bitbucket.repo = remote.repo;
168-
config.remote.bitbucket.is_custom = remote.is_custom;
129+
if !config.remote.github.is_set() {
130+
debug!("No GitHub remote is set, using remote: {}", remote);
131+
config.remote.github.owner = remote.owner;
132+
config.remote.github.repo = remote.repo;
133+
config.remote.github.is_custom = remote.is_custom;
134+
} else if !config.remote.gitlab.is_set() {
135+
debug!("No GitLab remote is set, using remote: {}", remote);
136+
config.remote.gitlab.owner = remote.owner;
137+
config.remote.gitlab.repo = remote.repo;
138+
config.remote.gitlab.is_custom = remote.is_custom;
139+
} else if !config.remote.gitea.is_set() {
140+
debug!("No Gitea remote is set, using remote: {}", remote);
141+
config.remote.gitea.owner = remote.owner;
142+
config.remote.gitea.repo = remote.repo;
143+
config.remote.gitea.is_custom = remote.is_custom;
144+
} else if !config.remote.bitbucket.is_set() {
145+
debug!("No Bitbucket remote is set, using remote: {}", remote);
146+
config.remote.bitbucket.owner = remote.owner;
147+
config.remote.bitbucket.repo = remote.repo;
148+
config.remote.bitbucket.is_custom = remote.is_custom;
149+
}
169150
}
170151
Err(e) => {
171-
debug!("Failed to get remote from Bitbucket repository: {:?}", e);
152+
debug!("Failed to get remote from repository: {:?}", e);
172153
}
173154
}
174155
}

0 commit comments

Comments
 (0)