Skip to content

Commit

Permalink
Control which command is lenient or not. That way gix-config can be…
Browse files Browse the repository at this point in the history
… lenient.
  • Loading branch information
Byron committed Aug 17, 2022
1 parent 0235111 commit 6a9c58f
Showing 1 changed file with 37 additions and 14 deletions.
51 changes: 37 additions & 14 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ pub fn main() -> Result<()> {
let object_hash = args.object_hash;
use git_repository as git;
let repository = args.repository;
let repository = move || {
enum Mode {
Strict,
Lenient,
}
let repository = move |mode: Mode| {
let mut mapping: git::sec::trust::Mapping<git::open::Options> = Default::default();
mapping.full = mapping.full.strict_config(true);
mapping.reduced = mapping.reduced.strict_config(true);
let toggle = matches!(mode, Mode::Strict);
mapping.full = mapping.full.strict_config(toggle);
mapping.reduced = mapping.reduced.strict_config(toggle);
git::ThreadSafeRepository::discover_opts(repository, Default::default(), mapping)
.map(git::Repository::from)
.map(|r| r.apply_environment())
Expand Down Expand Up @@ -88,7 +93,7 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::config::list(repository()?, filter, format, out),
move |_progress, out, _err| core::repository::config::list(repository(Mode::Lenient)?, filter, format, out),
)
.map(|_| ()),
Subcommands::Free(subcommands) => match subcommands {
Expand Down Expand Up @@ -505,7 +510,7 @@ pub fn main() -> Result<()> {
core::repository::verify::PROGRESS_RANGE,
move |progress, out, _err| {
core::repository::verify::integrity(
repository()?,
repository(Mode::Strict)?,
out,
progress,
&should_interrupt,
Expand All @@ -525,7 +530,9 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::revision::previous_branches(repository()?, out, format),
move |_progress, out, _err| {
core::repository::revision::previous_branches(repository(Mode::Lenient)?, out, format)
},
),
revision::Subcommands::Explain { spec } => prepare_and_run(
"revision-explain",
Expand All @@ -547,7 +554,7 @@ pub fn main() -> Result<()> {
None,
move |_progress, out, _err| {
core::repository::revision::resolve(
repository()?,
repository(Mode::Strict)?,
specs,
out,
core::repository::revision::resolve::Options {
Expand Down Expand Up @@ -577,7 +584,7 @@ pub fn main() -> Result<()> {
None,
move |_progress, out, err| {
core::repository::commit::describe(
repository()?,
repository(Mode::Strict)?,
rev_spec.as_deref(),
out,
err,
Expand Down Expand Up @@ -606,7 +613,14 @@ pub fn main() -> Result<()> {
progress_keep_open,
None,
move |_progress, out, _err| {
core::repository::tree::entries(repository()?, treeish.as_deref(), recursive, extended, format, out)
core::repository::tree::entries(
repository(Mode::Strict)?,
treeish.as_deref(),
recursive,
extended,
format,
out,
)
},
),
tree::Subcommands::Info { treeish, extended } => prepare_and_run(
Expand All @@ -616,7 +630,14 @@ pub fn main() -> Result<()> {
progress_keep_open,
None,
move |_progress, out, err| {
core::repository::tree::info(repository()?, treeish.as_deref(), extended, format, out, err)
core::repository::tree::info(
repository(Mode::Strict)?,
treeish.as_deref(),
extended,
format,
out,
err,
)
},
),
},
Expand All @@ -627,15 +648,15 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, _err| core::repository::odb::entries(repository()?, format, out),
move |_progress, out, _err| core::repository::odb::entries(repository(Mode::Strict)?, format, out),
),
odb::Subcommands::Info => prepare_and_run(
"odb-info",
verbose,
progress,
progress_keep_open,
None,
move |_progress, out, err| core::repository::odb::info(repository()?, format, out, err),
move |_progress, out, err| core::repository::odb::info(repository(Mode::Strict)?, format, out, err),
),
},
Subcommands::Mailmap(cmd) => match cmd {
Expand All @@ -645,7 +666,9 @@ pub fn main() -> Result<()> {
progress,
progress_keep_open,
None,
move |_progress, out, err| core::repository::mailmap::entries(repository()?, format, out, err),
move |_progress, out, err| {
core::repository::mailmap::entries(repository(Mode::Lenient)?, format, out, err)
},
),
},
Subcommands::Exclude(cmd) => match cmd {
Expand All @@ -662,7 +685,7 @@ pub fn main() -> Result<()> {
move |_progress, out, _err| {
use git::bstr::ByteSlice;
core::repository::exclude::query(
repository()?,
repository(Mode::Strict)?,
if pathspecs.is_empty() {
Box::new(
stdin_or_bail()?
Expand Down

0 comments on commit 6a9c58f

Please sign in to comment.