File tree 1 file changed +11
-2
lines changed
pkg/commands/git_commands
1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 4
4
"fmt"
5
5
"os"
6
6
"path/filepath"
7
+ "strings"
7
8
8
9
"github.com/go-errors/errors"
9
10
"github.com/jesseduffield/lazygit/pkg/commands/models"
@@ -230,15 +231,23 @@ func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) e
230
231
return self .cmd .New (cmdArgs ).Run ()
231
232
}
232
233
234
+ func escapeFilename (filename string ) string {
235
+ escapedFilename := filename
236
+ if strings .HasPrefix (filename , "#" ) || strings .HasPrefix (filename , "!" ) {
237
+ escapedFilename = "\\ " + filename
238
+ }
239
+ return escapedFilename
240
+ }
241
+
233
242
// Ignore adds a file to the gitignore for the repo
234
243
func (self * WorkingTreeCommands ) Ignore (filename string ) error {
235
- return self .os .AppendLineToFile (".gitignore" , filename )
244
+ return self .os .AppendLineToFile (".gitignore" , escapeFilename ( filename ) )
236
245
}
237
246
238
247
// Exclude adds a file to the .git/info/exclude for the repo
239
248
func (self * WorkingTreeCommands ) Exclude (filename string ) error {
240
249
excludeFile := filepath .Join (self .repoPaths .repoGitDirPath , "info" , "exclude" )
241
- return self .os .AppendLineToFile (excludeFile , filename )
250
+ return self .os .AppendLineToFile (excludeFile , escapeFilename ( filename ) )
242
251
}
243
252
244
253
// WorktreeFileDiff returns the diff of a file
You can’t perform that action at this time.
0 commit comments