Skip to content

Commit 4314abc

Browse files
authored
Merge pull request #11371 from Byron/next2
Single-branch support for `but branch apply`
2 parents b5bf904 + fb02d02 commit 4314abc

File tree

95 files changed

+1173
-1276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1173
-1276
lines changed

.github/workflows/push.yaml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,24 @@ jobs:
6464
needs: changes
6565
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
6666
runs-on: ubuntu-latest
67-
container:
68-
image: ghcr.io/gitbutlerapp/ci-base-image:latest
6967
env:
7068
CARGO_TERM_COLOR: always
7169
steps:
7270
- uses: actions/checkout@v6
7371
with:
7472
persist-credentials: false
73+
- name: Rust Cache
74+
uses: Swatinem/rust-cache@v2.8.1
75+
with:
76+
shared-key: ts-def-gen
77+
save-if: ${{ github.ref == 'refs/heads/master' }}
78+
# Node is needed for the formatting of typescript files.
7579
- uses: ./.github/actions/init-env-node
76-
- run: pnpm generate-ts-definitions
80+
- run: |
81+
sudo apt install libdbus-1-dev pkg-config
82+
./scripts/generate-ts-definitions-from-rust.sh
7783
7884
lint-node:
79-
needs: generate-ts-definitions
8085
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
8186
runs-on: ubuntu-latest
8287
steps:
@@ -87,7 +92,6 @@ jobs:
8792
- run: pnpm lint
8893

8994
check-node:
90-
needs: generate-ts-definitions
9195
if: ${{ needs.changes.outputs.node == 'true' || needs.changes.outputs.rust == 'true' }}
9296
runs-on: ubuntu-latest
9397
steps:
@@ -98,7 +102,6 @@ jobs:
98102
- run: pnpm check
99103

100104
unittest-node:
101-
needs: generate-ts-definitions
102105
if: ${{ needs.changes.outputs.node == 'true' }}
103106
runs-on: ubuntu-latest
104107
steps:
@@ -180,10 +183,12 @@ jobs:
180183
sudo apt update
181184
sudo apt install -y libdbus-1-dev pkg-config
182185
- run: |
183-
cargo test --workspace --exclude gitbutler-tauri
186+
cargo test --workspace --exclude gitbutler-tauri --exclude but-server
184187
env:
185188
GITBUTLER_TESTS_NO_CLEANUP: '1'
186189
name: cargo test
190+
# It's intentional to use 'name equals run-script' so it's easy to re-run locally on failure.
191+
- run: cargo test -p but --no-default-features
187192

188193
rust-test-tauri:
189194
needs: changes

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ but-settings = { path = "crates/but-settings" }
3737
but-oxidize = { path = "crates/but-oxidize" }
3838
but-fs = { path = "crates/but-fs" }
3939
but-forge = { path = "crates/but-forge" }
40+
but-oplog = { path = "crates/but-oplog" }
4041

4142
gitbutler-git = { path = "crates/gitbutler-git" }
4243
gitbutler-watcher = { path = "crates/gitbutler-watcher" }

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,4 @@ at the [DEVELOPMENT.md](DEVELOPMENT.md) file.
137137
<a href="https://github.com/gitbutlerapp/gitbutler/graphs/contributors">
138138
<img src="https://contrib.rocks/image?repo=gitbutlerapp/gitbutler" />
139139
</a>
140+
hi

