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

feat: Use execa #115

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 241 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@typescript-eslint/parser": "^8.12.2",
"@vscode/vsce": "^3.0.0",
"eslint": "^8.57.1",
"execa": "^9.5.1",
"mocha": "^10.0.0",
"nyc": "^17.1.0",
"prettier": "^3.0.3",
Expand Down
9 changes: 3 additions & 6 deletions src/git/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
*
* Run Git CLI commands within the extension and capture the text output.
*/
import { exec as _exec } from "child_process";
import * as util from "util";
import { execa } from "execa";
import { Repository } from "../api/git";

const exec = util.promisify(_exec);

// Ensure Git will show special characters literally without quoting the string
// and escaping characters.
const QUOTE_PATH = '-c "core.quotePath=false"';
const QUOTE_PATH = ["-c", "core.quotePath=false"];

const DIFF_INDEX_CMD = "diff-index";
const DIFF_INDEX_OPTIONS = [
Expand All @@ -29,7 +26,7 @@ function _execute(cwd: string, subcommand: string, options: string[] = []) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can see, for the array in QUOTE_PATH to help with escaping you would need to use execa's array syntax (which is the concept I was referring to in the issue)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right. I did a standalone test using array and nesting it.

But forgot to do it here, I guess on line 28 for command as array rather than strings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, (besides git needing to be extra). Line 29 could look like this as far as I see it:

return execa("git", [...QUOTE_PATH, subcommand, ...options] ,{ cwd });

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. I added #116 as a task to update to module type and then this PR will be possible

console.debug(`Running command: ${command}, cwd: ${cwd}`);

return exec(command, { cwd });
return execa(command, { cwd });
}

/**
Expand Down
Loading