@@ -233,9 +233,10 @@ func cmdMkGPGConfig(ts *testscript.TestScript, neg bool, args []string) {
233233 if neg {
234234 ts .Fatalf ("unupported: ! mkgpgconfig" )
235235 }
236- if len (args ) > 0 {
237- ts .Fatalf ("usage: mkgpgconfig" )
236+ if len (args ) > 1 || len ( args ) == 1 && args [ 0 ] != "-symmetric" {
237+ ts .Fatalf ("usage: mkgpgconfig [-symmetric] " )
238238 }
239+ symmetric := len (args ) == 1 && args [0 ] == "-symmetric"
239240
240241 // Create a new directory for GPG. We can't use a subdirectory of the
241242 // testscript's working directory because on darwin the absolute path can
@@ -260,17 +261,22 @@ func cmdMkGPGConfig(ts *testscript.TestScript, neg bool, args []string) {
260261
261262 configFile := filepath .Join (ts .Getenv ("HOME" ), ".config" , "chezmoi" , "chezmoi.toml" )
262263 ts .Check (os .MkdirAll (filepath .Dir (configFile ), 0o777 ))
263- ts . Check ( os . WriteFile ( configFile , [] byte ( fmt . Sprintf ( chezmoitest . JoinLines (
264+ lines := [] string {
264265 `encryption = "gpg"` ,
265266 `[gpg]` ,
266267 ` args = [` ,
267- ` "--homedir", %q ,` ,
268+ ` "--homedir", ` + quote ( gpgHomeDir ) + ` ,` ,
268269 ` "--no-tty",` ,
269- ` "--passphrase", %q ,` ,
270+ ` "--passphrase", ` + quote ( passphrase ) + ` ,` ,
270271 ` "--pinentry-mode", "loopback",` ,
271272 ` ]` ,
272- ` recipient = %q` ,
273- ), gpgHomeDir , passphrase , key )), 0o666 ))
273+ }
274+ if symmetric {
275+ lines = append (lines , ` symmetric = true` )
276+ } else {
277+ lines = append (lines , ` recipient = "` + key + `"` )
278+ }
279+ ts .Check (os .WriteFile (configFile , []byte (chezmoitest .JoinLines (lines ... )), 0o666 ))
274280}
275281
276282// cmdMkHomeDir makes and populates a home directory.
@@ -430,6 +436,10 @@ func prependDirToPath(dir, path string) string {
430436 return strings .Join (append ([]string {dir }, filepath .SplitList (path )... ), string (os .PathListSeparator ))
431437}
432438
439+ func quote (s string ) string {
440+ return fmt .Sprintf ("%q" , s )
441+ }
442+
433443func setup (env * testscript.Env ) error {
434444 var (
435445 binDir = filepath .Join (env .WorkDir , "bin" )
0 commit comments