@@ -277,7 +277,7 @@ func (suite *CLITestSuite) TestErrorHandling() {
277277 name : "add help" ,
278278 args : []string {"add" , "--help" },
279279 wantErr : false ,
280- outContains : "Moves a file to the lnk repository" ,
280+ outContains : "Moves files to the lnk repository" ,
281281 },
282282 {
283283 name : "list help" ,
@@ -790,8 +790,8 @@ func (suite *CLITestSuite) TestInitWithBootstrap() {
790790 err := os .MkdirAll (remoteDir , 0755 )
791791 suite .Require ().NoError (err )
792792
793- // Initialize git repo in remote
794- cmd := exec .Command ("git" , "init" , "--bare" )
793+ // Initialize git repo in remote with main branch
794+ cmd := exec .Command ("git" , "init" , "--bare" , "--initial-branch=main" )
795795 cmd .Dir = remoteDir
796796 err = cmd .Run ()
797797 suite .Require ().NoError (err )
@@ -835,7 +835,7 @@ touch remote-bootstrap-ran.txt
835835 err = cmd .Run ()
836836 suite .Require ().NoError (err )
837837
838- cmd = exec .Command ("git" , "push" , "origin" , "master " )
838+ cmd = exec .Command ("git" , "push" , "origin" , "main " )
839839 cmd .Dir = workingDir
840840 err = cmd .Run ()
841841 suite .Require ().NoError (err )
@@ -863,8 +863,8 @@ func (suite *CLITestSuite) TestInitWithBootstrapDisabled() {
863863 err := os .MkdirAll (remoteDir , 0755 )
864864 suite .Require ().NoError (err )
865865
866- // Initialize git repo in remote
867- cmd := exec .Command ("git" , "init" , "--bare" )
866+ // Initialize git repo in remote with main branch
867+ cmd := exec .Command ("git" , "init" , "--bare" , "--initial-branch=main" )
868868 cmd .Dir = remoteDir
869869 err = cmd .Run ()
870870 suite .Require ().NoError (err )
@@ -898,7 +898,7 @@ touch should-not-exist.txt
898898 err = cmd .Run ()
899899 suite .Require ().NoError (err )
900900
901- cmd = exec .Command ("git" , "push" , "origin" , "master " )
901+ cmd = exec .Command ("git" , "push" , "origin" , "main " )
902902 cmd .Dir = workingDir
903903 err = cmd .Run ()
904904 suite .Require ().NoError (err )
@@ -917,6 +917,101 @@ touch should-not-exist.txt
917917 suite .NoFileExists (markerFile )
918918}
919919
920+ func (suite * CLITestSuite ) TestAddCommandMultipleFiles () {
921+ // Initialize repository
922+ err := suite .runCommand ("init" )
923+ suite .Require ().NoError (err )
924+ suite .stdout .Reset ()
925+
926+ // Create multiple test files
927+ testFile1 := filepath .Join (suite .tempDir , ".bashrc" )
928+ err = os .WriteFile (testFile1 , []byte ("export PATH1" ), 0644 )
929+ suite .Require ().NoError (err )
930+
931+ testFile2 := filepath .Join (suite .tempDir , ".vimrc" )
932+ err = os .WriteFile (testFile2 , []byte ("set number" ), 0644 )
933+ suite .Require ().NoError (err )
934+
935+ testFile3 := filepath .Join (suite .tempDir , ".gitconfig" )
936+ err = os .WriteFile (testFile3 , []byte ("[user]\n name = test" ), 0644 )
937+ suite .Require ().NoError (err )
938+
939+ // Test add command with multiple files - should succeed
940+ err = suite .runCommand ("add" , testFile1 , testFile2 , testFile3 )
941+ suite .NoError (err , "Adding multiple files should succeed" )
942+
943+ // Check output shows all files were added
944+ output := suite .stdout .String ()
945+ suite .Contains (output , "Added 3 items to lnk" )
946+ suite .Contains (output , ".bashrc" )
947+ suite .Contains (output , ".vimrc" )
948+ suite .Contains (output , ".gitconfig" )
949+
950+ // Verify all files are now symlinks
951+ for _ , file := range []string {testFile1 , testFile2 , testFile3 } {
952+ info , err := os .Lstat (file )
953+ suite .NoError (err )
954+ suite .Equal (os .ModeSymlink , info .Mode ()& os .ModeSymlink )
955+ }
956+
957+ // Verify all files exist in storage
958+ lnkDir := filepath .Join (suite .tempDir , ".config" , "lnk" )
959+ suite .FileExists (filepath .Join (lnkDir , ".bashrc" ))
960+ suite .FileExists (filepath .Join (lnkDir , ".vimrc" ))
961+ suite .FileExists (filepath .Join (lnkDir , ".gitconfig" ))
962+
963+ // Verify .lnk file contains all entries
964+ lnkFile := filepath .Join (lnkDir , ".lnk" )
965+ lnkContent , err := os .ReadFile (lnkFile )
966+ suite .NoError (err )
967+ suite .Equal (".bashrc\n .gitconfig\n .vimrc\n " , string (lnkContent ))
968+ }
969+
970+ func (suite * CLITestSuite ) TestAddCommandMixedTypes () {
971+ // Initialize repository
972+ err := suite .runCommand ("init" )
973+ suite .Require ().NoError (err )
974+ suite .stdout .Reset ()
975+
976+ // Create a file
977+ testFile := filepath .Join (suite .tempDir , ".vimrc" )
978+ err = os .WriteFile (testFile , []byte ("set number" ), 0644 )
979+ suite .Require ().NoError (err )
980+
981+ // Create a directory with content
982+ testDir := filepath .Join (suite .tempDir , ".config" , "git" )
983+ err = os .MkdirAll (testDir , 0755 )
984+ suite .Require ().NoError (err )
985+ configFile := filepath .Join (testDir , "config" )
986+ err = os .WriteFile (configFile , []byte ("[user]" ), 0644 )
987+ suite .Require ().NoError (err )
988+
989+ // Test add command with mixed files and directories - should succeed
990+ err = suite .runCommand ("add" , testFile , testDir )
991+ suite .NoError (err , "Adding mixed files and directories should succeed" )
992+
993+ // Check output shows both items were added
994+ output := suite .stdout .String ()
995+ suite .Contains (output , "Added 2 items to lnk" )
996+ suite .Contains (output , ".vimrc" )
997+ suite .Contains (output , "git" )
998+
999+ // Verify both are now symlinks
1000+ info1 , err := os .Lstat (testFile )
1001+ suite .NoError (err )
1002+ suite .Equal (os .ModeSymlink , info1 .Mode ()& os .ModeSymlink )
1003+
1004+ info2 , err := os .Lstat (testDir )
1005+ suite .NoError (err )
1006+ suite .Equal (os .ModeSymlink , info2 .Mode ()& os .ModeSymlink )
1007+
1008+ // Verify storage
1009+ lnkDir := filepath .Join (suite .tempDir , ".config" , "lnk" )
1010+ suite .FileExists (filepath .Join (lnkDir , ".vimrc" ))
1011+ suite .DirExists (filepath .Join (lnkDir , ".config" , "git" ))
1012+ suite .FileExists (filepath .Join (lnkDir , ".config" , "git" , "config" ))
1013+ }
1014+
9201015func TestCLISuite (t * testing.T ) {
9211016 suite .Run (t , new (CLITestSuite ))
9221017}
0 commit comments