crates/but-api/Cargo.toml

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ tauri = ["dep:tauri"]
2222
path-bytes = ["dep:bstr"]
2323
## Make legacy functionality available.
2424
legacy = [
25+
"but-ctx/legacy",
26+
"but-workspace/legacy",
2527
"dep:gitbutler-user",
2628
"dep:gitbutler-project",
2729
"dep:gitbutler-branch",
2830
"dep:gitbutler-branch-actions",
2931
"dep:gitbutler-commit",
30-
"dep:but-ctx",
3132
"dep:gitbutler-reference",
3233
"dep:gitbutler-stack",
3334
"dep:gitbutler-repo",
@@ -36,35 +37,51 @@ legacy = [
3637
"dep:gitbutler-operating-modes",
3738
"dep:gitbutler-sync",
3839
"dep:gitbutler-oplog",
40+
"dep:but-action",
41+
"dep:but-hunk-assignment",
42+
"dep:but-hunk-dependency",
43+
"dep:but-claude",
44+
"dep:but-rules",
45+
"dep:but-gerrit",
46+
"dep:but-worktrees",
47+
"dep:but-cherry-apply",
3948
]
4049

4150

4251
[dependencies]
43-
but-settings.workspace = true
44-
but-github = { workspace = true, features = ["legacy"] }
45-
but-secret.workspace = true
46-
but-workspace = { workspace = true, features = ["legacy"] }
47-
but-worktrees.workspace = true
48-
but-core.workspace = true
49-
but-gerrit.workspace = true
50-
but-hunk-assignment.workspace = true
51-
but-action.workspace = true
52-
but-api-macros.workspace = true
53-
but-rebase.workspace = true
5452
but-serde.workspace = true
55-
but-graph.workspace = true
56-
but-meta = { workspace = true, features = ["legacy"] }
57-
but-claude.workspace = true
58-
but-cherry-apply.workspace = true
59-
but-hunk-dependency.workspace = true
6053
but-path.workspace = true
61-
but-forge-storage.workspace = true
54+
but-api-macros.workspace = true
55+
but-oxidize.workspace = true
6256
but-error.workspace = true
57+
but-core.workspace = true
58+
but-graph.workspace = true
59+
but-ctx.workspace = true
60+
but-workspace.workspace = true
61+
but-settings.workspace = true
62+
but-secret.workspace = true
63+
but-rebase.workspace = true
6364
but-db.workspace = true
64-
but-rules.workspace = true
65-
but-oxidize.workspace = true
6665
but-forge.workspace = true
67-
but-ctx = {workspace = true, optional = true}
66+
but-forge-storage.workspace = true
67+
# needs `gitbutler_user::User`, which can probably be ported over.
68+
but-github = { workspace = true, features = ["legacy"] }
69+
# 'legacy' is needed while we only have `virtual-branches.toml`
70+
but-meta = { workspace = true, features = ["legacy"] }
71+
# 'legacy' is needed while this is only a sketch of what the oplog could be.
72+
# For single-branch testing, we also want the oplog and just take it as it is.
73+
but-oplog = { workspace = true, features = ["legacy"] }
74+
75+
# What follows is *basically* newly written crates that are built on top of legacy,
76+
# so need some refactoring/rethinking to become usable.
77+
but-cherry-apply = { workspace = true, optional = true }
78+
but-action = { workspace = true, optional = true }
79+
but-hunk-assignment = { workspace = true, optional = true }
80+
but-hunk-dependency = { workspace = true, optional = true }
81+
but-claude = { workspace = true, optional = true }
82+
but-rules = { workspace = true, optional = true }
83+
but-gerrit = { workspace = true, optional = true }
84+
but-worktrees = { workspace = true, optional = true }
6885

6986
gitbutler-user = {workspace = true, optional = true}
7087
gitbutler-project = {workspace = true, optional = true}

crates/but-api/src/branch.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
use but_core::worktree::checkout::UncommitedWorktreeChanges;
2+
use but_oplog::legacy::{OperationKind, SnapshotDetails, Trailer};
3+
use but_workspace::branch::OnWorkspaceMergeConflict;
4+
use but_workspace::branch::apply::{WorkspaceMerge, WorkspaceReferenceNaming};
5+
6+
/// Just like [apply()], but without updating the oplog.
7+
pub fn apply_only(
8+
ctx: &but_ctx::Context,
9+
existing_branch: &gix::refs::FullNameRef,
10+
) -> anyhow::Result<but_workspace::branch::apply::Outcome<'static>> {
11+
let mut guard = ctx.exclusive_worktree_access();
12+
let (repo, mut meta, graph) =
13+
ctx.graph_and_meta_mut_and_repo_from_head(guard.write_permission())?;
14+
let ws = graph.to_workspace()?;
15+
let out = but_workspace::branch::apply(
16+
existing_branch,
17+
&ws,
18+
&repo,
19+
&mut meta,
20+
// NOTE: Options can later be passed as parameter, or we have a separate function for that.
21+
// Showing them off here while leaving defaults.
22+
but_workspace::branch::apply::Options {
23+
workspace_merge: WorkspaceMerge::default(),
24+
on_workspace_conflict: OnWorkspaceMergeConflict::default(),
25+
workspace_reference_naming: WorkspaceReferenceNaming::default(),
26+
uncommitted_changes: UncommitedWorktreeChanges::default(),
27+
order: None,
28+
new_stack_id: None,
29+
},
30+
)?
31+
.into_owned();
32+
Ok(out)
33+
}
34+
35+
/// Apply `existing_branch` to the workspace in the repository that `ctx` refers to, or create the workspace with default name.
36+
// TODO: generate this with an improved `api_cmd_tauri` macro.
37+
pub fn apply(
38+
ctx: &but_ctx::Context,
39+
existing_branch: &gix::refs::FullNameRef,
40+
) -> anyhow::Result<but_workspace::branch::apply::Outcome<'static>> {
41+
// NOTE: since this is optional by nature, the same would be true if snapshotting/undo would be disabled via `ctx` app settings, for instance.
42+
let maybe_oplog_entry = but_oplog::UnmaterializedOplogSnapshot::from_details(
43+
ctx,
44+
SnapshotDetails::new(OperationKind::CreateBranch).with_trailers(vec![Trailer {
45+
key: "name".into(),
46+
value: existing_branch.to_string(),
47+
}]),
48+
)
49+
.ok();
50+
51+
let res = apply_only(ctx, existing_branch);
52+
if let Some(snapshot) = maybe_oplog_entry.filter(|_| res.is_ok()) {
53+
snapshot.commit(ctx).ok();
54+
}
55+
res
56+
}

