Skip to content

Commit

Permalink
fsmonitor: query watchman with right valid json
Browse files Browse the repository at this point in the history
In rare circumstances where the current git index does not carry the
last_update_token, the fsmonitor v2 hook will be invoked with an
empty string which would caused the final rendered json to be invalid.

  ["query", "/path/to/my/git/repository/", {
          "since": ,
          "fields": ["name"],
          "expression": ["not", ["dirname", ".git"]]
  }]

Which will left user with the following error message

  > git status
  failed to parse command from stdin: line 2, column 13, position 67: unexpected token near ','
  Watchman: command returned no output.
  Falling back to scanning...

Hide the "since" field in json query when "last_update_token" is empty.

Co-authored-by: Ævar Arnfjörð Bjarmason <[email protected]>
Signed-off-by: Son Luong Ngoc <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
2 people authored and gitster committed Jun 7, 2022
1 parent e54793a commit 134047b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions templates/hooks--fsmonitor-watchman.sample
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ sub watchman_query {
# recency index to select candidate nodes and "fields" to limit the
# output to file names only. Then we're using the "expression" term to
# further constrain the results.
my $last_update_line = "";
if (substr($last_update_token, 0, 1) eq "c") {
$last_update_token = "\"$last_update_token\"";
$last_update_line = qq[\n"since": $last_update_token,];
}
my $query = <<" END";
["query", "$git_work_tree", {
"since": $last_update_token,
["query", "$git_work_tree", {$last_update_line
"fields": ["name"],
"expression": ["not", ["dirname", ".git"]]
}]
Expand Down

0 comments on commit 134047b

Please sign in to comment.