Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config level for worktrees #816

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libgit2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ The build is now aborting. To disable, unset the variable or use `LIBGIT2_NO_VEN
cfg.include(path);
}
features.push_str("#define GIT_SSH 1\n");
features.push_str("#define GIT_SSH_MEMORY_CREDENTIALS 1\n");
features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n");
}
if https {
features.push_str("#define GIT_HTTPS 1\n");
Expand Down
4 changes: 3 additions & 1 deletion libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,8 @@ git_enum! {
GIT_CONFIG_LEVEL_XDG = 3,
GIT_CONFIG_LEVEL_GLOBAL = 4,
GIT_CONFIG_LEVEL_LOCAL = 5,
GIT_CONFIG_LEVEL_APP = 6,
GIT_CONFIG_LEVEL_WORKTREE = 6,
GIT_CONFIG_LEVEL_APP = 7,
GIT_CONFIG_HIGHEST_LEVEL = -1,
}
}
Expand Down Expand Up @@ -981,6 +982,7 @@ pub struct git_push_options {
pub proxy_opts: git_proxy_options,
pub follow_redirects: git_remote_redirect_t,
pub custom_headers: git_strarray,
pub remote_push_options: git_strarray,
}

pub type git_tag_foreach_cb =
Expand Down
2 changes: 1 addition & 1 deletion libgit2-sys/libgit2
Submodule libgit2 updated 271 files
1 change: 1 addition & 0 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ mod impls {
ConfigLevel::XDG => raw::GIT_CONFIG_LEVEL_XDG,
ConfigLevel::Global => raw::GIT_CONFIG_LEVEL_GLOBAL,
ConfigLevel::Local => raw::GIT_CONFIG_LEVEL_LOCAL,
ConfigLevel::Worktree => raw::GIT_CONFIG_LEVEL_WORKTREE,
ConfigLevel::App => raw::GIT_CONFIG_LEVEL_APP,
ConfigLevel::Highest => raw::GIT_CONFIG_HIGHEST_LEVEL,
}
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ pub enum ConfigLevel {
Global,
/// Repository specific config, e.g. $PWD/.git/config
Local,
/// Worktree-specific config, e.g. $GIT_DIR/config.worktree
Worktree,
/// Application specific configuration file
App,
/// Highest level available
Expand Down Expand Up @@ -957,12 +959,14 @@ impl fmt::Display for ReferenceType {
impl ConfigLevel {
/// Converts a raw configuration level to a ConfigLevel
pub fn from_raw(raw: raw::git_config_level_t) -> ConfigLevel {
match raw {
match raw >> 12 {
// TODO: why!?
raw::GIT_CONFIG_LEVEL_PROGRAMDATA => ConfigLevel::ProgramData,
raw::GIT_CONFIG_LEVEL_SYSTEM => ConfigLevel::System,
raw::GIT_CONFIG_LEVEL_XDG => ConfigLevel::XDG,
raw::GIT_CONFIG_LEVEL_GLOBAL => ConfigLevel::Global,
raw::GIT_CONFIG_LEVEL_LOCAL => ConfigLevel::Local,
raw::GIT_CONFIG_LEVEL_WORKTREE => ConfigLevel::Worktree,
raw::GIT_CONFIG_LEVEL_APP => ConfigLevel::App,
raw::GIT_CONFIG_HIGHEST_LEVEL => ConfigLevel::Highest,
n => panic!("unknown config level: {}", n),
Expand Down
18 changes: 18 additions & 0 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct PushOptions<'cb> {
follow_redirects: RemoteRedirect,
custom_headers: Vec<CString>,
custom_headers_ptrs: Vec<*const c_char>,
remote_push_options: Vec<CString>,
remote_push_options_ptrs: Vec<*const c_char>,
}

/// Holds callbacks for a connection to a `Remote`. Disconnects when dropped
Expand Down Expand Up @@ -628,6 +630,8 @@ impl<'cb> PushOptions<'cb> {
follow_redirects: RemoteRedirect::Initial,
custom_headers: Vec::new(),
custom_headers_ptrs: Vec::new(),
remote_push_options: Vec::new(),
remote_push_options_ptrs: Vec::new(),
}
}

Expand Down Expand Up @@ -673,6 +677,16 @@ impl<'cb> PushOptions<'cb> {
self.custom_headers_ptrs = self.custom_headers.iter().map(|s| s.as_ptr()).collect();
self
}

/// Set server-side options for this push operation.
pub fn remote_push_options(&mut self, remote_push_options: &[&str]) -> &mut Self {
self.remote_push_options = remote_push_options
.iter()
.map(|&s| CString::new(s).unwrap())
.collect();
self.remote_push_options_ptrs = self.remote_push_options.iter().map(|s| s.as_ptr()).collect();
self
}
}

impl<'cb> Binding for PushOptions<'cb> {
Expand Down Expand Up @@ -700,6 +714,10 @@ impl<'cb> Binding for PushOptions<'cb> {
count: self.custom_headers_ptrs.len(),
strings: self.custom_headers_ptrs.as_ptr() as *mut _,
},
remote_push_options: git_strarray {
count: self.remote_push_options_ptrs.len(),
strings: self.remote_push_options_ptrs.as_ptr() as *mut _,
},
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/add_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ fn test_add_extensions() -> Result<(), Error> {

let extensions = unsafe { get_extensions() }?;

assert_eq!(extensions.len(), 3);
assert_eq!(extensions.len(), 4);
assert_eq!(extensions.get(0), Some("custom"));
// The objectformat extension was added in 1.6
assert_eq!(extensions.get(1), Some("noop"));
assert_eq!(extensions.get(2), Some("objectformat"));
assert_eq!(extensions.get(3), Some("worktreeconfig"));

Ok(())
}
3 changes: 2 additions & 1 deletion tests/get_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use git2::Error;
fn test_get_extensions() -> Result<(), Error> {
let extensions = unsafe { get_extensions() }?;

assert_eq!(extensions.len(), 2);
assert_eq!(extensions.len(), 3);
assert_eq!(extensions.get(0), Some("noop"));
// The objectformat extension was added in 1.6
assert_eq!(extensions.get(1), Some("objectformat"));
assert_eq!(extensions.get(2), Some("worktreeconfig"));

Ok(())
}
3 changes: 2 additions & 1 deletion tests/remove_extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ fn test_remove_extensions() -> Result<(), Error> {

let extensions = unsafe { get_extensions() }?;

assert_eq!(extensions.len(), 2);
assert_eq!(extensions.len(), 3);
assert_eq!(extensions.get(0), Some("custom"));
assert_eq!(extensions.get(1), Some("other"));
assert_eq!(extensions.get(2), Some("worktreeconfig"));

Ok(())
}
Loading