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

signing with login shell #5910

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/gitbutler-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ publish = false

[dependencies]
git2.workspace = true
gix.workspace = true
anyhow = "1.0.95"
tracing.workspace = true
serde = { workspace = true, features = ["std"]}
gitbutler-project.workspace = true
49 changes: 28 additions & 21 deletions crates/gitbutler-config/src/git.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use anyhow::Result;
use git2::ConfigLevel;
use gix::bstr::{BStr, ByteVec};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::ffi::OsStr;

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
Expand All @@ -24,11 +27,17 @@ pub trait GitConfig {

impl GitConfig for git2::Repository {
fn gb_config(&self) -> Result<GbConfig> {
let sign_commits = get_bool(self, SIGN_COMMITS)?;
let signing_key = get_string(self, SIGNING_KEY)?;
let signing_format = get_string(self, SIGNING_FORMAT)?;
let gpg_program = get_string(self, GPG_PROGRAM)?;
let gpg_ssh_program = get_string(self, GPG_SSH_PROGRAM)?;
let repo = gix::open(self.path())?;
let config = repo.config_snapshot();
let sign_commits = config.boolean(SIGN_COMMITS);
let signing_key = config.string(SIGNING_KEY).and_then(bstring_into_string);
let signing_format = config.string(SIGNING_FORMAT).and_then(bstring_into_string);
let gpg_program = config
.trusted_program(GPG_PROGRAM)
.and_then(osstr_into_string);
let gpg_ssh_program = config
.trusted_program(GPG_SSH_PROGRAM)
.and_then(osstr_into_string);
Ok(GbConfig {
sign_commits,
signing_key,
Expand Down Expand Up @@ -57,25 +66,23 @@ impl GitConfig for git2::Repository {
}
}

fn get_bool(repo: &git2::Repository, key: &str) -> Result<Option<bool>> {
let config = repo.config()?;
match config.get_bool(key) {
Ok(value) => Ok(Some(value)),
Err(err) => match err.code() {
git2::ErrorCode::NotFound => Ok(None),
_ => Err(err.into()),
},
fn bstring_into_string(s: Cow<'_, BStr>) -> Option<String> {
match Vec::from(s.into_owned()).into_string() {
Ok(s) => Some(s),
Err(err) => {
tracing::warn!("Could not convert to string due to illegal UTF8: {err}");
None
}
}
}

fn get_string(repo: &git2::Repository, key: &str) -> Result<Option<String>> {
let config = repo.config()?;
match config.get_string(key) {
Ok(value) => Ok(Some(value)),
Err(err) => match err.code() {
git2::ErrorCode::NotFound => Ok(None),
_ => Err(err.into()),
},
fn osstr_into_string(s: Cow<'_, OsStr>) -> Option<String> {
match Vec::from(gix::path::try_os_str_into_bstr(s).ok()?.into_owned()).into_string() {
Ok(s) => Some(s),
Err(err) => {
tracing::warn!("Could not convert to string due to illegal UTF8: {err}");
None
}
}
}

Expand Down
16 changes: 7 additions & 9 deletions crates/gitbutler-repo/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::Result;
use bstr::ByteVec;
use std::borrow::Cow;

pub struct Config<'a> {
git_repository: &'a git2::Repository,
Expand Down Expand Up @@ -39,15 +41,11 @@ impl Config<'_> {
}

pub fn get_local(&self, key: &str) -> Result<Option<String>> {
let config = self.git_repository.config()?;
match config
.open_level(git2::ConfigLevel::Local)
.and_then(|local| local.get_string(key))
{
Ok(value) => Ok(Some(value)),
Err(e) if e.code() == git2::ErrorCode::NotFound => Ok(None),
Err(e) => Err(e.into()),
}
let repo = gix::open(self.git_repository.path())?;
Ok(repo
.config_snapshot()
.string_filter(key, |meta| meta.source == gix::config::Source::Local)
.and_then(|s| Vec::from(Cow::into_owned(s)).into_string().ok()))
}

fn get_string(&self, key: &str) -> Result<Option<String>> {
Expand Down
Loading
Loading