Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/commands/git_commands/working_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ func (self *WorkingTreeCommands) DiscardUnstagedFileChanges(file *models.File) e
return self.cmd.New(cmdArgs).Run()
}

// Escapes special characters in a filename for gitignore and exclude files
// Escapes special characters in a filename for gitignore and exclude files, and prepends `/`
func escapeFilename(filename string) string {
re := regexp.MustCompile(`^[!#]|[\[\]*]`)
return re.ReplaceAllString(filename, `\${0}`)
return "/" + re.ReplaceAllString(filename, `\${0}`)
}

// Ignore adds a file to the gitignore for the repo
Expand Down
6 changes: 3 additions & 3 deletions pkg/integration/tests/file/gitignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ var Gitignore = NewIntegrationTest(NewIntegrationTestArgs{
t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .git/info/exclude")).Confirm()

t.FileSystem().FileContent(".gitignore", Equals(""))
t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
t.FileSystem().FileContent(".git/info/exclude", Contains("/toExclude"))
}).
SelectNextItem().
Press(keys.Files.IgnoreFile).
// ignore a file
Tap(func() {
t.ExpectPopup().Menu().Title(Equals("Ignore or exclude file")).Select(Contains("Add to .gitignore")).Confirm()

t.FileSystem().FileContent(".gitignore", Equals("toIgnore\n"))
t.FileSystem().FileContent(".git/info/exclude", Contains("toExclude"))
t.FileSystem().FileContent(".gitignore", Equals("/toIgnore\n"))
t.FileSystem().FileContent(".git/info/exclude", Contains("/toExclude"))
})
},
})
2 changes: 1 addition & 1 deletion pkg/integration/tests/file/gitignore_special_characters.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ var GitignoreSpecialCharacters = NewIntegrationTest(NewIntegrationTestArgs{
Equals(" ?? abc_def"),
)

t.FileSystem().FileContent(".gitignore", Equals("\\#file\nfile#abc\n\\!file\nfile!abc\nabc\\*def\nfile\\[x\\]\n"))
t.FileSystem().FileContent(".gitignore", Equals("/\\#file\n/file#abc\n/\\!file\n/file!abc\n/abc\\*def\n/file\\[x\\]\n"))
},
})