move legacy credentail helper to gitbutler-repo crate

it's mostly used from there
This commit is contained in:
Kiril Videlov 2024-07-08 13:01:38 +02:00
parent 6f3103d4b5
commit 306ab0bea9
No known key found for this signature in database
GPG Key ID: A4C733025427C471
17 changed files with 82 additions and 44 deletions

4
Cargo.lock generated
View File

@ -2269,7 +2269,11 @@ dependencies = [
"git2",
"gitbutler-core",
"gitbutler-git",
"gitbutler-testsupport",
"resolve-path",
"serde_json",
"tempfile",
"thiserror",
"tokio",
"tracing",
]

View File

@ -1,17 +1,14 @@
use anyhow::Result;
use gitbutler_branchstate::{VirtualBranchesAccess, VirtualBranchesHandle};
use gitbutler_core::{
git::{credentials::Helper, BranchExt},
project_repository::ProjectRepo,
projects::FetchResult,
types::ReferenceName,
git::BranchExt, project_repository::ProjectRepo, projects::FetchResult, types::ReferenceName,
};
use gitbutler_oplog::{
entry::{OperationKind, SnapshotDetails},
oplog::Oplog,
snapshot::Snapshot,
};
use gitbutler_repo::{RepoActions, RepositoryExt};
use gitbutler_repo::{credentials::Helper, RepoActions, RepositoryExt};
use std::{path::Path, sync::Arc};
use tokio::sync::Semaphore;

View File

