Skip to content

Commit d6ef2ce

Browse files
committed
adjust to changes in git-sec (#450)
1 parent fe24b41 commit d6ef2ce

File tree

13 files changed

+33
-43
lines changed

13 files changed

+33
-43
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

git-repository/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ git-discover = { version = "^0.4.2", path = "../git-discover" }
8282
git-tempfile = { version = "^2.0.0", path = "../git-tempfile" }
8383
git-lock = { version = "^2.0.0", path = "../git-lock" }
8484
git-validate = { version = "^0.5.5", path = "../git-validate" }
85-
git-sec = { version = "^0.3.1", path = "../git-sec", features = ["thiserror"] }
85+
git-sec = { version = "^0.3.1", path = "../git-sec" }
8686
git-date = { version = "^0.1.0", path = "../git-date" }
8787
git-refspec = { version = "^0.1.1", path = "../git-refspec" }
8888

git-repository/src/config/cache/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl Cache {
171171
pub fn xdg_config_path(
172172
&self,
173173
resource_file_name: &str,
174-
) -> Result<Option<PathBuf>, git_sec::permission::Error<PathBuf, git_sec::Permission>> {
174+
) -> Result<Option<PathBuf>, git_sec::permission::Error<PathBuf>> {
175175
std::env::var_os("XDG_CONFIG_HOME")
176176
.map(|path| (path, &self.xdg_config_home_env))
177177
.or_else(|| std::env::var_os("HOME").map(|path| (path, &self.home_env)))

git-repository/src/config/cache/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl std::fmt::Debug for Cache {
1616
impl Cache {
1717
pub(crate) fn personas(&self) -> &identity::Personas {
1818
self.personas
19-
.get_or_init(|| identity::Personas::from_config_and_env(&self.resolved, &self.git_prefix))
19+
.get_or_init(|| identity::Personas::from_config_and_env(&self.resolved, self.git_prefix))
2020
}
2121

2222
pub(crate) fn url_rewrite(&self) -> &remote::url::Rewrite {
@@ -29,7 +29,7 @@ impl Cache {
2929
&self,
3030
) -> Result<&remote::url::SchemePermission, remote::url::scheme_permission::init::Error> {
3131
self.url_scheme.get_or_try_init(|| {
32-
remote::url::SchemePermission::from_config(&self.resolved, &self.git_prefix, self.filter_config_section)
32+
remote::url::SchemePermission::from_config(&self.resolved, self.git_prefix, self.filter_config_section)
3333
})
3434
}
3535
}

git-repository/src/config/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pub use git_config::*;
22
use git_features::threading::OnceCell;
33

4-
use crate::{bstr::BString, permission, remote, repository::identity, revision::spec, Repository};
4+
use crate::{bstr::BString, remote, repository::identity, revision::spec, Repository};
55

66
pub(crate) mod cache;
77
mod snapshot;
@@ -84,10 +84,10 @@ pub(crate) struct Cache {
8484
/// The path to the user-level excludes file to ignore certain files in the worktree.
8585
pub excludes_file: Option<std::path::PathBuf>,
8686
/// Define how we can use values obtained with `xdg_config(…)` and its `XDG_CONFIG_HOME` variable.
87-
xdg_config_home_env: permission::env_var::Resource,
87+
xdg_config_home_env: git_sec::Permission,
8888
/// Define how we can use values obtained with `xdg_config(…)`. and its `HOME` variable.
89-
home_env: permission::env_var::Resource,
89+
home_env: git_sec::Permission,
9090
/// How to use git-prefixed environment variables
91-
git_prefix: permission::env_var::Resource,
91+
git_prefix: git_sec::Permission,
9292
// TODO: make core.precomposeUnicode available as well.
9393
}

git-repository/src/config/snapshot/credential_helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ impl Snapshot<'_> {
120120
}
121121
}
122122

123-
let allow_git_env = *self.repo.options.permissions.env.git_prefix == git_sec::Permission::Allow;
124-
let allow_ssh_env = *self.repo.options.permissions.env.ssh_prefix == git_sec::Permission::Allow;
123+
let allow_git_env = self.repo.options.permissions.env.git_prefix.is_allowed();
124+
let allow_ssh_env = self.repo.options.permissions.env.ssh_prefix.is_allowed();
125125
let prompt_options =
126126
git_prompt::Options::default().apply_environment(allow_git_env, allow_ssh_env, allow_git_env);
127127
Ok((

git-repository/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,10 @@ pub fn open_opts(directory: impl Into<std::path::PathBuf>, options: open::Option
234234
pub mod permission {
235235
///
236236
pub mod env_var {
237-
use git_sec::{permission, Access};
238-
239-
/// A permission to control access to the resource pointed to an environment variable.
240-
pub type Resource = Access<permission::Resource, git_sec::Permission>;
241237
///
242238
pub mod resource {
243239
///
244-
pub type Error = git_sec::permission::Error<std::path::PathBuf, git_sec::Permission>;
240+
pub type Error = git_sec::permission::Error<std::path::PathBuf>;
245241
}
246242
}
247243
}

git-repository/src/remote/url/scheme_permission.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
use std::{borrow::Cow, collections::BTreeMap, convert::TryFrom};
44

5-
use crate::{
6-
bstr::{BStr, BString, ByteSlice},
7-
permission,
8-
};
5+
use crate::bstr::{BStr, BString, ByteSlice};
96

107
///
118
pub mod init {
@@ -62,7 +59,7 @@ pub(crate) struct SchemePermission {
6259
impl SchemePermission {
6360
pub fn from_config(
6461
config: &git_config::File<'static>,
65-
git_prefix: &permission::env_var::Resource,
62+
git_prefix: git_sec::Permission,
6663
mut filter: fn(&git_config::file::Metadata) -> bool,
6764
) -> Result<Self, init::Error> {
6865
let allow: Option<Allow> = config

git-repository/src/repository/identity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Cow, time::SystemTime};
22

3-
use crate::{bstr::BString, permission};
3+
use crate::bstr::BString;
44

55
/// Identity handling.
66
impl crate::Repository {
@@ -98,7 +98,7 @@ pub(crate) struct Personas {
9898
}
9999

100100
impl Personas {
101-
pub fn from_config_and_env(config: &git_config::File<'_>, git_env: &permission::env_var::Resource) -> Self {
101+
pub fn from_config_and_env(config: &git_config::File<'_>, git_env: git_sec::Permission) -> Self {
102102
fn env_var(name: &str) -> Option<BString> {
103103
std::env::var_os(name).map(|value| git_path::into_bstr(Cow::Owned(value.into())).into_owned())
104104
}

git-repository/src/repository/permissions.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use git_sec::{Access, Trust};
2-
3-
use crate::permission;
1+
use git_sec::Trust;
42

53
/// Permissions associated with various resources of a git repository
64
#[derive(Debug, Clone)]
@@ -67,23 +65,23 @@ pub struct Environment {
6765
/// Control whether resources pointed to by `XDG_CONFIG_HOME` can be used when looking up common configuration values.
6866
///
6967
/// Note that [`git_sec::Permission::Forbid`] will cause the operation to abort if a resource is set via the XDG config environment.
70-
pub xdg_config_home: permission::env_var::Resource,
68+
pub xdg_config_home: git_sec::Permission,
7169
/// Control the way resources pointed to by the home directory (similar to `xdg_config_home`) may be used.
72-
pub home: permission::env_var::Resource,
70+
pub home: git_sec::Permission,
7371
/// Control if resources pointed to by `GIT_*` prefixed environment variables can be used.
74-
pub git_prefix: permission::env_var::Resource,
72+
pub git_prefix: git_sec::Permission,
7573
/// Control if resources pointed to by `SSH_*` prefixed environment variables can be used (like `SSH_ASKPASS`)
76-
pub ssh_prefix: permission::env_var::Resource,
74+
pub ssh_prefix: git_sec::Permission,
7775
}
7876

7977
impl Environment {
8078
/// Allow access to the entire environment.
8179
pub fn all() -> Self {
8280
Environment {
83-
xdg_config_home: Access::resource(git_sec::Permission::Allow),
84-
home: Access::resource(git_sec::Permission::Allow),
85-
git_prefix: Access::resource(git_sec::Permission::Allow),
86-
ssh_prefix: Access::resource(git_sec::Permission::Allow),
81+
xdg_config_home: git_sec::Permission::Allow,
82+
home: git_sec::Permission::Allow,
83+
git_prefix: git_sec::Permission::Allow,
84+
ssh_prefix: git_sec::Permission::Allow,
8785
}
8886
}
8987
}
@@ -122,11 +120,11 @@ impl Permissions {
122120
includes: false,
123121
},
124122
env: {
125-
let deny = permission::env_var::Resource::resource(git_sec::Permission::Deny);
123+
let deny = git_sec::Permission::Deny;
126124
Environment {
127-
xdg_config_home: deny.clone(),
128-
home: deny.clone(),
129-
ssh_prefix: deny.clone(),
125+
xdg_config_home: deny,
126+
home: deny,
127+
ssh_prefix: deny,
130128
git_prefix: deny,
131129
}
132130
},

git-repository/src/worktree/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub mod excludes {
111111
#[error("Could not read repository exclude.")]
112112
Io(#[from] std::io::Error),
113113
#[error(transparent)]
114-
EnvironmentPermission(#[from] git_sec::permission::Error<PathBuf, git_sec::Permission>),
114+
EnvironmentPermission(#[from] git_sec::permission::Error<PathBuf>),
115115
}
116116

117117
impl<'repo> crate::Worktree<'repo> {

git-repository/tests/remote/connect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod blocking_io {
3232
remote::repo("protocol_file_user").git_dir(),
3333
git::open::Options::isolated().permissions(git::Permissions {
3434
env: git::permissions::Environment {
35-
git_prefix: git_sec::Access::resource(git_sec::Permission::Allow),
35+
git_prefix: git_sec::Permission::Allow,
3636
..git::permissions::Environment::all()
3737
},
3838
..git::Permissions::isolated()

git-repository/tests/repository/config/identity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use git_repository as git;
4-
use git_sec::{Access, Permission};
4+
use git_sec::Permission;
55
use git_testtools::Env;
66
use serial_test::serial;
77

@@ -28,8 +28,8 @@ fn author_and_committer_and_fallback() {
2828
repo.git_dir(),
2929
repo.open_options().clone().with(trust).permissions(git::Permissions {
3030
env: git::permissions::Environment {
31-
xdg_config_home: Access::resource(Permission::Deny),
32-
home: Access::resource(Permission::Deny),
31+
xdg_config_home: Permission::Deny,
32+
home: Permission::Deny,
3333
..git::permissions::Environment::all()
3434
},
3535
..Default::default()

0 commit comments

Comments
 (0)