Issue 3482: gerrit version 2.9 - ssh query fails to honor time or timezone with after operator
Status:  New
Owner: ----
Reported by srer...@gmail.com, Jul 16, 2015
Affected Version: 2.9

When I use the command line through ssh, I get valid data only if I use a date with the "after" operator.  If I add a time like "2015-07-16 00:00:00", then I get a row count of 0.  And if I add a timezone like "2015-07-16 00:00:00 -0700", then I get this message returned: 
fatal: "-0700" is not a valid option

If I use the web interface and just use the same 'after:"2015-07-16 00:00:00 -0700"' operator in the web search box, then everything works correctly.

Here's the command that works:
A. ssh -n -p <port> <git server> gerrit query after:"2015-07-16"
Here's the commands that don't work:
B. ssh -n -p <port> <git server> gerrit query after:"2015-07-16 00:00:00"
C. ssh -n -p <port> <git server> gerrit query after:"2015-07-16 00:00:00 -0700"
D. ssh -n -p <port> <git server> gerrit query after:"2015-07-16 07:00:00"

The expected output between A and B should be the same.  Right?  C should change from B because there would be 7 hours difference.  But C and D should get the same information.  Right?

I expect that the output from ssh would match the output on the web search.  The web search seems to work just fine.  But the ssh query does not.

I've tried replacing the double quotes with single quotes above and that does not work either.  I tried following the latest code for the query through the various different classes, but I can't see why this would fail.  So, I'm hoping that either this is fixed in version after 2.9 or maybe I'm using this incorrectly.  Otherwise, if it's a real bug, then hopefully, it can get fixed.  Thanks

Jul 17, 2015
#1 srer...@gmail.com
From what I can tell, it looks like the problem is that the SSH treats the space as a new argument.  i.e. I get the same output from both of these statements:
B. ssh -n -p <port> <git server> gerrit query after:"2015-07-16 00:00:00"
E. ssh -n -p <port> <git server> gerrit query after:"2015-07-16" 00:00:00
So, I think it has to do with the argument parsing of SSH.

Is there a workaround for something like this?  It's too bad we can just enter a UTC timestamp.  That would have fixed this as well.
Jul 17, 2015
Project Member #2 edwin.ke...@gmail.com
Have you tried it with double-quoting it, with single quotes AND double quotes?

  ssh -n -p <port> <git server> gerrit query after:"'2015-07-16 00:00:00'"
Jul 17, 2015
#3 srer...@gmail.com
Yes, I tried both of these:
after:"'2015-07-16 00:00:00'"
after:'"2015-07-16 00:00:00"'
Both respond just as if I did either of these:
after:"'2015-07-16'" 00:00:00
after:2015-07-16 00:00:00
Jul 20, 2015
#4 srer...@gmail.com
Any more ideas here?

Is there any way to get an acknowledgement that this is a real issue that will get fixed at some point?  Right now, I'm wondering if anyone thinks this is a real issue or not.  It'd be great if someone else could verify my findings.  Or if there is a public test gerrit server that I can use, I'll give that a shot myself.

Jul 21, 2015
#5 srer...@gmail.com
FYI - I found a workaround, but I'm not 100% sure on why it is needed.

While looking at the code inside $TOP/gerrit-util-cli/src/main/java/com/google/gerrit/util/cli/CmdLineParser.java – parseArgument(), I zeroed in on the idea that argv and args.length must still be interpreting the space between the date and time as a separate argument.  When I look at java command line arguments online though, they say that quotes around an argument with a space should not split an argument on that space.

So, after grumbling on that for awhile, I had thought that maybe ssh is swallowing the quotes.  I don’t know for certain if that’s it, but I tried this:
ssh -n -p <port> <git server> gerrit query after:\’\”2015-07-16 00:00:00\”\’
and it worked!

So just escaping the quotes allowed the argument parsing to work.  I tried just a single \’ or \” around the date time, but that didn’t work.

Anyway, that seems like a valid workaround for me and I plan to use it.  Feel free to close this out if you all agree that it's valid as well.

Jul 24, 2015
#6 icee...@googlemail.com
Try: gerrit query "after:\"2015-06-01 00:00:00 +1\""

-> The whole arg must be qoted for ssh, and the escape the inner quotes.