the_silver_searcher icon indicating copy to clipboard operation
the_silver_searcher copied to clipboard

Unexpected behavior under Windows mintty (git for windows 2.35.1)

Open kenstir opened this issue 2 years ago • 5 comments

When running under Git bash, ag behaves strangely and I can't explain the results. What I see under CMD is correct; what I see under Git bash is inexplicable:

  1. ag string hangs
  2. ag string . returns unexpected results
  3. ag -l string . returns no matches at all

test case set up

Set up:

  1. Create a clean directory
  2. Run this script to create one file string.cpp
#!/bin/bash -

cat >string.cpp <<EOF
#include "string.h"
class String {
    static int i;
};
int String::i;
EOF

Case 1 - ag string hangs:

$ ag string

Case 2 - ag string . returns unexpected results:

$ ag string .
#include "string.h"
class String {
int String::i;

Expected results from CMD:

C:\Users\kenstir\Downloads\ag_test_case>ag string .
string.cpp
1:#include "string.h"
2:class String {
5:int String::i;

Case 3 - ag -l string . returns zero matches:

kenstir@agent-smith MINGW64 ~/Downloads/ag_test_case
$ ag -l string .

kenstir@agent-smith MINGW64 ~/Downloads/ag_test_case
$

Expected results from CMD:

C:\Users\kenstir\Downloads\ag_test_case>ag -l string .
string.cpp

kenstir avatar Mar 10 '22 17:03 kenstir

Forgot to mention that ag is the latest version installed today with winget:

C:\Users\kenstir\Downloads\ag_test_case>ag --version
ag version 2.2.5 ; Windows port 2021-06-04 Win64 >= Server2003 amd64
MsvcLibX 2021-06-03 ; PCRE 8.44 2020-02-12 ; pthreads4w 3.0.0 ; zlib 1.2.11

Features:
  +jit -lzma +zlib +2enc

kenstir avatar Mar 10 '22 17:03 kenstir

If it is helpful, ag-2.2.0 from k-takata works

kenstir@agent-smith MINGW64 ~/Downloads/ag_test_case
$ PATH=/c/tools/ag-2020-07-05_2.2.0-58-g5a1c8d8-x64:$PATH

kenstir@agent-smith MINGW64 ~/Downloads/ag_test_case
$ ag string
string.cpp
1:#include "string.h"
2:class String {
5:int String::i;

kenstir@agent-smith MINGW64 ~/Downloads/ag_test_case
$ ag string .
string.cpp
1:#include "string.h"
2:class String {
5:int String::i;

kenstir@agent-smith MINGW64 ~/Downloads/ag_test_case
$ ag -l string .
string.cpp

kenstir avatar Mar 10 '22 17:03 kenstir

Thanks for the detailed description, which should make it easy to reproduce. I'm currently traveling, and I'll look at that next week.

JFLarvoire avatar Mar 11 '22 15:03 JFLarvoire

I've reproduced the problem. It does not occur with my usual instance of git bash, but it does if I start "C:\msys64\mingw64.exe" manually. The difference is that my usual git bash runs MSYS ("%PROGRAMFILES%\Git\usr\bin\bash.exe") in the new Windows Terminal, whereas the failing instance is MINGW64 ("C:\msys64\mingw64.exe") in its own terminal. It's still unclear if the problem comes from MSYS versus MINGW64, or from the Windows Terminal versus MINGW64's mintty.

JFLarvoire avatar Mar 17 '22 13:03 JFLarvoire

The repro is good news! I run the Git Bash shortcut from the Start menu item created by the Git installer, which has the Target:

C:\Users\kenstir\AppData\Local\Programs\Git\git-bash.exe --cd-to-home

kenstir avatar Mar 17 '22 16:03 kenstir