Skip to content

Commit 71f3ff8

Browse files
committed
fix: Allow remote-URLs to be used when pushing.
That way this works when branches are checked out with URLs in stead of symbolic remote names. This happens by default when using `gh pr checkout`. Previously, it would panic, which now also won't happen anymore in favor of a more descriptive error.
1 parent 2919096 commit 71f3ff8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/command/release/git.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{convert::TryInto, process::Command};
22

3-
use anyhow::{anyhow, bail};
3+
use anyhow::{anyhow, bail, Context};
44
use cargo_metadata::Package;
55
use gix::{bstr::ByteSlice, refs, refs::transaction::PreviousValue, Id};
66

@@ -98,15 +98,17 @@ pub fn push_tags_and_head(
9898

9999
let mut cmd = Command::new("git");
100100
cmd.arg("push")
101-
.arg(
102-
repo.head()?
101+
.arg({
102+
let remote = repo
103+
.head()?
103104
.into_remote(gix::remote::Direction::Push)
104-
.ok_or_else(|| anyhow!("Cannot push in uninitialized repo"))??
105+
.ok_or_else(|| anyhow!("Cannot push in uninitialized repo"))??;
106+
remote
105107
.name()
106-
.expect("configured remotes have a name")
107-
.as_bstr()
108-
.to_string(),
109-
)
108+
.map(|name| name.as_bstr().to_string())
109+
.or_else(|| remote.url(gix::remote::Direction::Push).map(|url| url.to_string()))
110+
.context("Couldn't find push-remote of HEAD reference")?
111+
})
110112
.arg("HEAD");
111113
for tag_name in tag_names {
112114
cmd.arg(tag_name.as_bstr().to_str()?);

0 commit comments

Comments
 (0)