@@ -73,6 +73,42 @@ func TestDotfiles(t *testing.T) {
73
73
assert .NoError (t , err )
74
74
assert .Equal (t , string (b ), "wow\n " )
75
75
})
76
+ t .Run ("SymlinkBackup" , func (t * testing.T ) {
77
+ _ , root := clitest .New (t )
78
+ testRepo := testGitRepo (t , root )
79
+
80
+ // nolint:gosec
81
+ err := os .WriteFile (filepath .Join (testRepo , ".bashrc" ), []byte ("wow" ), 0750 )
82
+ assert .NoError (t , err )
83
+
84
+ // add a conflicting file at destination
85
+ // nolint:gosec
86
+ err = os .WriteFile (filepath .Join (string (root ), ".bashrc" ), []byte ("backup" ), 0750 )
87
+ assert .NoError (t , err )
88
+
89
+ c := exec .Command ("git" , "add" , ".bashrc" )
90
+ c .Dir = testRepo
91
+ err = c .Run ()
92
+ assert .NoError (t , err )
93
+
94
+ c = exec .Command ("git" , "commit" , "-m" , `"add .bashrc"` )
95
+ c .Dir = testRepo
96
+ out , err := c .CombinedOutput ()
97
+ assert .NoError (t , err , string (out ))
98
+
99
+ cmd , _ := clitest .New (t , "dotfiles" , "--global-config" , string (root ), "--symlink-dir" , string (root ), "-y" , testRepo )
100
+ err = cmd .Execute ()
101
+ assert .NoError (t , err )
102
+
103
+ b , err := os .ReadFile (filepath .Join (string (root ), ".bashrc" ))
104
+ assert .NoError (t , err )
105
+ assert .Equal (t , string (b ), "wow" )
106
+
107
+ // check for backup file
108
+ b , err = os .ReadFile (filepath .Join (string (root ), ".bashrc.bak" ))
109
+ assert .NoError (t , err )
110
+ assert .Equal (t , string (b ), "backup" )
111
+ })
76
112
}
77
113
78
114
func testGitRepo (t * testing.T , root config.Root ) string {
0 commit comments