@@ -650,6 +650,132 @@ normal = "status"
650650 }
651651 }
652652 })
653+
654+ // Test importing a single setting
655+ t .Run ("import single setting" , func (t * testing.T ) {
656+ // Create a new test home for this test
657+ testHome3 := t .TempDir ()
658+
659+ // Create test jj config with multiple values
660+ jjConfigDir3 := filepath .Join (testHome3 , ".config" , "jj" )
661+ if err := os .MkdirAll (jjConfigDir3 , 0o755 ); err != nil {
662+ t .Fatalf ("Failed to create jj config dir: %v" , err )
663+ }
664+
665+ jjConfigMultiple := `[user]
666+ name = "Single Import Test"
667+ email = "single@example.com"
668+
669+ [snapshot]
670+ max-new-file-size = 4096
671+ `
672+ if err := os .WriteFile (filepath .Join (jjConfigDir3 , "config.toml" ), []byte (jjConfigMultiple ), 0o644 ); err != nil {
673+ t .Fatalf ("Failed to write jj config: %v" , err )
674+ }
675+
676+ // Import only user.name
677+ cmd := exec .Command (binaryPath , "import" , "jj" , "user.name" )
678+ cmd .Env = append (os .Environ (), "HOME=" + testHome3 )
679+
680+ var stdout , stderr bytes.Buffer
681+ cmd .Stdout = & stdout
682+ cmd .Stderr = & stderr
683+
684+ if err := cmd .Run (); err != nil {
685+ t .Errorf ("Import single setting failed: %v" , err )
686+ t .Logf ("stdout: %s" , stdout .String ())
687+ t .Logf ("stderr: %s" , stderr .String ())
688+ }
689+
690+ output := stdout .String ()
691+
692+ // Verify only user.name is imported
693+ if ! strings .Contains (output , "user.name" ) {
694+ t .Errorf ("Expected import output to show user.name, got: %s" , output )
695+ }
696+ if ! strings .Contains (output , "Single Import Test" ) {
697+ t .Errorf ("Expected import output to show the value 'Single Import Test', got: %s" , output )
698+ }
699+ if ! strings .Contains (output , "✓ Import complete" ) {
700+ t .Errorf ("Expected completion message, got: %s" , output )
701+ }
702+
703+ // Verify conf state file was created and contains only user.name
704+ confStateFile := filepath .Join (testHome3 , ".config" , "conf" , "jj.toml" )
705+ if _ , err := os .Stat (confStateFile ); os .IsNotExist (err ) {
706+ t .Errorf ("Expected conf state file to be created at %s" , confStateFile )
707+ } else {
708+ content , err := os .ReadFile (confStateFile )
709+ if err != nil {
710+ t .Errorf ("Failed to read conf state file: %v" , err )
711+ } else {
712+ contentStr := string (content )
713+ // Should contain user.name but not the other values
714+ if ! strings .Contains (contentStr , "Single Import Test" ) {
715+ t .Errorf ("Expected conf state to contain 'Single Import Test', got: %s" , contentStr )
716+ }
717+ // Should NOT contain user.email or snapshot settings since we only imported user.name
718+ if strings .Contains (contentStr , "single@example.com" ) {
719+ t .Errorf ("Expected conf state to NOT contain 'single@example.com' (not imported), got: %s" , contentStr )
720+ }
721+ if strings .Contains (contentStr , "4096" ) {
722+ t .Errorf ("Expected conf state to NOT contain '4096' (not imported), got: %s" , contentStr )
723+ }
724+ }
725+ }
726+ })
727+
728+ // Test importing a single setting with dry-run
729+ t .Run ("import single setting dry-run" , func (t * testing.T ) {
730+ // Create a new test home for this test
731+ testHome4 := t .TempDir ()
732+
733+ // Create test jj config
734+ jjConfigDir4 := filepath .Join (testHome4 , ".config" , "jj" )
735+ if err := os .MkdirAll (jjConfigDir4 , 0o755 ); err != nil {
736+ t .Fatalf ("Failed to create jj config dir: %v" , err )
737+ }
738+
739+ jjConfigSingle := `[user]
740+ email = "dryrun@example.com"
741+ `
742+ if err := os .WriteFile (filepath .Join (jjConfigDir4 , "config.toml" ), []byte (jjConfigSingle ), 0o644 ); err != nil {
743+ t .Fatalf ("Failed to write jj config: %v" , err )
744+ }
745+
746+ // Dry-run import of user.email
747+ cmd := exec .Command (binaryPath , "import" , "jj" , "user.email" , "--dry-run" )
748+ cmd .Env = append (os .Environ (), "HOME=" + testHome4 )
749+
750+ var stdout , stderr bytes.Buffer
751+ cmd .Stdout = & stdout
752+ cmd .Stderr = & stderr
753+
754+ if err := cmd .Run (); err != nil {
755+ t .Errorf ("Import single setting dry-run failed: %v" , err )
756+ t .Logf ("stdout: %s" , stdout .String ())
757+ t .Logf ("stderr: %s" , stderr .String ())
758+ }
759+
760+ output := stdout .String ()
761+
762+ // Verify dry-run output
763+ if ! strings .Contains (output , "user.email" ) {
764+ t .Errorf ("Expected dry-run output to show user.email, got: %s" , output )
765+ }
766+ if ! strings .Contains (output , "dryrun@example.com" ) {
767+ t .Errorf ("Expected dry-run output to show the value 'dryrun@example.com', got: %s" , output )
768+ }
769+ if ! strings .Contains (output , "Would import: jj.user.email = dryrun@example.com" ) {
770+ t .Errorf ("Expected dry-run message, got: %s" , output )
771+ }
772+
773+ // Verify conf state file was NOT created in dry-run mode
774+ confStateFile := filepath .Join (testHome4 , ".config" , "conf" , "jj.toml" )
775+ if _ , err := os .Stat (confStateFile ); ! os .IsNotExist (err ) {
776+ t .Errorf ("Expected conf state file to NOT be created in dry-run mode, but it exists at %s" , confStateFile )
777+ }
778+ })
653779}
654780
655781// TestApplyPreservesUnmanagedSettings tests that `conf apply` preserves
0 commit comments