Skip to content

Commit dcd9e00

Browse files
committed
remote url lookup inside push_hook
1 parent 129f481 commit dcd9e00

File tree

3 files changed

+21
-44
lines changed

3 files changed

+21
-44
lines changed

asyncgit/src/sync/hooks.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ pub fn hooks_prepare_commit_msg(
161161
/// see `git2_hooks::hooks_pre_push`
162162
pub fn hooks_pre_push(
163163
repo_path: &RepoPath,
164-
remote: Option<&str>,
165-
url: &str,
164+
remote: &str,
166165
push: &PrePushTarget<'_>,
167166
basic_credential: Option<crate::sync::cred::BasicAuthCredential>,
168167
) -> Result<HookResult> {
@@ -177,10 +176,21 @@ pub fn hooks_pre_push(
177176
return Ok(HookResult::Ok);
178177
}
179178

179+
let git_remote = repo.find_remote(remote)?;
180+
let url = git_remote
181+
.pushurl()
182+
.or_else(|| git_remote.url())
183+
.ok_or_else(|| {
184+
crate::error::Error::Generic(format!(
185+
"remote '{remote}' has no URL configured"
186+
))
187+
})?
188+
.to_string();
189+
180190
let advertised = advertised_remote_refs(
181191
repo_path,
182-
remote,
183-
url,
192+
Some(remote),
193+
&url,
184194
basic_credential,
185195
)?;
186196
let updates = match push {
@@ -196,14 +206,16 @@ pub fn hooks_pre_push(
196206
)?]
197207
}
198208
PrePushTarget::Tags => {
199-
// If remote is None, use url per git spec
200-
let remote = remote.unwrap_or(url);
201209
pre_push_tag_updates(repo_path, remote, &advertised)?
202210
}
203211
};
204212

205213
Ok(git2_hooks::hooks_pre_push(
206-
&repo, None, remote, url, &updates,
214+
&repo,
215+
None,
216+
Some(remote),
217+
&url,
218+
&updates,
207219
)?
208220
.into())
209221
}

src/popups/push.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,28 +144,11 @@ impl PushPopup {
144144
remote
145145
};
146146

147-
let remote_url = asyncgit::sync::get_remote_url(
148-
&self.repo.borrow(),
149-
&remote,
150-
)?;
151-
152-
// If remote doesn't have a URL configured, we can't push
153-
let Some(remote_url) = remote_url else {
154-
log::error!("remote '{remote}' has no URL configured");
155-
self.queue.push(InternalEvent::ShowErrorMsg(format!(
156-
"Remote '{remote}' has no URL configured"
157-
)));
158-
self.pending = false;
159-
self.visible = false;
160-
return Ok(());
161-
};
162-
163147
// run pre push hook - can reject push
164148
let repo = self.repo.borrow();
165149
if let HookResult::NotOk(e) = hooks_pre_push(
166150
&repo,
167-
Some(&remote),
168-
&remote_url,
151+
&remote,
169152
&asyncgit::sync::PrePushTarget::Branch {
170153
branch: &self.branch,
171154
delete: self.modifier.delete(),

src/popups/push_tags.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,10 @@ impl PushTagsPopup {
8686
) -> Result<()> {
8787
let remote = get_default_remote(&self.repo.borrow())?;
8888

89-
let remote_url = asyncgit::sync::get_remote_url(
90-
&self.repo.borrow(),
91-
&remote,
92-
)?;
93-
94-
// If remote doesn't have a URL configured, we can't push
95-
let Some(remote_url) = remote_url else {
96-
log::error!("remote '{remote}' has no URL configured");
97-
self.queue.push(InternalEvent::ShowErrorMsg(format!(
98-
"Remote '{remote}' has no URL configured"
99-
)));
100-
self.pending = false;
101-
self.visible = false;
102-
return Ok(());
103-
};
104-
105-
// run pre push hook - can reject push
10689
let repo = self.repo.borrow();
10790
if let HookResult::NotOk(e) = hooks_pre_push(
10891
&repo,
109-
Some(&remote),
110-
&remote_url,
92+
&remote,
11193
&asyncgit::sync::PrePushTarget::Tags,
11294
cred.clone(),
11395
)? {

0 commit comments

Comments
 (0)