Skip to content

Commit

Permalink
Frame for gix fetch (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 2, 2022
1 parent 83f2156 commit 5b72d27
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
34 changes: 34 additions & 0 deletions gitoxide-core/src/repository/fetch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use crate::OutputFormat;
use git::bstr::BString;
use git_repository as git;

pub struct Options {
pub format: OutputFormat,
pub dry_run: bool,
pub remote: Option<String>,
/// If non-empty, override all ref-specs otherwise configured in the remote
pub ref_specs: Vec<BString>,
}

pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=2;

pub(crate) mod function {
#![allow(unused_variables, unused_mut)]
use super::Options;
use git_repository as git;

pub fn fetch(
repo: git::Repository,
mut progress: impl git::Progress,
mut out: impl std::io::Write,
err: impl std::io::Write,
Options {
format,
dry_run,
remote,
ref_specs,
}: Options,
) -> anyhow::Result<()> {
todo!()
}
}
2 changes: 2 additions & 0 deletions gitoxide-core/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub mod config;
mod credential;
pub use credential::function as credential;
pub mod exclude;
pub mod fetch;
pub use fetch::function::fetch;
pub mod mailmap;
pub mod odb;
pub mod remote;
Expand Down
24 changes: 24 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use git_repository::bstr::io::BufReadExt;
use gitoxide_core as core;
use gitoxide_core::pack::verify;

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

match cmd {
#[cfg(feature = "gitoxide-core-blocking-client")]
Subcommands::Fetch(fetch::Platform {
dry_run,
remote,
ref_spec,
}) => {
let opts = core::repository::fetch::Options {
format,
dry_run,
remote,
ref_specs: ref_spec,
};
prepare_and_run(
"fetch",
verbose,
progress,
progress_keep_open,
core::repository::fetch::PROGRESS_RANGE,
move |progress, out, err| {
core::repository::fetch(repository(Mode::LenientWithGitInstallConfig)?, progress, out, err, opts)
},
)
}
Subcommands::Progress => show_progress(),
Subcommands::Credential(cmd) => core::repository::credential(
repository(Mode::StrictWithGitInstallConfig)?,
Expand Down
25 changes: 25 additions & 0 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ pub enum Subcommands {
/// A program just like `git credential`.
#[clap(subcommand)]
Credential(credential::Subcommands),
/// Fetch data from remotes and store it in the repository
#[cfg(feature = "gitoxide-core-blocking-client")]
Fetch(fetch::Platform),
/// Interact with the mailmap.
#[clap(subcommand)]
Mailmap(mailmap::Subcommands),
Expand Down Expand Up @@ -110,6 +113,28 @@ pub mod config {
}
}

#[cfg(feature = "gitoxide-core-blocking-client")]
pub mod fetch {
use git_repository as git;

#[derive(Debug, clap::Parser)]
pub struct Platform {
/// Don't change the local repository, but otherwise try to be as accurate as possible.
#[clap(long, short = 'n')]
pub dry_run: bool,

/// The name of the remote to connect to.
///
/// If unset, the current branch will determine the remote.
#[clap(long, short = 'r')]
pub remote: Option<String>,

/// Override the built-in and configured ref-specs with one or more of the given ones.
#[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
pub ref_spec: Vec<git_repository::bstr::BString>,
}
}

pub mod remote {
use git_repository as git;

Expand Down

0 comments on commit 5b72d27

Please sign in to comment.