Skip to content

Commit d736cc7

Browse files
committed
Add a new crate with a sketch of the V3 staging API.
1 parent 796c3d0 commit d736cc7

File tree

9 files changed

+179
-37
lines changed

9 files changed

+179
-37
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
11
[workspace]
22
members = [
3-
"crates/gitbutler-tauri",
4-
"crates/gitbutler-git",
5-
"crates/gitbutler-watcher",
6-
"crates/gitbutler-watcher/vendor/debouncer",
7-
"crates/gitbutler-testsupport",
8-
"crates/gitbutler-cli",
9-
"crates/gitbutler-branch-actions",
10-
"crates/gitbutler-sync",
11-
"crates/gitbutler-oplog",
12-
"crates/gitbutler-repo",
13-
"crates/gitbutler-repo-actions",
14-
"crates/gitbutler-command-context",
15-
"crates/gitbutler-feedback",
16-
"crates/gitbutler-config",
17-
"crates/gitbutler-project",
18-
"crates/gitbutler-user",
19-
"crates/gitbutler-branch",
20-
"crates/gitbutler-reference",
21-
"crates/gitbutler-error",
22-
"crates/gitbutler-serde",
23-
"crates/gitbutler-secret",
24-
"crates/gitbutler-id",
25-
"crates/gitbutler-storage",
26-
"crates/gitbutler-fs",
27-
"crates/gitbutler-time",
28-
"crates/gitbutler-commit",
29-
"crates/gitbutler-tagged-string",
30-
"crates/gitbutler-url",
31-
"crates/gitbutler-diff",
32-
"crates/gitbutler-operating-modes",
33-
"crates/gitbutler-edit-mode",
34-
"crates/gitbutler-cherry-pick",
35-
"crates/gitbutler-oxidize",
36-
"crates/gitbutler-stack",
37-
"crates/gitbutler-hunk-dependency",
38-
"crates/gitbutler-settings",
39-
"crates/gitbutler-workspace",
3+
"crates/gitbutler-*",
4+
"crates/but-*"
405
]
416
resolver = "2"
427

@@ -96,6 +61,7 @@ gitbutler-forge = { path = "crates/gitbutler-forge" }
9661
gitbutler-hunk-dependency = { path = "crates/gitbutler-hunk-dependency" }
9762
gitbutler-settings = { path = "crates/gitbutler-settings" }
9863
gitbutler-workspace = { path = "crates/gitbutler-workspace" }
64+
but-core = { path = "crates/but-core" }
9965

10066
[profile.release]
10167
codegen-units = 1 # Compile crates one after another so the compiler can optimize better

crates/but-cli/Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
name = "but-cli"
3+
version = "0.0.0"
4+
edition = "2021"
5+
authors = ["GitButler <gitbutler@gitbutler.com>"]
6+
publish = false
7+
rust-version = "1.74"
8+
9+
[[bin]]
10+
name = "but-cli"
11+
path = "src/main.rs"
12+
doctest = false
13+
14+
[dependencies]
15+
but-core.workspace = true
16+
17+
clap = { version = "4.5.23", features = ["derive", "env"] }
18+
anyhow = "1.0.95"
19+
tracing-forest = { version = "0.1.6" }
20+
tracing-subscriber.workspace = true
21+
tracing.workspace = true

crates/but-cli/src/args.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::path::PathBuf;
2+
3+
#[derive(Debug, clap::Parser)]
4+
#[clap(name = "gitbutler-cli", about = "A CLI for GitButler", version = option_env!("GIX_VERSION"))]
5+
pub struct Args {
6+
/// Enable tracing for debug and performance information printed to stderr.
7+
#[clap(short = 'd', long)]
8+
pub trace: bool,
9+
/// Run as if gitbutler-cli was started in PATH instead of the current working directory.
10+
#[clap(short = 'C', long, default_value = ".", value_name = "PATH")]
11+
pub current_dir: PathBuf,
12+
13+
#[clap(subcommand)]
14+
pub cmd: Subcommands,
15+
}
16+
17+
#[derive(Debug, clap::Subcommand)]
18+
pub enum Subcommands {
19+
/// Update the local workspace against an updated remote or target branch.
20+
Status,
21+
}
22+
23+
#[cfg(test)]
24+
mod tests {
25+
use super::*;
26+
27+
#[test]
28+
fn clap() {
29+
use clap::CommandFactory;
30+
Args::command().debug_assert();
31+
}
32+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn debug_print(this: impl std::fmt::Debug) -> anyhow::Result<()> {
2+
println!("{:#?}", this);
3+
Ok(())
4+
}
5+
6+
pub mod status {
7+
use crate::command::debug_print;
8+
9+
pub fn doit() -> anyhow::Result<()> {
10+
debug_print("call into but-core")
11+
}
12+
}

crates/but-cli/src/main.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! A debug-CLI for making `but`-crates functionality available in real-world repositories.
2+
use anyhow::Result;
3+
4+
mod args;
5+
use args::Args;
6+
7+
mod command;
8+
9+
fn main() -> Result<()> {
10+
let args: Args = clap::Parser::parse();
11+
12+
if args.trace {
13+
trace::init()?;
14+
}
15+
let _op_span = tracing::info_span!("cli-op").entered();
16+
17+
match args.cmd {
18+
args::Subcommands::Status => command::status::doit(),
19+
}
20+
}
21+
22+
mod trace {
23+
use tracing::metadata::LevelFilter;
24+
use tracing_subscriber::layer::SubscriberExt;
25+
use tracing_subscriber::util::SubscriberInitExt;
26+
use tracing_subscriber::Layer;
27+
28+
pub fn init() -> anyhow::Result<()> {
29+
tracing_subscriber::registry()
30+
.with(
31+
tracing_forest::ForestLayer::from(
32+
tracing_forest::printer::PrettyPrinter::new().writer(std::io::stderr),
33+
)
34+
.with_filter(LevelFilter::DEBUG),
35+
)
36+
.init();
37+
Ok(())
38+
}
39+
}

crates/but-core/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "but-core"
3+
version = "0.0.0"
4+
edition = "2021"
5+
authors = ["GitButler <gitbutler@gitbutler.com>"]
6+
publish = false
7+
8+
[lib]
9+
doctest = false
10+
11+
[dependencies]
12+
serde = { workspace = true, features = ["std"] }
13+
bstr.workspace = true
14+
anyhow = "1.0.95"
15+
gix = { workspace = true, features = ["dirwalk", "credentials", "parallel"] }
16+
walkdir = "2.5.0"
17+
toml.workspace = true

crates/but-core/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![deny(missing_docs, rust_2018_idioms)]
2+
//! The basic primitives that GitButler is built around.
3+
//!
4+
//! It also is a catch-all for code until it's worth putting it into its own crate.
5+
//!
6+
//! ### House-~~Rules~~ Guidance
7+
//!
8+
//! * Try hard to do write all the 'right' tests
9+
//! - Tests should challenge the implementation, try hard to break it.
10+
//! - capture *all* business requirements
11+
//! - 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.
14+
//! - 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
16+
//! - 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.
17+
//! - 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.
20+
21+
/// Functions related to a Git worktree, i.e. the files checked out from a repository.
22+
pub mod worktree {
23+
use std::path::Path;
24+
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+
}
29+
}

crates/but-core/tests/core/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[test]
2+
fn itworks() {}

0 commit comments

Comments
 (0)