Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git.grep and pathspec not working as expected #914

Closed
didoo opened this issue Apr 5, 2023 · 6 comments
Closed

git.grep and pathspec not working as expected #914

didoo opened this issue Apr 5, 2023 · 6 comments

Comments

@didoo
Copy link

didoo commented Apr 5, 2023

issue

If a pathspec option is provided to the git.grep command, it's not appended as last option per official documentation but it appears before the -e option, which causes git to fail:

Frame 1

I tried different alternatives to provide the arguments, to bypass the problem, but none of them worked. Looking at the source code, my understanding is that the -e option is always appendend (but this should not be the case if a pathspec argument is provided).

Any idea if there is a workaround? Should this be considered a bug? I may try to open a PR, if there's no alternatives, but since I'm new to this codebase I would prefer to be sure that my understanding of the problem is correct.

@didoo didoo changed the title git.grep and pathspec not working as expected git.grep and pathspec not working as expected Apr 5, 2023
@steveukx
Copy link
Owner

steveukx commented Apr 9, 2023

Hello, please can you include the code you are using to generate the arguments - is this through the grepQueryBuilder ?

@steveukx steveukx added the more-info-needed More information is required in order to investigate label Apr 9, 2023
@didoo
Copy link
Author

didoo commented Apr 13, 2023

Hello, please can you include the code you are using to generate the arguments - is this through the grepQueryBuilder ?

@steveukx I have tried both these variants, but both lead to the same problem of arguments order:

const grepResultsPds = await git.grep('<Pds::', ['--ignore-case', '--count', '--', '*.hbs']);
const grepResultsPds = await git.grep(grepQueryBuilder('<Pds::'), ['--ignore-case', '--count', '--', '--*.hbs']);

@github-actions github-actions bot removed the more-info-needed More information is required in order to investigate label Apr 13, 2023
steveukx added a commit that referenced this issue May 14, 2023
@steveukx
Copy link
Owner

Apologies for the delay, but thank you for the detail in the issue.

From the next release, which will be this week, you will be able to use a pathspec utility in the trailing TaskOptions array/object that handles the -- separation for you.

import {pathspec, simpleGit} from 'simple-git'
const grepResultsPds = await git.grep('<Pds::', ['--ignore-case',  pathspec('*.hbs')]);

@didoo
Copy link
Author

didoo commented May 22, 2023

@steveukx thank you for the fix (I see the same issue with the command submoduleUpdate, and probably subModule)
let me know when it's released so I can test it (for now I had to fallback to use execSync)

@steveukx
Copy link
Owner

Hi @didoo the changes are now live in 3.19.0 and should "just work" in any task that allowed a trailing TaskOptions array or object (and in some that don't - for example git.add([ pathspec('abc' ]). If you do have problems though, please open a new issue and I'll have a look into it.

@didoo
Copy link
Author

didoo commented Jun 19, 2023

@steveukx tested now, and works like a charm! Thank you for the fix 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants