Skip to content

V3 Uncommitted Files, CLI and Filewatching (part 2) #5945

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

Merged
merged 3 commits into from
Jan 17, 2025
Merged
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
277 changes: 159 additions & 118 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ resolver = "2"
[workspace.dependencies]
bstr = "1.11.1"
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
gix = { git = "https://github.com/GitoxideLabs/gitoxide", rev = "a22f13bec0cdd580ee92390a98d5d522eb29978d", default-features = false, features = [
gix = { git = "https://github.com/GitoxideLabs/gitoxide", branch = "main", default-features = false, features = [
] }
gix-testtools = "0.15.0"
insta = "1.41.1"
git2 = { version = "0.20.0", features = [
"vendored-openssl",
"vendored-libgit2",
Expand Down
1 change: 1 addition & 0 deletions crates/but-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ but-core.workspace = true
but-workspace.workspace = true

clap = { version = "4.5.23", features = ["derive", "env"] }
gix.workspace = true
anyhow.workspace = true
tracing-forest = { version = "0.1.6" }
tracing-subscriber.workspace = true
Expand Down
12 changes: 9 additions & 3 deletions crates/but-cli/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ pub fn project_from_path(path: PathBuf) -> anyhow::Result<Project> {
Project::from_path(&path)
}

pub fn project_repo(path: PathBuf) -> anyhow::Result<gix::Repository> {
let project = project_from_path(path)?;
Ok(gix::open(project.worktree_path())?)
}

fn debug_print(this: impl std::fmt::Debug) -> anyhow::Result<()> {
println!("{:#?}", this);
Ok(())
}

pub mod status {
use crate::command::debug_print;
use crate::command::{debug_print, project_repo};
use std::path::PathBuf;

pub fn doit() -> anyhow::Result<()> {
debug_print("call into but-core")
pub fn doit(current_dir: PathBuf) -> anyhow::Result<()> {
debug_print(but_core::worktree::changes(&project_repo(current_dir)?)?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/but-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> Result<()> {
let _op_span = tracing::info_span!("cli-op").entered();

match args.cmd {
args::Subcommands::Status => command::status::doit(),
args::Subcommands::Status => command::status::doit(args.current_dir),
args::Subcommands::Stacks => command::stacks::list(args.current_dir),
}
}
Expand Down
8 changes: 5 additions & 3 deletions crates/but-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ doctest = false
serde = { workspace = true, features = ["std"] }
bstr.workspace = true
anyhow = "1.0.95"
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
walkdir = "2.5.0"
toml.workspace = true
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel", "serde", "status"] }

[dev-dependencies]
gix-testtools.workspace = true
insta.workspace = true
48 changes: 36 additions & 12 deletions crates/but-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,49 @@
//!
//! ### House-~~Rules~~ Guidance
//!
//! * Try hard to do write all the 'right' tests
//! * **Try hard to do write all the 'right' tests**
//! - Tests should challenge the implementation, try hard to break it.
//! - capture *all* business requirements
//! - Try to avoid doing read-only filesystem fixtures with `tempdir`, instead use `gitbutler-testtools::readonly`.
//! * minimal dependencies
//! - both for the crate and for parameters of functions as well.
//! * **minimal dependencies**
//! - both for the *crate* and for *parameters* of functions as well.
//! - i.e. try to avoid 'God' structures so the function only has access to what it needs to.
//! * The filesystem is `Sync` but we don't have atomic operations
//! * **The filesystem is `Sync` but we don't have atomic operations**
//! - Let's be very careful about changes to the filesystem, must at least be on the level of Git which means `.lock` files instead of direct writes.
//! - If only one part of the application is supposed to change the worktree, let's protect the Application from itself by using `gitbutler::access` just like we do now.
//! * Make it work, make it work right, and if time and profiler permits, make it work fast.
//! * All of the above can and should be scrutinized and is there is no hard rules.
//! * **Implement `Serialize` on utility types to facilitate transfer to the frontend**
//! - But don't make bigger types frontend-specific. If that is needed, create a new type in the frontend-crate that uses frontend types.
//! - `BString` has a `BStringForFrontend` counterpart.
//! - `gix::ObjectId` has a `with = gitbutler_serde::object_id` serialization module.
//! * **Make it work, make it work right, and if time and profiler permits, make it work fast**.
//! * **All of the above can and should be scrutinized and is there is no hard rules.**
//!
//! ### Terminology
//!
//! * **Worktree**
//! - A git worktree, i.e. the checkout of a tree that makes the tree accessible on disk.
//! * **Workspace**
//! - A GitButler concept of the combination of one or more branches into one worktree. This allows
//! multiple branches to be perceived in one worktree, by merging multiple branches together.
//!

use bstr::BString;

/// Functions related to a Git worktree, i.e. the files checked out from a repository.
pub mod worktree {
use std::path::Path;
pub mod worktree;

/// Return a list of items that live underneath `worktree_root` that changed and thus can become part of a commit.
pub fn committable_entries(_worktree_root: &Path) -> anyhow::Result<()> {
todo!()
}
/// An entry in the worktree that changed and thus is eligible to being committed.
///
/// It either lives (or lived) in the in `.git/index`, or in the `worktree`.
///
/// ### Note
///
/// For simplicity, copy-tracking is not representable right now, but `copy: bool` could be added
/// if needed.
#[derive(Debug, Clone)]
pub struct WorktreeChange {
/// The *relative* path in the worktree where the entry can be found.
pub path: BString,
/// The specific information about this change.
pub status: worktree::Status,
}
Loading
Loading