From 6ee547f070975392b8da6cf86aa6315c9d286da5 Mon Sep 17 00:00:00 2001 From: estib Date: Tue, 16 Jun 2026 09:28:51 +0200 Subject: [PATCH 1/2] but: Don't switch to the workspace on setup --- crates/but/src/command/legacy/setup.rs | 67 +------------ crates/but/tests/but/command/setup.rs | 130 +++++++------------------ crates/but/tests/but/journey.rs | 27 +---- 3 files changed, 43 insertions(+), 181 deletions(-) diff --git a/crates/but/src/command/legacy/setup.rs b/crates/but/src/command/legacy/setup.rs index 8099686bb34..b8c531ac0d2 100644 --- a/crates/but/src/command/legacy/setup.rs +++ b/crates/but/src/command/legacy/setup.rs @@ -181,16 +181,6 @@ pub(crate) fn repo( let t = theme::get(); let mut target_info: Option = None; - // what branch is head() pointing to? - let pre_head_name = { - let repo = ctx.repo.get()?; - let pre_head = repo.head()?; - pre_head - .referent_name() - .map(|n| n.shorten().to_string()) - .unwrap_or_default() - }; - // find or setup the gitbutler project if let Some(out) = out.for_human() { writeln!( @@ -334,9 +324,10 @@ pub(crate) fn repo( }; drop(repo); - but_api::legacy::virtual_branches::set_base_branch_with_perm( + let target_ref: gix::refs::FullName = format!("refs/remotes/{name}").try_into()?; + but_api::branch::set_default_target_with_perm( ctx, - name.clone(), + target_ref.as_ref(), Some(remote_name.clone()), perm, )?; @@ -393,58 +384,6 @@ pub(crate) fn repo( } } - let head_name = { - let repo = ctx.repo.get()?; - let head = repo.head()?; - head.referent_name() - .map(|n| n.shorten().to_owned()) - .unwrap_or_default() - }; - - // switch to gitbutler/workspace if not already there - if !head_name.starts_with(b"gitbutler/") { - but_api::legacy::virtual_branches::switch_back_to_workspace_with_perm(ctx, perm)?; - } - - // Install managed hooks to prevent accidental git commits - if let Ok(repo) = ctx.repo.get() - && let Err(e) = gitbutler_repo::managed_hooks::install_managed_hooks(&repo) - && let Some(out) = out.for_human() - { - writeln!( - out, - " {}", - t.attention.paint(format!( - "Warning: Failed to install GitButler managed hooks: {e}" - )) - )?; - } - - // if we switched - tell the user what this is all about - if pre_head_name != "gitbutler/workspace" - && let Some(out) = out.for_human() - { - writeln!( - out, - "{}", - t.attention.paint(format!( - r#" -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout {pre_head_name}`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch -"# - )) - )?; - } - // Display splash screen for human output if let Some(out) = out.for_human() { display_splash_screen(out)?; diff --git a/crates/but/tests/but/command/setup.rs b/crates/but/tests/but/command/setup.rs index cf7060a9482..1f94d94ea6f 100644 --- a/crates/but/tests/but/command/setup.rs +++ b/crates/but/tests/but/command/setup.rs @@ -17,6 +17,28 @@ Error: No git repository found - run `but setup --init` to initialize a new repo Ok(()) } +fn assert_metadata_only_setup( + env: &Sandbox, + expected_branch: &str, + expected_target_ref: &str, +) -> anyhow::Result<()> { + let output = env.invoke_git("branch --show-current"); + assert_eq!(output, expected_branch); + + env.invoke_git_fails( + "show-ref --verify refs/heads/gitbutler/workspace", + "setup should not create gitbutler/workspace", + ); + + let output = env.invoke_git("config --get gitbutler.project.targetRef"); + assert_eq!(output, expected_target_ref); + + let output = env.invoke_git("config --get gitbutler.project.targetCommitId"); + assert!(!output.is_empty(), "setup should write targetCommitId"); + + Ok(()) +} + #[test] fn no_remote_creates_gb_local() -> anyhow::Result<()> { let env = Sandbox::open_with_default_settings("repo-no-remote")?; @@ -46,19 +68,6 @@ Target branch: gb-local/main Remote: gb-local -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -87,6 +96,8 @@ Learn more at https://docs.gitbutler.com/cli-overview let output = env.invoke_git("symbolic-ref refs/remotes/gb-local/HEAD"); assert_eq!(output, "refs/remotes/gb-local/main"); + assert_metadata_only_setup(&env, "main", "refs/remotes/gb-local/main")?; + Ok(()) } @@ -115,19 +126,6 @@ Target branch: gb-local/development Remote: gb-local -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout development`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -152,6 +150,8 @@ Learn more at https://docs.gitbutler.com/cli-overview let output = env.invoke_git("symbolic-ref refs/remotes/gb-local/HEAD"); assert_eq!(output, "refs/remotes/gb-local/development"); + assert_metadata_only_setup(&env, "development", "refs/remotes/gb-local/development")?; + Ok(()) } @@ -189,19 +189,6 @@ Target branch: origin/main Remote: origin -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -222,6 +209,8 @@ Learn more at https://docs.gitbutler.com/cli-overview "#]]); + assert_metadata_only_setup(&env, "main", "refs/remotes/origin/main")?; + Ok(()) } @@ -255,19 +244,6 @@ Target branch: origin/main Remote: origin -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -288,6 +264,8 @@ Learn more at https://docs.gitbutler.com/cli-overview "#]]); + assert_metadata_only_setup(&env, "main", "refs/remotes/origin/main")?; + Ok(()) } @@ -517,19 +495,6 @@ Target branch: gb-local/main Remote: gb-local -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -554,12 +519,13 @@ Learn more at https://docs.gitbutler.com/cli-overview let output = env.invoke_git("rev-parse --git-dir"); assert!(!output.is_empty()); - // Verify initial commit was created (may have additional workspace commit) + // Verify initial commit was created without an additional workspace commit. let commit_count: u32 = env.invoke_git("rev-list --count HEAD").parse()?; - assert!( - commit_count >= 1, - "Expected at least 1 commit, found {commit_count}" + assert_eq!( + commit_count, 1, + "setup should not create a workspace commit" ); + assert_metadata_only_setup(&env, "main", "refs/remotes/gb-local/main")?; Ok(()) } @@ -618,19 +584,6 @@ Target branch: gb-local/main Remote: gb-local -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -680,19 +633,6 @@ Target branch: gb-local/main Remote: gb-local -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ diff --git a/crates/but/tests/but/journey.rs b/crates/but/tests/but/journey.rs index 0cfa2a97c02..af2cefa450a 100644 --- a/crates/but/tests/but/journey.rs +++ b/crates/but/tests/but/journey.rs @@ -62,19 +62,6 @@ Target branch: gb-local/main Remote: gb-local -Setting up your project for GitButler tooling. Some things to note: - -- Switching you to a special `gitbutler/workspace` branch to enable parallel branches -- Installing Git hooks to help manage commits on the workspace branch - -To undo these changes and return to normal Git mode, either: - - - Directly checkout a branch (`git checkout main`) - - Run `but teardown` - -More info: https://docs.gitbutler.com/workspace-branch - - ██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ ████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ @@ -143,16 +130,12 @@ Learn more at https://docs.gitbutler.com/cli-overview env.but("status") .assert() - .success() - .stdout_eq(str![[r#" -╭┄zz [unassigned changes] (no changes) -┊ -┴ 6f66116 (common base) 2000-01-02 Initial empty commit - -Hint: run `but branch new` to create a new branch to work on + .failure() + .stdout_eq(str![""]) + .stderr_eq(str![[r#" +Error: Setup required: Not currently on a gitbutler/* branch. - run `but setup` to configure the project -"#]]) - .stderr_eq(str![""]); +"#]]); Ok(()) } From 6c1fb08c9175ef10261dbf6b37fa2c1d52005ef3 Mon Sep 17 00:00:00 2001 From: estib Date: Tue, 16 Jun 2026 12:02:26 +0200 Subject: [PATCH 2/2] WIP --- crates/but/src/args/mod.rs | 9 ++- crates/but/src/command/legacy/setup.rs | 69 +++++++++++++---- crates/but/src/command/legacy/status/mod.rs | 2 +- crates/but/src/command/legacy/teardown.rs | 6 +- crates/but/src/lib.rs | 16 ++-- crates/but/src/setup.rs | 4 +- crates/but/tests/but/command/setup.rs | 82 ++++++++++++++++++--- crates/but/tests/but/command/teardown.rs | 10 +-- crates/but/tests/but/journey.rs | 21 ++++-- crates/gitbutler-repo/src/managed_hooks.rs | 2 +- 10 files changed, 177 insertions(+), 44 deletions(-) diff --git a/crates/but/src/args/mod.rs b/crates/but/src/args/mod.rs index 2eea12d4e77..04f0ae1637f 100644 --- a/crates/but/src/args/mod.rs +++ b/crates/but/src/args/mod.rs @@ -781,9 +781,9 @@ pub enum Subcommands { /// /// This command will: /// - Add the repository to the global GitButler project registry - /// - Switch to the gitbutler/workspace branch (if not already on it) /// - Set up a default target branch (the remote's HEAD) /// - Add a gb-local remote if no push remote exists + /// - Optionally enter the temporary legacy gitbutler/workspace mode with --workspace /// /// If you have an existing Git repository and want to start using GitButler /// with it, you can run this command to set up the necessary configuration @@ -807,6 +807,13 @@ pub enum Subcommands { #[clap(long)] #[cfg_attr(feature = "raw-clap-docs", clap(verbatim_doc_comment))] init: bool, + /// Enter the temporary legacy gitbutler/workspace mode after setup. + /// + /// This is a compatibility escape hatch for commands that still require managed + /// workspace mode. The long-term direction is that commands should work without it. + #[clap(long)] + #[clap(verbatim_doc_comment)] + workspace: bool, }, /// Exit GitButler mode and return to normal Git workflow. diff --git a/crates/but/src/command/legacy/setup.rs b/crates/but/src/command/legacy/setup.rs index b8c531ac0d2..23471b984b6 100644 --- a/crates/but/src/command/legacy/setup.rs +++ b/crates/but/src/command/legacy/setup.rs @@ -43,8 +43,8 @@ struct TargetInfo { newly_set: bool, } -/// Display a colorful splash screen with GitButler branding and helpful commands -fn display_splash_screen(out: &mut dyn std::fmt::Write) -> anyhow::Result<()> { +/// Display a colorful splash screen with GitButler branding and helpful commands. +fn display_splash_screen(out: &mut dyn std::fmt::Write, workspace: bool) -> anyhow::Result<()> { let t = theme::get(); writeln!(out)?; writeln!( @@ -92,12 +92,21 @@ fn display_splash_screen(out: &mut dyn std::fmt::Write) -> anyhow::Result<()> { t.command_suggestion.paint("$ but push"), t.hint.paint("Push all branches") )?; - writeln!( - out, - "{:<45} {}", - t.command_suggestion.paint("$ but teardown"), - t.hint.paint("Return to normal Git mode") - )?; + if workspace { + writeln!( + out, + "{:<45} {}", + t.command_suggestion.paint("$ but teardown"), + t.hint.paint("Return to normal Git mode") + )?; + } else { + writeln!( + out, + "{:<45} {}", + t.command_suggestion.paint("$ but setup --workspace"), + t.hint.paint("Enter temporary legacy workspace mode") + )?; + } writeln!(out)?; writeln!( @@ -176,6 +185,7 @@ pub(crate) fn repo( ctx: &mut Context, repo_path: &Path, out: &mut OutputChannel, + workspace: bool, perm: &mut RepoExclusive, ) -> anyhow::Result<()> { let t = theme::get(); @@ -384,9 +394,45 @@ pub(crate) fn repo( } } + if workspace { + if let Some(out) = out.for_human() { + writeln!(out)?; + writeln!( + out, + "{}", + t.hint + .paint("→ Entering temporary legacy managed workspace mode") + )?; + } + + but_api::legacy::virtual_branches::switch_back_to_workspace_with_perm(ctx, perm)?; + + if let Some(out) = out.for_human() { + writeln!( + out, + " {}", + t.success.paint("✓ Switched to gitbutler/workspace") + )?; + writeln!( + out, + " {}", + t.success.paint("✓ Installed managed workspace hooks") + )?; + writeln!(out)?; + writeln!( + out, + "{}", + t.attention.paint( + "This is a temporary compatibility mode. The long-term direction is that no command should require it." + ) + )?; + writeln!(out)?; + } + } + // Display splash screen for human output if let Some(out) = out.for_human() { - display_splash_screen(out)?; + display_splash_screen(out, workspace)?; } // Output JSON if requested @@ -410,19 +456,14 @@ pub(crate) fn repo( /// - if the project is registered in GitButler /// - if there is a remote /// - if there is a default target branch set -/// - if we're on a gitbutler/* branch pub fn check_project_setup(ctx: &Context, perm: &RepoShared) -> anyhow::Result { let (repo, ws, _) = ctx.workspace_and_db_with_perm(perm)?; - // check if we're on a gitbutler/* branch let head = repo.head()?; let head_name = head .referent_name() .map(|n| n.shorten().to_owned()) .unwrap_or_default(); - if !head_name.starts_with(b"gitbutler/") { - anyhow::bail!("Not currently on a gitbutler/* branch."); - } // When on gitbutler/edit, the project was already set up when entering edit mode. // The workspace graph built from gitbutler/edit doesn't expose the target ref or diff --git a/crates/but/src/command/legacy/status/mod.rs b/crates/but/src/command/legacy/status/mod.rs index 25f430f75f0..77f3fbaa83d 100644 --- a/crates/but/src/command/legacy/status/mod.rs +++ b/crates/but/src/command/legacy/status/mod.rs @@ -639,7 +639,7 @@ fn print_hint( let has_uncommitted_files = !status_ctx.worktree_changes.is_empty(); let hint_text = if not_on_workspace { - "Hint: run `but setup` to switch back to GitButler managed mode." + "Hint: run `but setup --workspace` to switch back to GitButler managed mode." } else if !status_ctx.has_branches { "Hint: run `but branch new` to create a new branch to work on" } else if has_uncommitted_files { diff --git a/crates/but/src/command/legacy/teardown.rs b/crates/but/src/command/legacy/teardown.rs index dcf82ad638a..3c5d52c5143 100644 --- a/crates/but/src/command/legacy/teardown.rs +++ b/crates/but/src/command/legacy/teardown.rs @@ -242,7 +242,11 @@ pub(crate) fn teardown( )?; writeln!(out)?; writeln!(out, "{}", t.info.paint("To return to GitButler mode, run:"))?; - writeln!(out, " {}", t.command_suggestion.paint("but setup"))?; + writeln!( + out, + " {}", + t.command_suggestion.paint("but setup --workspace") + )?; writeln!(out)?; } diff --git a/crates/but/src/lib.rs b/crates/but/src/lib.rs index 967ed5653f9..adf1d0b95b1 100644 --- a/crates/but/src/lib.rs +++ b/crates/but/src/lib.rs @@ -1190,7 +1190,7 @@ async fn match_subcommand( .map_err(CliError::from) } #[cfg(feature = "legacy")] - Subcommands::Setup { init } => { + Subcommands::Setup { init, workspace } => { let repo = match but_api::legacy::projects::add_project_best_effort(args.current_dir.clone())? { @@ -1206,10 +1206,16 @@ async fn match_subcommand( }; let mut ctx = but_ctx::Context::from_repo(repo)?; let mut guard = ctx.exclusive_worktree_access(); - command::legacy::setup::repo(&mut ctx, &args.current_dir, out, guard.write_permission()) - .context("Failed to set up GitButler project.") - .emit_metrics(metrics_ctx) - .map_err(CliError::from) + command::legacy::setup::repo( + &mut ctx, + &args.current_dir, + out, + workspace, + guard.write_permission(), + ) + .context("Failed to set up GitButler project.") + .emit_metrics(metrics_ctx) + .map_err(CliError::from) } #[cfg(feature = "legacy")] Subcommands::Teardown { checkout_to } => { diff --git a/crates/but/src/setup.rs b/crates/but/src/setup.rs index ae50bad9be0..0c805ef2aea 100644 --- a/crates/but/src/setup.rs +++ b/crates/but/src/setup.rs @@ -128,6 +128,7 @@ pub fn init_ctx( &mut ctx, &args.current_dir, out, + false, guard.write_permission(), )?; // Retry finding the project after setup @@ -160,6 +161,7 @@ pub fn init_ctx( &mut ctx, &args.current_dir, out, + false, guard.write_permission(), )?; // Re-find and re-check the project after setup @@ -424,7 +426,7 @@ fn prompt_for_setup(out: &mut OutputChannel, message: &str) -> SetupPromptResult if let Some(mut inout) = out.prepare_for_terminal_input() { _ = writeln!( progress, - "In order to manage projects with GitButler, we need to do some changes:\n\n - Switch you to a special `gitbutler/workspace` branch to enable parallel branches\n - Install Git hooks to help manage the tooling\n\nYou can go back to normal git workflows at any time by either:\n\n - Running `but teardown`\n - Manually checking out a normal branch with `git checkout `\n", + "In order to manage projects with GitButler, we need to configure this repository:\n\n - Add it to the GitButler project registry\n - Configure a default target branch\n\nTo enter the temporary legacy managed workspace mode later, run:\n\n - `but setup --workspace`\n", ); if let Ok(Confirm::Yes) = diff --git a/crates/but/tests/but/command/setup.rs b/crates/but/tests/but/command/setup.rs index 1f94d94ea6f..e2248f9cbf0 100644 --- a/crates/but/tests/but/command/setup.rs +++ b/crates/but/tests/but/command/setup.rs @@ -81,7 +81,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -139,7 +139,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -202,7 +202,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -257,7 +257,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -269,6 +269,70 @@ Learn more at https://docs.gitbutler.com/cli-overview Ok(()) } +#[test] +fn workspace_flag_enters_legacy_managed_workspace() -> anyhow::Result<()> { + let env = Sandbox::open_with_default_settings("repo-with-remote-and-head")?; + + env.but("setup --workspace") + .assert() + .success() + .stderr_eq(snapbox::str![]) + .stdout_eq(snapbox::str![[r#" +Setting up GitButler project... + +→ Adding repository to GitButler project registry + ✓ Repository already in project registry + +→ Configuring default target branch + ✓ Using existing push remote: origin + ✓ Set default target to: origin/main + +GitButler project setup complete! +Target branch: origin/main +Remote: origin + + +→ Entering temporary legacy managed workspace mode + ✓ Switched to gitbutler/workspace + ✓ Installed managed workspace hooks + +This is a temporary compatibility mode. The long-term direction is that no command should require it. + + + +██▄ ▄██ ▀██▀▀█▄ ▀██▀ ▀██▀ █▀▀██▀▀█ +████▄ ▄████ ██ ██ ██ ██ ▀ ██ ▀ +████████████ ██▀▀█▄ ██ ██ ██ +████▀ ▀████ ██ ██ ██ ██ ██ +██▀ ▀██ ▄██▄▄█▀ ▀█▄▄▄█▀ ▄▄██▄▄ + +The command-line interface for GitButler ⋈ + +$ but branch new Create a new branch +$ but status View workspace status +$ but commit -m Commit changes to current branch +$ but push Push all branches +$ but teardown Return to normal Git mode + +Learn more at https://docs.gitbutler.com/cli-overview + + +"#]]); + + let output = env.invoke_git("branch --show-current"); + assert_eq!(output, "gitbutler/workspace"); + env.invoke_git("show-ref --verify refs/heads/gitbutler/workspace"); + + let pre_commit_hook = env.projects_root().join(".git/hooks/pre-commit"); + let hook = std::fs::read_to_string(&pre_commit_hook)?; + assert!( + hook.contains("GITBUTLER_MANAGED_HOOK_V1"), + "setup --workspace should install managed workspace hooks" + ); + + Ok(()) +} + #[test] fn already_setup() -> anyhow::Result<()> { let env = Sandbox::open_with_default_settings("repo-already-setup")?; @@ -306,7 +370,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -508,7 +572,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -597,7 +661,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -646,7 +710,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -690,7 +754,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview diff --git a/crates/but/tests/but/command/teardown.rs b/crates/but/tests/but/command/teardown.rs index 2c66837932a..9130ec5be92 100644 --- a/crates/but/tests/but/command/teardown.rs +++ b/crates/but/tests/but/command/teardown.rs @@ -37,7 +37,7 @@ Exiting GitButler mode... You are now on branch: A To return to GitButler mode, run: - but setup + but setup --workspace "#]]); @@ -89,7 +89,7 @@ Exiting GitButler mode... You are now on branch: A To return to GitButler mode, run: - but setup + but setup --workspace "#]]); @@ -159,7 +159,7 @@ Attempting to fix workspace stacks... You are now on branch: A To return to GitButler mode, run: - but setup + but setup --workspace "#]]); @@ -240,7 +240,7 @@ Attempting to fix workspace stacks... You are now on branch: A To return to GitButler mode, run: - but setup + but setup --workspace "#]]); @@ -322,7 +322,7 @@ Attempting to fix workspace stacks... You are now on branch: A To return to GitButler mode, run: - but setup + but setup --workspace "#]]); diff --git a/crates/but/tests/but/journey.rs b/crates/but/tests/but/journey.rs index af2cefa450a..76b137162b2 100644 --- a/crates/but/tests/but/journey.rs +++ b/crates/but/tests/but/journey.rs @@ -75,7 +75,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -120,7 +120,7 @@ $ but branch new Create a new branch $ but status View workspace status $ but commit -m Commit changes to current branch $ but push Push all branches -$ but teardown Return to normal Git mode +$ but setup --workspace Enter temporary legacy workspace mode Learn more at https://docs.gitbutler.com/cli-overview @@ -130,10 +130,19 @@ Learn more at https://docs.gitbutler.com/cli-overview env.but("status") .assert() - .failure() - .stdout_eq(str![""]) - .stderr_eq(str![[r#" -Error: Setup required: Not currently on a gitbutler/* branch. - run `but setup` to configure the project + .success() + .stderr_eq(str![""]) + .stdout_eq(str![[r#" +╭┄zz [unassigned changes] (no changes) +┊ +┊╭┄ma [main] (no commits) +├╯ +┊ +┴ [..] (common base) 2000-01-02 Initial empty commit +⚠️ You are in plain Git mode, directly on a branch. Some commands may be unavailable. ⚠️ +⚠️ More info: https://github.com/gitbutlerapp/gitbutler/issues/11866 ⚠️ + +Hint: run `but setup --workspace` to switch back to GitButler managed mode. "#]]); diff --git a/crates/gitbutler-repo/src/managed_hooks.rs b/crates/gitbutler-repo/src/managed_hooks.rs index 75cfd7bb837..c4f38948206 100644 --- a/crates/gitbutler-repo/src/managed_hooks.rs +++ b/crates/gitbutler-repo/src/managed_hooks.rs @@ -121,7 +121,7 @@ if echo "$PREV_BRANCH" | grep -q "gitbutler/workspace"; then fi echo "" - echo "To return to GitButler mode, run: but setup" + echo "To return to GitButler mode, run: but setup --workspace" echo "" exit 0 fi