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

fix git mv commands when migrating files with $ characters #6129

Merged
merged 4 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/unlucky-cameras-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-migrate': patch
---

[fix] git mv files correctly when they contain \$ characters
3 changes: 2 additions & 1 deletion packages/migrate/migrations/routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'path';
import colors from 'kleur';
import ts from 'typescript';
import MagicString from 'magic-string';
import sq from 'shell-quote';
import { execSync } from 'child_process';

/** @param {string} message */
Expand Down Expand Up @@ -46,7 +47,7 @@ export function error(description, comment_id) {
*/
export function move_file(file, renamed, content, use_git) {
if (use_git) {
execSync(`git mv ${JSON.stringify(file)} ${JSON.stringify(renamed)}`);
execSync(`git mv ${sq.quote([file, renamed])}`);
Copy link
Member

Choose a reason for hiding this comment

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

Could we use https://nodejs.org/dist/latest/docs/api/child_process.html#child_processexecfilefile-args-options-callback instead so we can pass in an array of arguments directly and not have to worry about the shell escaping?

Copy link
Member

Choose a reason for hiding this comment

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

Untested, but I think it'd be execFileSync('git', ['mv', file, renamed]).

Copy link
Member

@dominikg dominikg Aug 20, 2022

Choose a reason for hiding this comment

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

ohh, thats nice.
Seems to work alright for \n and $
execFileSync:

node -e 'console.log(require("child_process").execFileSync("echo",["bla\\n$1"]).toString())'
bla\n$1

execSync:

node -e 'console.log(require("child_process").execSync("echo bla\\n$1").toString())'
blan

Copy link
Member Author

Choose a reason for hiding this comment

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

ooh yeah that's way better

} else {
fs.unlinkSync(file);
}
Expand Down
1 change: 1 addition & 0 deletions packages/migrate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"kleur": "^4.1.4",
"magic-string": "^0.26.2",
"prompts": "^2.4.2",
"shell-quote": "^1.7.3",
"tiny-glob": "^0.2.9",
"typescript": "^4.7.4"
},
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

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