Skip to content

Commit 134047b

Browse files
sluongngavar
authored andcommitted
fsmonitor: query watchman with right valid json
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]>
1 parent e54793a commit 134047b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

templates/hooks--fsmonitor-watchman.sample

+3-2
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ sub watchman_query {
8686
# recency index to select candidate nodes and "fields" to limit the
8787
# output to file names only. Then we're using the "expression" term to
8888
# further constrain the results.
89+
my $last_update_line = "";
8990
if (substr($last_update_token, 0, 1) eq "c") {
9091
$last_update_token = "\"$last_update_token\"";
92+
$last_update_line = qq[\n"since": $last_update_token,];
9193
}
9294
my $query = <<" END";
93-
["query", "$git_work_tree", {
94-
"since": $last_update_token,
95+
["query", "$git_work_tree", {$last_update_line
9596
"fields": ["name"],
9697
"expression": ["not", ["dirname", ".git"]]
9798
}]

0 commit comments

Comments
 (0)