mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-26 22:10:52 +00:00
Add jj debug snapshot
command and use it in trigger
The command only takes a snapshot and avoids other overhead, so it can be used as a target for the watchman trigger that gets installed.
This commit is contained in:
parent
3ebad154ca
commit
3e7ad4d23c
4 changed files with 75 additions and 3 deletions
|
@ -17,6 +17,7 @@ pub mod index;
|
|||
pub mod operation;
|
||||
pub mod reindex;
|
||||
pub mod revset;
|
||||
pub mod snapshot;
|
||||
pub mod template;
|
||||
pub mod tree;
|
||||
pub mod watchman;
|
||||
|
@ -33,6 +34,7 @@ use self::index::{cmd_debug_index, IndexArgs};
|
|||
use self::operation::{cmd_debug_operation, OperationArgs};
|
||||
use self::reindex::{cmd_debug_reindex, ReindexArgs};
|
||||
use self::revset::{cmd_debug_revset, RevsetArgs};
|
||||
use self::snapshot::{cmd_debug_snapshot, SnapshotArgs};
|
||||
use self::template::{cmd_debug_template, TemplateArgs};
|
||||
use self::tree::{cmd_debug_tree, TreeArgs};
|
||||
use self::watchman::{cmd_debug_watchman, WatchmanCommand};
|
||||
|
@ -57,6 +59,7 @@ pub enum DebugCommand {
|
|||
Tree(TreeArgs),
|
||||
#[command(subcommand)]
|
||||
Watchman(WatchmanCommand),
|
||||
Snapshot(SnapshotArgs),
|
||||
}
|
||||
|
||||
pub fn cmd_debug(
|
||||
|
@ -74,6 +77,7 @@ pub fn cmd_debug(
|
|||
DebugCommand::Operation(args) => cmd_debug_operation(ui, command, args),
|
||||
DebugCommand::Tree(args) => cmd_debug_tree(ui, command, args),
|
||||
DebugCommand::Watchman(args) => cmd_debug_watchman(ui, command, args),
|
||||
DebugCommand::Snapshot(args) => cmd_debug_snapshot(ui, command, args),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
33
cli/src/commands/debug/snapshot.rs
Normal file
33
cli/src/commands/debug/snapshot.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Copyright 2024 The Jujutsu Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::fmt::Debug;
|
||||
|
||||
use crate::cli_util::CommandHelper;
|
||||
use crate::command_error::CommandError;
|
||||
use crate::ui::Ui;
|
||||
|
||||
/// Trigger a snapshot in the op log
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
pub struct SnapshotArgs {}
|
||||
|
||||
pub fn cmd_debug_snapshot(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
_args: &SnapshotArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
// workspace helper will snapshot as needed
|
||||
command.workspace_helper(ui)?;
|
||||
Ok(())
|
||||
}
|
|
@ -782,6 +782,42 @@ fn test_workspaces_root() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_snapshot() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
std::fs::write(repo_path.join("file"), "contents").unwrap();
|
||||
test_env.jj_cmd_ok(&repo_path, &["debug", "snapshot"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
@ 2d01fc903f0f test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
|
||||
│ snapshot working copy
|
||||
│ args: jj debug snapshot
|
||||
◉ b51416386f26 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ add workspace 'default'
|
||||
◉ 9a7d829846af test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
test_env.jj_cmd_ok(&repo_path, &["describe", "-m", "initial"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["op", "log"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
@ 53a64275e379 test-username@host.example.com 2001-02-03 04:05:10.000 +07:00 - 2001-02-03 04:05:10.000 +07:00
|
||||
│ describe commit 123ed18e4c4c0d77428df41112bc02ffc83fb935
|
||||
│ args: jj describe -m initial
|
||||
◉ 2d01fc903f0f test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
|
||||
│ snapshot working copy
|
||||
│ args: jj debug snapshot
|
||||
◉ b51416386f26 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ add workspace 'default'
|
||||
◉ 9a7d829846af test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
|
||||
│ initialize repo
|
||||
◉ 000000000000 root()
|
||||
"###);
|
||||
}
|
||||
|
||||
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
||||
let template = r#"
|
||||
separate(" ",
|
||||
|
|
|
@ -283,9 +283,8 @@ pub mod watchman {
|
|||
name: "jj-background-monitor".to_string(),
|
||||
command: vec![
|
||||
"jj".to_string(),
|
||||
"files".to_string(),
|
||||
"-r".to_string(),
|
||||
"root()".to_string(),
|
||||
"debug".to_string(),
|
||||
"snapshot".to_string(),
|
||||
],
|
||||
expression: Some(self.build_exclude_expr()),
|
||||
..Default::default()
|
||||
|
|
Loading…
Reference in a new issue