crates/but-api/src/github.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//! In place of commands.rs
1+
// TODO: everything should be fully documented.
2+
#![allow(missing_docs)]
23
use anyhow::Result;
34
use but_api_macros::api_cmd_tauri;
45
use but_github::{AuthStatusResponse, AuthenticatedUser, Verification};

crates/but-api/src/json.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! JSON types and utilities to produce decent JSON from API types.
12
pub use error::{Error, ToJsonError, UnmarkedError};
23
use gix::refs::Target;
34
use schemars::{self, JsonSchema};
@@ -195,7 +196,9 @@ mod error {
195196
}
196197
}
197198

199+
/// A utility to convert any `Result<T, impl std::error::Error>` into a [JSON-Error](Error).
198200
pub trait ToJsonError<T> {
201+
/// Convert this instance into a Result<T, [JSON-Error](Error)>.
199202
fn to_json_error(self) -> Result<T, Error>;
200203
}
201204

crates/but-api/src/legacy/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(missing_docs)]
12
//! Legacy data structures and functionality tied to `gitbutler-*` crates.
23
//!
34
pub mod askpass;

crates/but-api/src/legacy/workspace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub fn amend_commit_from_worktree_changes(
327327
let app_settings = AppSettings::load_from_default_path_creating()?;
328328
let outcome = but_workspace::legacy::commit_engine::create_commit_and_update_refs_with_project(
329329
&repo,
330-
&project,
330+
&project.gb_dir(),
331331
Some(stack_id),
332332
commit_engine::Destination::AmendCommit {
333333
commit_id: commit_id.into(),
@@ -620,7 +620,7 @@ pub fn stash_into_branch(
620620

621621
let outcome = but_workspace::legacy::commit_engine::create_commit_and_update_refs_with_project(
622622
&repo,
623-
&ctx.legacy_project,
623+
&ctx.project_data_dir(),
624624
Some(stack.id),
625625
commit_engine::Destination::NewCommit {
626626
parent_commit_id: Some(parent_commit_id),

0 commit comments

Comments
 (0)