@ -1,5 +1,6 @@
use gitbutler_branchstate::{VirtualBranchesAccess, VirtualBranchesHandle};
use gitbutler_oplog::snapshot::Snapshot;
use gitbutler_repo::credentials::Helper;
use gitbutler_repo::{LogUntil, RepoActions, RepositoryExt};
use std::borrow::Borrow;
#[cfg(target_family = "unix")]
@ -2159,7 +2160,7 @@ pub fn push(
project_repository: &project_repository::ProjectRepo,
branch_id: BranchId,
with_force: bool,
credentials: &git::credentials::Helper,
credentials: &Helper,
askpass: Option<Option<BranchId>>,
) -> Result<()> {
let vb_state = project_repository.project().virtual_branches();

View File

@ -1,4 +1,3 @@
pub mod credentials;
pub mod diff;
mod reference;

View File

@ -2,7 +2,6 @@ mod suite {
mod projects;
}
mod git;
mod keys;
mod lock;
mod types;

View File

@ -14,3 +14,13 @@ tokio = { workspace = true, features = [ "rt-multi-thread", "rt", "macros" ] }
gitbutler-git.workspace = true
tracing = "0.1.40"
tempfile = "3.10"
thiserror.workspace = true
resolve-path = "0.1.0"
[[test]]
name="repo"
path = "tests/mod.rs"
[dev-dependencies]
gitbutler-testsupport.workspace = true
serde_json = { version = "1.0", features = [ "std", "arbitrary_precision" ] }

View File

@ -3,9 +3,9 @@ use std::{path::PathBuf, vec};
use anyhow::Context;
use crate::{keys, project_repository, projects};
use gitbutler_core::{keys, project_repository, projects};
use super::Url;
use gitbutler_core::git::Url;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SshCredential {
@ -80,7 +80,7 @@ pub enum HelpError {
#[error("no url set for remote")]
NoUrlSet,
#[error("failed to convert url: {0}")]
UrlConvertError(#[from] super::ConvertError),
UrlConvertError(#[from] gitbutler_core::git::ConvertError),
#[error(transparent)]
Git(#[from] git2::Error),
#[error(transparent)]
@ -98,13 +98,13 @@ impl Helper {
.context("failed to parse remote url")?;
// if file, no auth needed.
if remote_url.scheme == super::Scheme::File {
if remote_url.scheme == gitbutler_core::git::Scheme::File {
return Ok(vec![(remote, vec![Credential::Noop])]);
}
match &project_repository.project().preferred_key {
projects::AuthKey::Local { private_key_path } => {
let ssh_remote = if remote_url.scheme == super::Scheme::Ssh {
let ssh_remote = if remote_url.scheme == gitbutler_core::git::Scheme::Ssh {
Ok(remote)
} else {
let ssh_url = remote_url.as_ssh()?;
@ -122,7 +122,7 @@ impl Helper {
)])
}
projects::AuthKey::GitCredentialsHelper => {
let https_remote = if remote_url.scheme == super::Scheme::Https {
let https_remote = if remote_url.scheme == gitbutler_core::git::Scheme::Https {
Ok(remote)
} else {
let url = remote_url.as_https()?;
@ -143,7 +143,7 @@ impl Helper {
fn https_flow(
project_repository: &project_repository::ProjectRepo,
remote_url: &super::Url,
remote_url: &gitbutler_core::git::Url,
) -> Result<Vec<HttpsCredential>, HelpError> {
let mut flow = vec![];

View File

@ -8,3 +8,5 @@ pub use commands::RepoCommands;
mod repository_ext;
pub use repository_ext::RepositoryExt;
pub mod credentials;

View File

@ -13,20 +13,16 @@ use gitbutler_core::{
use gitbutler_core::project_repository::{Config, ProjectRepo};
use crate::RepositoryExt;
use crate::{credentials::Helper, RepositoryExt};
pub trait RepoActions {
fn fetch(
&self,
remote_name: &str,
credentials: &git::credentials::Helper,
askpass: Option<String>,
) -> Result<()>;
fn fetch(&self, remote_name: &str, credentials: &Helper, askpass: Option<String>)
-> Result<()>;
fn push(
&self,
head: &git2::Oid,
branch: &git::RemoteRefname,
with_force: bool,
credentials: &git::credentials::Helper,
credentials: &Helper,
refspec: Option<String>,
askpass_broker: Option<Option<BranchId>>,
) -> Result<()>;
@ -46,7 +42,7 @@ pub trait RepoActions {
fn add_branch_reference(&self, branch: &Branch) -> Result<()>;
fn git_test_push(
&self,
credentials: &git::credentials::Helper,
credentials: &Helper,
remote_name: &str,
branch_name: &str,
askpass: Option<Option<BranchId>>,
@ -56,7 +52,7 @@ pub trait RepoActions {
impl RepoActions for ProjectRepo {
fn git_test_push(
&self,
credentials: &git::credentials::Helper,
credentials: &Helper,
remote_name: &str,
branch_name: &str,
askpass: Option<Option<BranchId>>,
@ -254,7 +250,7 @@ impl RepoActions for ProjectRepo {
head: &git2::Oid,
branch: &git::RemoteRefname,
with_force: bool,
credentials: &git::credentials::Helper,
credentials: &Helper,
refspec: Option<String>,
askpass_broker: Option<Option<BranchId>>,
) -> Result<()> {
@ -357,7 +353,7 @@ impl RepoActions for ProjectRepo {
fn fetch(
&self,
remote_name: &str,
credentials: &git::credentials::Helper,
credentials: &Helper,
askpass: Option<String>,
) -> Result<()> {
let refspec = format!("+refs/heads/*:refs/remotes/{}/*", remote_name);

View File

@ -1,10 +1,8 @@
use std::path::PathBuf;
use std::str;
use gitbutler_core::{
git::credentials::{Credential, Helper, SshCredential},
project_repository, projects, users,
};
use gitbutler_core::{project_repository, projects, users};
use gitbutler_repo::credentials::{Credential, Helper, SshCredential};
use gitbutler_testsupport::{temp_dir, test_repository};
@ -22,9 +20,9 @@ impl TestCase<'_> {
gitbutler_testsupport::secrets::setup_blackhole_store();
let users = users::Controller::from_path(local_app_data.path());
let user: users::User = serde_json::from_str(if self.with_github_login {
include_str!("../../tests/fixtures/users/with-github.v1")
include_str!("../tests/fixtures/users/with-github.v1")
} else {
include_str!("../../tests/fixtures/users/login-only.v1")
include_str!("../tests/fixtures/users/login-only.v1")
})
.expect("valid v1 sample user");
users.set_user(&user).unwrap();

View File

@ -0,0 +1,15 @@
{
"id": 13612,
"name": "Sebastian Thiel",
"given_name": null,
"family_name": null,
"email": "sebastian.thiel@icloud.com",
"picture": "https://avatars.githubusercontent.com/u/63622?v=4",
"locale": null,
"created_at": "2024-03-26T13:17:05Z",
"updated_at": "2024-06-24T15:21:45Z",
"access_token": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"role": null,
"github_access_token": null,
"github_username": null
}

View File

@ -0,0 +1,15 @@
{
"id": 13612,
"name": "Sebastian Thiel",
"given_name": null,
"family_name": null,
"email": "sebastian.thiel@icloud.com",
"picture": "https://avatars.githubusercontent.com/u/63622?v=4",
"locale": null,
"created_at": "2024-03-26T13:17:05Z",
"updated_at": "2024-06-24T15:21:45Z",
"access_token": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
"role": null,
"github_access_token": "gho_AAAAAAAAAAAAABBBBBBBBBBBBBBBCCCCCCCC",
"github_username": null
}

View File

@ -5,7 +5,7 @@ use gitbutler_core::{
projects::{self, ProjectId},
virtual_branches::BranchId,
};
use gitbutler_repo::{RepoActions, RepositoryExt};
use gitbutler_repo::{credentials::Helper, RepoActions, RepositoryExt};
#[derive(Clone)]
pub struct App {
@ -36,7 +36,7 @@ impl App {
project_id: ProjectId,
remote_name: &str,
branch_name: &str,
credentials: &git::credentials::Helper,
credentials: &Helper,
askpass: Option<Option<BranchId>>,
) -> Result<()> {
let project = self.projects.get(project_id)?;
@ -48,7 +48,7 @@ impl App {
&self,
project_id: ProjectId,
remote_name: &str,
credentials: &git::credentials::Helper,
credentials: &Helper,
askpass: Option<String>,
) -> Result<()> {
let project = self.projects.get(project_id)?;

View File

@ -1,4 +1,5 @@
use gitbutler_core::{git, projects::ProjectId};
use gitbutler_repo::credentials::Helper;
use tauri::Manager;
use tracing::instrument;
@ -25,7 +26,7 @@ pub async fn git_test_push(
branch_name: &str,
) -> Result<(), Error> {
let app = handle.state::<app::App>();
let helper = handle.state::<gitbutler_core::git::credentials::Helper>();
let helper = handle.state::<Helper>();
Ok(app.git_test_push(
project_id,
remote_name,
@ -45,7 +46,7 @@ pub async fn git_test_fetch(
action: Option<String>,
) -> Result<(), Error> {
let app = handle.state::<app::App>();
let helper = handle.state::<gitbutler_core::git::credentials::Helper>();
let helper = handle.state::<Helper>();
Ok(app.git_test_fetch(
project_id,
remote_name,

View File

@ -13,7 +13,8 @@
clippy::too_many_lines
)]
use gitbutler_core::{assets, git, storage};
use gitbutler_core::{assets, storage};
use gitbutler_repo::credentials::Helper;
use gitbutler_tauri::{
app, askpass, commands, config, github, keys, logs, menu, projects, remotes, repo, secret,
undo, users, virtual_branches, watcher, zip,
@ -132,7 +133,7 @@ fn main() {
let keys_controller = gitbutler_core::keys::Controller::new(keys_storage_controller.clone());
app_handle.manage(keys_controller.clone());
let git_credentials_controller = git::credentials::Helper::default();
let git_credentials_controller = Helper::default();
app_handle.manage(git_credentials_controller.clone());
app_handle.manage(gitbutler_branch::controller::Controller::default());

View File

@ -5,7 +5,7 @@ use std::{
};
use gitbutler_core::project_repository;
use gitbutler_repo::RepositoryExt;
use gitbutler_repo::{credentials::Helper, RepositoryExt};
use tempfile::{tempdir, TempDir};
use crate::{init_opts, init_opts_bare, VAR_NO_CLEANUP};
@ -92,7 +92,7 @@ impl Suite {
pub struct Case {
pub project: gitbutler_core::projects::Project,
pub project_repository: gitbutler_core::project_repository::ProjectRepo,
pub credentials: gitbutler_core::git::credentials::Helper,
pub credentials: Helper,
/// The directory containing the `project_repository`
project_tmp: Option<TempDir>,
}
@ -113,7 +113,7 @@ impl Case {
fn new(project: gitbutler_core::projects::Project, project_tmp: TempDir) -> Case {
let project_repository = gitbutler_core::project_repository::ProjectRepo::open(&project)
.expect("failed to create project repository");
let credentials = gitbutler_core::git::credentials::Helper::default();
let credentials = Helper::default();
Case {
project,
project_repository,
@ -129,7 +129,7 @@ impl Case {
.expect("failed to get project");
let project_repository = gitbutler_core::project_repository::ProjectRepo::open(&project)
.expect("failed to create project repository");
let credentials = gitbutler_core::git::credentials::Helper::default();
let credentials = Helper::default();
Self {
credentials,
project_repository,