Skip to content

Commit 61e5cc4

Browse files
committed
Add a way to get a list of changed items in the worktree.
1 parent c8a064d commit 61e5cc4

File tree

20 files changed

+2042
-25
lines changed

20 files changed

+2042
-25
lines changed

Cargo.lock

Lines changed: 43 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ bstr = "1.11.1"
77
# Add the `tracing` or `tracing-detail` features to see more of gitoxide in the logs. Useful to see which programs it invokes.
88
gix = { git = "https://github.com/GitoxideLabs/gitoxide", branch = "main", default-features = false, features = [
99
] }
10+
gix-testtools = "0.15.0"
11+
insta = "1.41.1"
1012
git2 = { version = "0.20.0", features = [
1113
"vendored-openssl",
1214
"vendored-libgit2",

crates/but-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ but-core.workspace = true
1717
but-workspace.workspace = true
1818

1919
clap = { version = "4.5.23", features = ["derive", "env"] }
20+
gix.workspace = true
2021
anyhow.workspace = true
2122
tracing-forest = { version = "0.1.6" }
2223
tracing-subscriber.workspace = true

crates/but-cli/src/command/mod.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,22 @@ pub fn project_from_path(path: PathBuf) -> anyhow::Result<Project> {
55
Project::from_path(&path)
66
}
77

8+
pub fn project_repo(path: PathBuf) -> anyhow::Result<gix::Repository> {
9+
let project = project_from_path(path)?;
10+
Ok(gix::open(project.worktree_path())?)
11+
}
12+
813
fn debug_print(this: impl std::fmt::Debug) -> anyhow::Result<()> {
914
println!("{:#?}", this);
1015
Ok(())
1116
}
1217

1318
pub mod status {
14-
use crate::command::debug_print;
19+
use crate::command::{debug_print, project_repo};
20+
use std::path::PathBuf;
1521

16-
pub fn doit() -> anyhow::Result<()> {
17-
debug_print("call into but-core")
22+
pub fn doit(current_dir: PathBuf) -> anyhow::Result<()> {
23+
debug_print(but_core::worktree::changes(&project_repo(current_dir)?)?)
1824
}
1925
}
2026

crates/but-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() -> Result<()> {
1515
let _op_span = tracing::info_span!("cli-op").entered();
1616

1717
match args.cmd {
18-
args::Subcommands::Status => command::status::doit(),
18+
args::Subcommands::Status => command::status::doit(args.current_dir),
1919
args::Subcommands::Stacks => command::stacks::list(args.current_dir),
2020
}
2121
}

crates/but-core/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ doctest = false
1212
serde = { workspace = true, features = ["std"] }
1313
bstr.workspace = true
1414
anyhow = "1.0.95"
15-
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
16-
walkdir = "2.5.0"
17-
toml.workspace = true
15+
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel", "serde", "status"] }
16+
17+
[dev-dependencies]
18+
gix-testtools.workspace = true
19+
insta.workspace = true

crates/but-core/src/lib.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,49 @@
55
//!
66
//! ### House-~~Rules~~ Guidance
77
//!
8-
//! * Try hard to do write all the 'right' tests
8+
//! * **Try hard to do write all the 'right' tests**
99
//! - Tests should challenge the implementation, try hard to break it.
1010
//! - capture *all* business requirements
1111
//! - Try to avoid doing read-only filesystem fixtures with `tempdir`, instead use `gitbutler-testtools::readonly`.
12-
//! * minimal dependencies
13-
//! - both for the crate and for parameters of functions as well.
12+
//! * **minimal dependencies**
13+
//! - both for the *crate* and for *parameters* of functions as well.
1414
//! - i.e. try to avoid 'God' structures so the function only has access to what it needs to.
15-
//! * The filesystem is `Sync` but we don't have atomic operations
15+
//! * **The filesystem is `Sync` but we don't have atomic operations**
1616
//! - 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.
1717
//! - 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.
18-
//! * Make it work, make it work right, and if time and profiler permits, make it work fast.
19-
//! * All of the above can and should be scrutinized and is there is no hard rules.
18+
//! * **Implement `Serialize` on utility types to facilitate transfer to the frontend**
19+
//! - But don't make bigger types frontend-specific. If that is needed, create a new type in the frontend-crate that uses frontend types.
20+
//! - `BString` has a `BStringForFrontend` counterpart.
21+
//! - `gix::ObjectId` has a `with = gitbutler_serde::object_id` serialization module.
22+
//! * **Make it work, make it work right, and if time and profiler permits, make it work fast**.
23+
//! * **All of the above can and should be scrutinized and is there is no hard rules.**
24+
//!
25+
//! ### Terminology
26+
//!
27+
//! * **Worktree**
28+
//! - A git worktree, i.e. the checkout of a tree that makes the tree accessible on disk.
29+
//! * **Workspace**
30+
//! - A GitButler concept of the combination of one or more branches into one worktree. This allows
31+
//! multiple branches to be perceived in one worktree, by merging multiple branches together.
32+
//!
33+
34+
use bstr::BString;
2035

2136
/// Functions related to a Git worktree, i.e. the files checked out from a repository.
22-
pub mod worktree {
23-
use std::path::Path;
37+
pub mod worktree;
2438

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

0 commit comments

Comments
 (0)