@@ -80,6 +80,52 @@ func TestDotfiles(t *testing.T) {
80
80
require .NoError (t , err )
81
81
require .Equal (t , string (b ), "wow\n " )
82
82
})
83
+ t .Run ("InstallScriptChangeBranch" , func (t * testing.T ) {
84
+ t .Parallel ()
85
+ if runtime .GOOS == "windows" {
86
+ t .Skip ("install scripts on windows require sh and aren't very practical" )
87
+ }
88
+ _ , root := clitest .New (t )
89
+ testRepo := testGitRepo (t , root )
90
+
91
+ // We need an initial commit to start the `main` branch
92
+ c := exec .Command ("git" , "commit" , "--allow-empty" , "-m" , `"initial commit"` )
93
+ c .Dir = testRepo
94
+ err := c .Run ()
95
+ require .NoError (t , err )
96
+
97
+ // nolint:gosec
98
+ err = os .WriteFile (filepath .Join (testRepo , "install.sh" ), []byte ("#!/bin/bash\n echo wow > " + filepath .Join (string (root ), ".bashrc" )), 0o750 )
99
+ require .NoError (t , err )
100
+
101
+ c = exec .Command ("git" , "checkout" , "-b" , "other_branch" )
102
+ c .Dir = testRepo
103
+ err = c .Run ()
104
+ require .NoError (t , err )
105
+
106
+ c = exec .Command ("git" , "add" , "install.sh" )
107
+ c .Dir = testRepo
108
+ err = c .Run ()
109
+ require .NoError (t , err )
110
+
111
+ c = exec .Command ("git" , "commit" , "-m" , `"add install.sh"` )
112
+ c .Dir = testRepo
113
+ err = c .Run ()
114
+ require .NoError (t , err )
115
+
116
+ c = exec .Command ("git" , "checkout" , "main" )
117
+ c .Dir = testRepo
118
+ err = c .Run ()
119
+ require .NoError (t , err )
120
+
121
+ inv , _ := clitest .New (t , "dotfiles" , "--global-config" , string (root ), "--symlink-dir" , string (root ), "-y" , testRepo , "-b" , "other_branch" )
122
+ err = inv .Run ()
123
+ require .NoError (t , err )
124
+
125
+ b , err := os .ReadFile (filepath .Join (string (root ), ".bashrc" ))
126
+ require .NoError (t , err )
127
+ require .Equal (t , string (b ), "wow\n " )
128
+ })
83
129
t .Run ("SymlinkBackup" , func (t * testing.T ) {
84
130
t .Parallel ()
85
131
_ , root := clitest .New (t )
@@ -152,5 +198,10 @@ func testGitRepo(t *testing.T, root config.Root) string {
152
198
err = c .Run ()
153
199
require .NoError (t , err )
154
200
201
+ c = exec .Command ("git" , "checkout" , "-b" , "main" )
202
+ c .Dir = dir
203
+ err = c .Run ()
204
+ require .NoError (t , err )
205
+
155
206
return dir
156
207
}
0 commit comments