Skip to content

Commit

Permalink
frame for gix repo exclude query (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Apr 28, 2022
1 parent 120675d commit a331314
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* **mailmap**
* [x] **verify** - check entries of a mailmap file for parse errors and display them
* **repository**
* **exclude**
* [x] **query** - check if path specs are excluded via gits exclusion rules like `.gitignore`.
* **verify** - validate a whole repository, for now only the object database.
* **commit**
* [x] **describe** - identify a commit by its closest tag in its past
Expand Down
3 changes: 2 additions & 1 deletion crate-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ See its [README.md](https://github.com/Byron/gitoxide/blob/main/git-lock/README.
* **refs**
* [ ] run transaction hooks and handle special repository states like quarantine
* [ ] support for different backends like `files` and `reftable`
* [ ] worktrees
* **worktrees**
* [ ] open a repository with worktrees
* [ ] remotes with push and pull
* [x] mailmap
* [x] object replacements (`git replace`)
Expand Down
14 changes: 14 additions & 0 deletions git-path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,19 @@
//! Callers may `.expect()` on the result to indicate they don't wish to handle this special and rare case. Note that servers should not
//! ever get into a code-path which does panic though.

/// A dummy type to represent path specs and help finding all spots that take path specs once it is implemented.
#[derive(Clone, Debug)]
pub struct Spec(String);

impl FromStr for Spec {
type Err = std::convert::Infallible;

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Spec(s.to_owned()))
}
}

mod convert;

pub use convert::*;
use std::str::FromStr;
29 changes: 29 additions & 0 deletions gitoxide-core/src/repository/exclude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use anyhow::bail;
use std::io;
use std::path::PathBuf;

use crate::OutputFormat;
use git_repository as git;

pub mod query {
use crate::OutputFormat;
use git_repository as git;

pub struct Options {
pub format: OutputFormat,
pub pathspecs: Vec<git::path::Spec>,
}
}

pub fn query(
repository: PathBuf,
mut out: impl io::Write,
query::Options { format, pathspecs }: query::Options,
) -> anyhow::Result<()> {
if format != OutputFormat::Human {
bail!("JSON output isn't implemented yet");
}

let repo = git::open(repository)?.apply_environment();
todo!("impl");
}
2 changes: 2 additions & 0 deletions gitoxide-core/src/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ pub mod verify;
pub mod odb;

pub mod mailmap;

pub mod exclude;
16 changes: 16 additions & 0 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ pub fn main() -> Result<()> {
},
),
},
repo::Subcommands::Exclude { cmd } => match cmd {
repo::exclude::Subcommands::Query { pathspecs } => prepare_and_run(
"repository-exclude-query",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, _err| {
core::repository::exclude::query(
repository,
out,
core::repository::exclude::query::Options { format, pathspecs },
)
},
),
},
repo::Subcommands::Mailmap { cmd } => match cmd {
repo::mailmap::Subcommands::Entries => prepare_and_run(
"repository-mailmap-entries",
Expand Down
18 changes: 18 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,24 @@ pub mod repo {
#[clap(subcommand)]
cmd: mailmap::Subcommands,
},
/// Interact with the exclude files like .gitignore.
Exclude {
#[clap(subcommand)]
cmd: exclude::Subcommands,
},
}

pub mod exclude {
use git_repository as git;

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Check if path-specs are excluded and print the result similar to `git check-ignore`.
Query {
/// The git path specifications to check for exclusion.
pathspecs: Vec<git::path::Spec>,
},
}
}

pub mod mailmap {
Expand Down

0 comments on commit a331314

Please sign in to comment.