Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a1b5425c2 |
No files matched your search
@@ -333,15 +333,8 @@ func newConfigEditCommand() *cobra.Command {
|
|||||||
editor = "vi"
|
editor = "vi"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run $EDITOR through the shell, as git does, so a value
|
|
||||||
// with arguments such as "code --wait" works. The path
|
|
||||||
// goes in as an argument ("$@"), not into the command
|
|
||||||
// text, so a path with spaces or quotes arrives whole.
|
|
||||||
// sh -c takes the word after the command as $0, which
|
|
||||||
// is why editor appears twice.
|
|
||||||
//nolint:gosec // G204: launching the operator's own $EDITOR is the point
|
//nolint:gosec // G204: launching the operator's own $EDITOR is the point
|
||||||
ed := exec.CommandContext(cmd.Context(),
|
ed := exec.CommandContext(cmd.Context(), editor, path)
|
||||||
"sh", "-c", editor+` "$@"`, editor, path)
|
|
||||||
ed.Stdin = os.Stdin
|
ed.Stdin = os.Stdin
|
||||||
ed.Stdout = os.Stdout
|
ed.Stdout = os.Stdout
|
||||||
ed.Stderr = os.Stderr
|
ed.Stderr = os.Stderr
|
||||||
|
|||||||
@@ -647,30 +647,6 @@ func TestWriteConfigSetTightensMode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestConfigEditEditorWithArgument checks that an $EDITOR carrying an
|
|
||||||
// argument works and that a config path with a space reaches it whole.
|
|
||||||
// The "editor" is cp with the replacement file as its argument, so the
|
|
||||||
// config ends up with the replacement's content only if both arrived.
|
|
||||||
func TestConfigEditEditorWithArgument(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
path := seedFile(t, dir, "my config.yml", "compression_level: 3\n")
|
|
||||||
edited := seedFile(t, dir, "edited.yml", "compression_level: 9\n")
|
|
||||||
|
|
||||||
setRootFlags(t, RootFlags{ConfigPath: path})
|
|
||||||
t.Setenv("EDITOR", "cp '"+edited+"'")
|
|
||||||
|
|
||||||
mustExecute(t, newConfigEditCommand())
|
|
||||||
|
|
||||||
data, err := os.ReadFile(path) //nolint:gosec // G304: test-controlled path
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("reading config back: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if string(data) != "compression_level: 9\n" {
|
|
||||||
t.Errorf("config after edit = %q, want the edited content", data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func splitPath(s string) []string {
|
func splitPath(s string) []string {
|
||||||
return strings.Split(s, ".")
|
return strings.Split(s, ".")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user