Skip to content

Commit 5b72d27

Browse files
committed
Frame for gix fetch (#450)
1 parent 83f2156 commit 5b72d27

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

gitoxide-core/src/repository/fetch.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::OutputFormat;
2+
use git::bstr::BString;
3+
use git_repository as git;
4+
5+
pub struct Options {
6+
pub format: OutputFormat,
7+
pub dry_run: bool,
8+
pub remote: Option<String>,
9+
/// If non-empty, override all ref-specs otherwise configured in the remote
10+
pub ref_specs: Vec<BString>,
11+
}
12+
13+
pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=2;
14+
15+
pub(crate) mod function {
16+
#![allow(unused_variables, unused_mut)]
17+
use super::Options;
18+
use git_repository as git;
19+
20+
pub fn fetch(
21+
repo: git::Repository,
22+
mut progress: impl git::Progress,
23+
mut out: impl std::io::Write,
24+
err: impl std::io::Write,
25+
Options {
26+
format,
27+
dry_run,
28+
remote,
29+
ref_specs,
30+
}: Options,
31+
) -> anyhow::Result<()> {
32+
todo!()
33+
}
34+
}

gitoxide-core/src/repository/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub mod config;
1919
mod credential;
2020
pub use credential::function as credential;
2121
pub mod exclude;
22+
pub mod fetch;
23+
pub use fetch::function::fetch;
2224
pub mod mailmap;
2325
pub mod odb;
2426
pub mod remote;

src/plumbing/main.rs

+24
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use git_repository::bstr::io::BufReadExt;
1313
use gitoxide_core as core;
1414
use gitoxide_core::pack::verify;
1515

16+
use crate::plumbing::options::fetch;
1617
use crate::{
1718
plumbing::{
1819
options::{commit, config, credential, exclude, free, mailmap, odb, remote, revision, tree, Args, Subcommands},
@@ -112,6 +113,29 @@ pub fn main() -> Result<()> {
112113
})?;
113114

114115
match cmd {
116+
#[cfg(feature = "gitoxide-core-blocking-client")]
117+
Subcommands::Fetch(fetch::Platform {
118+
dry_run,
119+
remote,
120+
ref_spec,
121+
}) => {
122+
let opts = core::repository::fetch::Options {
123+
format,
124+
dry_run,
125+
remote,
126+
ref_specs: ref_spec,
127+
};
128+
prepare_and_run(
129+
"fetch",
130+
verbose,
131+
progress,
132+
progress_keep_open,
133+
core::repository::fetch::PROGRESS_RANGE,
134+
move |progress, out, err| {
135+
core::repository::fetch(repository(Mode::LenientWithGitInstallConfig)?, progress, out, err, opts)
136+
},
137+
)
138+
}
115139
Subcommands::Progress => show_progress(),
116140
Subcommands::Credential(cmd) => core::repository::credential(
117141
repository(Mode::StrictWithGitInstallConfig)?,

src/plumbing/options/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ pub enum Subcommands {
8181
/// A program just like `git credential`.
8282
#[clap(subcommand)]
8383
Credential(credential::Subcommands),
84+
/// Fetch data from remotes and store it in the repository
85+
#[cfg(feature = "gitoxide-core-blocking-client")]
86+
Fetch(fetch::Platform),
8487
/// Interact with the mailmap.
8588
#[clap(subcommand)]
8689
Mailmap(mailmap::Subcommands),
@@ -110,6 +113,28 @@ pub mod config {
110113
}
111114
}
112115

116+
#[cfg(feature = "gitoxide-core-blocking-client")]
117+
pub mod fetch {
118+
use git_repository as git;
119+
120+
#[derive(Debug, clap::Parser)]
121+
pub struct Platform {
122+
/// Don't change the local repository, but otherwise try to be as accurate as possible.
123+
#[clap(long, short = 'n')]
124+
pub dry_run: bool,
125+
126+
/// The name of the remote to connect to.
127+
///
128+
/// If unset, the current branch will determine the remote.
129+
#[clap(long, short = 'r')]
130+
pub remote: Option<String>,
131+
132+
/// Override the built-in and configured ref-specs with one or more of the given ones.
133+
#[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
134+
pub ref_spec: Vec<git_repository::bstr::BString>,
135+
}
136+
}
137+
113138
pub mod remote {
114139
use git_repository as git;
115140

0 commit comments

Comments
 (0)