Skip to content

Commit

Permalink
Do not panic if hg command is not available
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D32066385

fbshipit-source-id: 3ff1acca165a9e77f1f306dde132882f417e3469
  • Loading branch information
alunyov authored and facebook-github-bot committed Nov 1, 2021
1 parent 3eb1de3 commit d336460
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions compiler/crates/graphql-watchman/src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub struct WatchmanFileSourceResult {
pub struct WatchmanFileSourceSubscription {
resolved_root: ResolvedRoot,
subscription: WatchmanSubscription<WatchmanFile>,
base_revision: String,
base_revision: Option<String>,
}

impl WatchmanFileSourceSubscription {
Expand All @@ -50,7 +50,7 @@ impl WatchmanFileSourceSubscription {
Self {
resolved_root,
subscription,
base_revision: get_base_revision(None),
base_revision: get_base_hg_revision(None),
}
}

Expand Down Expand Up @@ -88,7 +88,7 @@ impl WatchmanFileSourceSubscription {
} else {
None
};
let current_base_revision = get_base_revision(current_commit);
let current_base_revision = get_base_hg_revision(current_commit);
if current_base_revision != self.base_revision {
self.base_revision = current_base_revision;
return Ok(WatchmanFileSourceSubscriptionNextChange::SourceControlUpdate);
Expand All @@ -113,7 +113,7 @@ impl WatchmanFileSourceSubscription {
/// `master` and current commit hash or `.`
///
/// TODO: Make this dynamic on the default branch name.
fn get_base_revision(commit_hash: Option<String>) -> String {
fn get_base_hg_revision(commit_hash: Option<String>) -> Option<String> {
let output = Command::new("hg")
.arg("log".to_string())
.arg("-r".to_string())
Expand All @@ -123,14 +123,11 @@ fn get_base_revision(commit_hash: Option<String>) -> String {
))
.arg("-T={node}")
.output()
.expect("Expect `hg` command getting base revision.");
.ok()?;

if output.stdout.is_empty() {
panic!(
"Failed to get base revision hash:\n {:?}",
String::from_utf8_lossy(&output.stderr)
);
return None;
}

String::from_utf8_lossy(&output.stdout).to_string()
Some(String::from_utf8_lossy(&output.stdout).to_string())
}

0 comments on commit d336460

Please sign in to comment.