Skip to content

Commit

Permalink
New jj debug watchman status command
Browse files Browse the repository at this point in the history
This command checks not only whether Watchman works, but also whether
it's enabled in the config. Also, the output is easier to understand
than that of the other `jj debug watchman` commands.

It would be nice if `jj debug watchman` called `jj debug watchman
status`, but it's not trivial in `clap` to have a default subcommand.
  • Loading branch information
ilyagr committed Apr 11, 2024
1 parent d9a4660 commit 0d5e8b3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
evaluates to true if the operation was a snapshot created by a non-mutating
command (e.g. `jj log`).

* You can check whether Watchman fsmonitor is enabled or installed with the new
`jj debug watchman status` command.

### Fixed bugs

* Revsets now support `\`-escapes in string literal.
Expand Down
27 changes: 27 additions & 0 deletions cli/src/commands/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ pub struct DebugTreeArgs {

#[derive(Subcommand, Clone, Debug)]
pub enum DebugWatchmanSubcommand {
/// Check whether `watchman` is enabled and whether it's correctly installed
Status,
QueryClock,
QueryChangedFiles,
ResetClock,
Expand Down Expand Up @@ -367,6 +369,31 @@ fn cmd_debug_watchman(
let mut workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo().clone();
match subcommand {
DebugWatchmanSubcommand::Status => {
// TODO(ilyagr): It would be nice to add colors here
match command.settings().fsmonitor_kind()? {
jj_lib::fsmonitor::FsmonitorKind::Watchman => {
writeln!(ui.stdout(), "Watchman is enabled via `core.fsmonitor`.")?
}
jj_lib::fsmonitor::FsmonitorKind::None => writeln!(
ui.stdout(),
"Watchman is disabled. Set `core.fsmonitor=\"watchman\"` to \
enable.\nAttempting to contact the `watchman` CLI regardless..."
)?,
other_fsmonitor => {
return Err(user_error(format!(
"This command does not support the currently enabled filesystem monitor: \
{other_fsmonitor:?}."
)))
}
};
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let _ = wc.query_watchman()?;
writeln!(
ui.stdout(),
"The watchman server seems to be installed and working correctly."
)?;
}
DebugWatchmanSubcommand::QueryClock => {
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let (clock, _changed_files) = wc.query_watchman()?;
Expand Down
3 changes: 2 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,8 @@ To configure the Watchman filesystem monitor, set
`core.fsmonitor = "watchman"`. Ensure that you have [installed the Watchman
executable on your system](https://facebook.github.io/watchman/docs/install).

Debugging commands are available under `jj debug watchman`.
You can check whether Watchman is enabled and whether it is installed correctly
using `jj debug watchman status`.

## Ways to specify `jj` config: details

Expand Down
2 changes: 1 addition & 1 deletion lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::path::PathBuf;
use std::str::FromStr;

/// The recognized kinds of filesystem monitors.
#[derive(Eq, PartialEq)]
#[derive(Eq, PartialEq, Clone, Debug)]
pub enum FsmonitorKind {
/// The Watchman filesystem monitor (<https://facebook.github.io/watchman/>).
Watchman,
Expand Down

0 comments on commit 0d5e8b3

Please sign in to comment.