Skip to content

Commit

Permalink
feat: Test for existing watchman trigger before installing one
Browse files Browse the repository at this point in the history
  • Loading branch information
fowles committed Jun 12, 2024
1 parent 20c12dc commit 7cd52b1
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/src/fsmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ pub mod watchman {
};

if kind == super::FsmonitorKind::WatchmanTrigger {
monitor.register_trigger().await?;
if !monitor.is_trigger_registered().await? {
monitor.register_trigger().await?;
}
}
Ok(monitor)
}
Expand Down Expand Up @@ -245,6 +247,20 @@ pub mod watchman {
}
}

/// Return whether or not a trigger has been registered already.
#[instrument(skip(self))]
async fn is_trigger_registered(&self) -> Result<bool, Error> {
info!("Checking for an existing Watchman trigger...");
Ok(self
.client
.list_triggers(&self.resolved_root)
.await
.map_err(Error::WatchmanTriggerError)?
.triggers
.iter()
.any(|t| t.name == "jj-background-monitor"))
}

/// Register trigger for changed files.
#[instrument(skip(self))]
async fn register_trigger(&self) -> Result<(), Error> {
Expand All @@ -255,7 +271,7 @@ pub mod watchman {
.register_trigger(
&self.resolved_root,
TriggerRequest {
name: format!("jj-trigger-{:?}", self.resolved_root.path()),
name: "jj-background-monitor".to_string(),
command: vec!["jj".to_string(), "st".to_string()],
expression: Some(self.build_exclude_expr()),
..Default::default()
Expand Down

0 comments on commit 7cd52b1

Please sign in to comment.