History

feat!: remove `gix remote --url` in favor of determining the intention similar to `git fetch` (#450)

Sebastian Thiel committed 4 years ago

Commit 92bbe331 parent 8c7351c4 files · +22 −35Browse files

Unified · Split

4 files
  1. gitoxide-core/src/repository/fetch.rs +1 −3
  2. gitoxide-core/src/repository/remote.rs +17 −16
  3. src/plumbing/main.rs +2 −6
  4. src/plumbing/options/mod.rs +2 −10
gitoxide-core/src/repository/fetch.rs+1−3
@@ -6,7 +6,6 @@ pub struct Options { · 5 unmodified lines
6 pub format: OutputFormat,6 pub format: OutputFormat,
7 pub dry_run: bool,7 pub dry_run: bool,
8 pub remote: Option<String>,8 pub remote: Option<String>,
9 pub url: Option<git::Url>,
10 /// If non-empty, override all ref-specs otherwise configured in the remote9 /// If non-empty, override all ref-specs otherwise configured in the remote
11 pub ref_specs: Vec<BString>,10 pub ref_specs: Vec<BString>,
12}11}
@@ -27,11 +26,10 @@ pub(crate) mod function { · 14 unmodified lines
27 format,26 format,
28 dry_run,27 dry_run,
29 remote,28 remote,
30 url,
31 ref_specs,29 ref_specs,
32 }: Options,30 }: Options,
33 ) -> anyhow::Result<()> {31 ) -> anyhow::Result<()> {
34 let _remote = crate::repository::remote::by_name_or_url(&repo, remote.as_deref(), url)?;32 let _remote = crate::repository::remote::by_name_or_url(&repo, remote.as_deref())?;
35 todo!()33 todo!()
36 }34 }
37}35}
gitoxide-core/src/repository/remote.rs+17−16
@@ -21,10 +21,9 @@ mod refs_impl { · 20 unmodified lines
21 Tracking { ref_specs: Vec<BString> },21 Tracking { ref_specs: Vec<BString> },
22 }22 }
23 23
24 pub struct Context {24 pub struct Options {
25 pub format: OutputFormat,25 pub format: OutputFormat,
26 pub name: Option<String>,26 pub name_or_url: Option<String>,
27 pub url: Option<git_repository::Url>,
28 pub handshake_info: bool,27 pub handshake_info: bool,
29 }28 }
30 29
@@ -38,15 +37,14 @@ mod refs_impl { · 7 unmodified lines
38 mut progress: impl git::Progress,37 mut progress: impl git::Progress,
39 mut out: impl std::io::Write,38 mut out: impl std::io::Write,
40 err: impl std::io::Write,39 err: impl std::io::Write,
41 refs::Context {40 refs::Options {
42 format,41 format,
43 name,42 name_or_url,
44 url,
45 handshake_info,43 handshake_info,
46 }: refs::Context,44 }: refs::Options,
47 ) -> anyhow::Result<()> {45 ) -> anyhow::Result<()> {
48 use anyhow::Context;46 use anyhow::Context;
49 let mut remote = by_name_or_url(&repo, name.as_deref(), url)?;47 let mut remote = by_name_or_url(&repo, name_or_url.as_deref())?;
50 if let refs::Kind::Tracking { ref_specs, .. } = &kind {48 if let refs::Kind::Tracking { ref_specs, .. } = &kind {
51 if format != OutputFormat::Human {49 if format != OutputFormat::Human {
52 bail!("JSON output isn't yet supported for listing ref-mappings.");50 bail!("JSON output isn't yet supported for listing ref-mappings.");
@@ -255,17 +253,20 @@ use git_repository as git; · 202 unmodified lines
255 253
256pub(crate) fn by_name_or_url<'repo>(254pub(crate) fn by_name_or_url<'repo>(
257 repo: &'repo git::Repository,255 repo: &'repo git::Repository,
258 name: Option<&str>,256 name_or_url: Option<&str>,
259 url: Option<git::Url>,
260) -> anyhow::Result<git::Remote<'repo>> {257) -> anyhow::Result<git::Remote<'repo>> {
261 use anyhow::{bail, Context};258 use anyhow::Context;
262 Ok(match (name, url) {259 Ok(match name_or_url {
263 (Some(name), None) => repo.find_remote(&name)?,260 Some(name) => {
264 (None, None) => repo261 if name.contains('/') {
262 repo.remote_at(git::url::parse(name.into())?)?
263 } else {
264 repo.find_remote(&name)?
265 }
266 }
267 None => repo
265 .head()?268 .head()?
266 .into_remote(git::remote::Direction::Fetch)269 .into_remote(git::remote::Direction::Fetch)
267 .context("Cannot find a remote for unborn branch")??,270 .context("Cannot find a remote for unborn branch")??,
268 (None, Some(url)) => repo.remote_at(url)?,
269 (Some(_), Some(_)) => bail!("Must not set both the remote name and the url - they are mutually exclusive"),
270 })271 })
271}272}
src/plumbing/main.rs+2−6
@@ -118,14 +118,12 @@ pub fn main() -> Result<()> { · 117 unmodified lines
118 dry_run,118 dry_run,
119 remote,119 remote,
120 ref_spec,120 ref_spec,
121 url,
122 }) => {121 }) => {
123 let opts = core::repository::fetch::Options {122 let opts = core::repository::fetch::Options {
124 format,123 format,
125 dry_run,124 dry_run,
126 remote,125 remote,
127 ref_specs: ref_spec,126 ref_specs: ref_spec,
128 url,
129 };127 };
130 prepare_and_run(128 prepare_and_run(
131 "fetch",129 "fetch",
@@ -150,7 +148,6 @@ pub fn main() -> Result<()> { · 18 unmodified lines
150 #[cfg_attr(feature = "small", allow(unused_variables))]148 #[cfg_attr(feature = "small", allow(unused_variables))]
151 Subcommands::Remote(remote::Platform {149 Subcommands::Remote(remote::Platform {
152 name,150 name,
153 url,
154 cmd,151 cmd,
155 handshake_info,152 handshake_info,
156 }) => match cmd {153 }) => match cmd {
@@ -162,9 +159,8 @@ pub fn main() -> Result<()> { · 5 unmodified lines
162 core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }159 core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
163 }160 }
164 };161 };
165 let context = core::repository::remote::refs::Context {162 let context = core::repository::remote::refs::Options {
166 name,163 name_or_url: name,
167 url,
168 format,164 format,
169 handshake_info,165 handshake_info,
170 };166 };
src/plumbing/options/mod.rs+2−10
@@ -123,16 +123,12 @@ pub mod fetch { · 122 unmodified lines
123 #[clap(long, short = 'n')]123 #[clap(long, short = 'n')]
124 pub dry_run: bool,124 pub dry_run: bool,
125 125
126 /// The name of the remote to connect to.126 /// The name of the remote to connect to, or the url of the remote to connect to directly.
127 ///127 ///
128 /// If unset, the current branch will determine the remote.128 /// If unset, the current branch will determine the remote.
129 #[clap(long, short = 'r')]129 #[clap(long, short = 'r')]
130 pub remote: Option<String>,130 pub remote: Option<String>,
131 131
132 /// Connect directly to the given URL, forgoing any configuration from the repository.
133 #[clap(long, short = 'u', conflicts_with("remote"), parse(try_from_os_str = std::convert::TryFrom::try_from))]
134 pub url: Option<git::Url>,
135
136 /// Override the built-in and configured ref-specs with one or more of the given ones.132 /// Override the built-in and configured ref-specs with one or more of the given ones.
137 #[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]133 #[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
138 pub ref_spec: Vec<git_repository::bstr::BString>,134 pub ref_spec: Vec<git_repository::bstr::BString>,
@@ -144,16 +140,12 @@ pub mod remote { · 5 unmodified lines
144 140
145 #[derive(Debug, clap::Parser)]141 #[derive(Debug, clap::Parser)]
146 pub struct Platform {142 pub struct Platform {
147 /// The name of the remote to connect to.143 /// The name of the remote to connect to, or the URL of the remote to connect to directly.
148 ///144 ///
149 /// If unset, the current branch will determine the remote.145 /// If unset, the current branch will determine the remote.
150 #[clap(long, short = 'n')]146 #[clap(long, short = 'n')]
151 pub name: Option<String>,147 pub name: Option<String>,
152 148
153 /// Connect directly to the given URL, forgoing any configuration from the repository.
154 #[clap(long, short = 'u', conflicts_with("name"), parse(try_from_os_str = std::convert::TryFrom::try_from))]
155 pub url: Option<git::Url>,
156
157 /// Output additional typically information provided by the server as part of the connection handshake.149 /// Output additional typically information provided by the server as part of the connection handshake.
158 #[clap(long)]150 #[clap(long)]
159 pub handshake_info: bool,151 pub handshake_info: bool,