Skip to content
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
63 changes: 20 additions & 43 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ members = [
# Mostly supporting legacy code.
# In big parts replaced by other crates.
"crates/but-fs", # 📄filesystem utilities 👉we should be using `but-db` instead.
"crates/but-status", # 📄 One function that will be put elsewhere soon to remove this crate.
"crates/but-oxidize", # 📄Utilities to help translate between `git2` and `gix`. 👉Shouldn't be needed once `git2` is gone.

##
Expand Down Expand Up @@ -161,7 +160,6 @@ but-meta = { path = "crates/but-meta" }
but-rules = { path = "crates/but-rules" }
but-action = { path = "crates/but-action" }
but-bot = { path = "crates/but-bot" }
but-status = { path = "crates/but-status" }
but-tools = { path = "crates/but-tools" }
but-api = { path = "crates/but-api" }
but-api-macros = { path = "crates/but-api-macros" }
Expand Down Expand Up @@ -191,7 +189,6 @@ but-llm = { path = "crates/but-llm" }
gitbutler-git = { path = "crates/gitbutler-git" }
gitbutler-watcher = { path = "crates/gitbutler-watcher" }
gitbutler-filemonitor = { path = "crates/gitbutler-filemonitor" }
gitbutler-testsupport = { path = "crates/gitbutler-testsupport" }
gitbutler-branch-actions = { path = "crates/gitbutler-branch-actions" }
gitbutler-oplog = { path = "crates/gitbutler-oplog" }
gitbutler-repo = { path = "crates/gitbutler-repo" }
Expand Down
3 changes: 3 additions & 0 deletions crates/but-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ pub mod cmd;
pub mod settings;
pub use settings::git::types::GitConfigSettings;

/// Raw status helpers.
pub mod status;

pub mod snapshot;

/// Utilities to deal with git worktrees.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// Gets the status of a given repository.
//! Status helpers built on top of `gix`.

/// Return raw status items for `repo`.
pub fn get_status(repo: &gix::Repository) -> anyhow::Result<Vec<gix::status::Item>> {
use gix::{dir::walk::EmissionMode, status::tree_index::TrackRenames};

Expand Down
1 change: 1 addition & 0 deletions crates/but-ctx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ gitbutler-project = { workspace = true, optional = true }

tracing.workspace = true
anyhow.workspace = true
but-error.workspace = true
gix.workspace = true
git2.workspace = true

Expand Down
29 changes: 25 additions & 4 deletions crates/but-ctx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use but_core::{
RepositoryExt,
sync::{RepoExclusive, RepoExclusiveGuard, RepoShared, RepoSharedGuard},
};
use but_error::Code;
use but_settings::AppSettings;
use tracing::instrument;

Expand Down Expand Up @@ -460,10 +461,18 @@ impl Context {
.with_repo(repo))
}

/// Use `git2_repo` instead of the default repository that would be opened on first query.
pub fn with_git2_repo(mut self, git2_repo: git2::Repository) -> Self {
self.git2_repo.assign(git2_repo);
self
/// Eagerly open the legacy `git2` repository, preserving repo-ownership error tagging used
/// by activation entrypoints before any database work begins.
pub fn initialize_git2_repo(&mut self) -> anyhow::Result<()> {
{
let existing = self.git2_repo.get_opt();
if existing.is_some() {
return Ok(());
}
}
let repo = open_git2_repo_for_activation(&self.gitdir)?;
self.git2_repo.assign(repo);
Ok(())
}

/// Use `repo` instead of the default repository that would be opened on first query.
Expand Down Expand Up @@ -1080,6 +1089,18 @@ fn new_ondemand_git2_repo(gitdir: PathBuf) -> OnDemand<git2::Repository> {
})
}

fn open_git2_repo_for_activation(gitdir: &Path) -> anyhow::Result<git2::Repository> {
git2::Repository::open(gitdir).map_err(|err| {
let code = err.code();
let err = anyhow::Error::from(err);
if code == git2::ErrorCode::Owner {
err.context(Code::RepoOwnership)
} else {
err
}
})
}

#[instrument(level = "trace")]
fn new_ondemand_db(project_data_dir: PathBuf) -> OnDemand<but_db::DbHandle> {
OnDemand::new(move || but_db::DbHandle::new_in_directory(project_data_dir.clone()))
Expand Down
1 change: 0 additions & 1 deletion crates/but-napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ but-ctx.workspace = true
but-error.workspace = true
but-path.workspace = true
but-settings.workspace = true
git2.workspace = true
gitbutler-watcher.workspace = true
napi = { version = "3", features = ["serde-json", "async"] }
napi-derive = "3"
Expand Down
11 changes: 1 addition & 10 deletions crates/but-napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,8 @@ fn app_settings_sync() -> anyhow::Result<AppSettingsWithDiskSync> {
fn open_prepared_context(project_id: &ProjectHandleOrLegacyProjectId) -> anyhow::Result<Context> {
// We don't get a validated legacy object here, but that's fine as we're only opening repos/watchers.
let mut ctx: Context = project_id.clone().try_into()?;
let repo = git2::Repository::open(&ctx.gitdir).map_err(|err| {
let code = err.code();
let err = anyhow::Error::from(err);
if code == git2::ErrorCode::Owner {
err.context(but_error::Code::RepoOwnership)
} else {
err
}
})?;
// Keep this before any database usage on `ctx`.
ctx = ctx.with_git2_repo(repo);
ctx.initialize_git2_repo()?;
but_api::legacy::projects::prepare_project_for_activation(&mut ctx)?;
Ok(ctx)
}
Expand Down
17 changes: 0 additions & 17 deletions crates/but-status/Cargo.toml

This file was deleted.

42 changes: 40 additions & 2 deletions crates/but-testsupport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ test = false
doctest = false

[features]
## Provide legacy GitButler test helpers that are still being migrated into `but-*` crates.
legacy = [
"dep:but-ctx",
"dep:but-fs",
"dep:but-oxidize",
"dep:but-project-handle",
"dep:but-settings",
"dep:but-workspace",
"dep:gitbutler-branch-actions",
"dep:gitbutler-project",
"dep:gitbutler-reference",
"dep:gitbutler-repo",
"dep:gitbutler-stack",
"dep:gitbutler-url",
"dep:gitbutler-user",
"dep:git2",
"dep:keyring",
"dep:serde_json",
"dep:tempfile",
"dep:uuid",
]
## Make `snapbox` utilities available, generally useful for CLI testing.
snapbox = ["dep:snapbox"]
## Provide a writable sandbox for testing of higher-level functions, with everything *but* the `Context`, useful even for plumbing.
Expand All @@ -29,20 +50,37 @@ sandbox-but-api = [

[dependencies]
but-graph.workspace = true
but-core.workspace = true
but-core = { workspace = true, features = ["legacy"] }
but-db.workspace = true
but-settings = { workspace = true, optional = true }
but-fs = { workspace = true, optional = true, features = ["legacy"] }
but-oxidize = { workspace = true, optional = true }
but-project-handle = { workspace = true, optional = true }
but-workspace = { workspace = true, optional = true, features = ["legacy"] }
but-meta = { workspace = true, optional = true, features = ["legacy"] }
but-ctx = { workspace = true, optional = true }
but-ctx = { workspace = true, optional = true, features = ["legacy"] }

shell-words = { workspace = true, optional = true }

gitbutler-branch-actions = { workspace = true, optional = true }
gitbutler-project = { workspace = true, optional = true }
gitbutler-reference = { workspace = true, optional = true }
gitbutler-repo = { workspace = true, optional = true }
gitbutler-stack = { workspace = true, optional = true }
gitbutler-url = { workspace = true, optional = true }
gitbutler-user = { workspace = true, optional = true }

gix-testtools.workspace = true
gix.workspace = true
anyhow.workspace = true
termtree = "0.5.1"
regex = { workspace = true }
snapbox = { workspace = true, optional = true, features = ["regex"] }
git2 = { workspace = true, optional = true }
keyring = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
tempfile = { workspace = true, optional = true }
uuid = { workspace = true, optional = true }

[dev-dependencies]

Expand Down
Loading
Loading