diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2018-08-19 20:42:51 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-19 20:42:51 +1000 |
commit | e6712832b502bf893d11d0c891f5ab1b69242fec (patch) | |
tree | 739ea69769d7e644f17222bf44b05c74ccfd4438 | |
parent | 51558f51ab3b54b445f7449582a060f1bc42de18 (diff) | |
parent | aa4d739577f627ca6a3843ccb9e9468c7dd7aeba (diff) |
Merge pull request #187 from jesseduffield/hotfix/177-fix-gitignorev0.1.73
177: Fix ignore feature
-rw-r--r-- | pkg/commands/git.go | 6 | ||||
-rw-r--r-- | pkg/commands/os.go | 11 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 4 |
3 files changed, 16 insertions, 5 deletions
diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 5176e55c9..557e6a8c0 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -461,10 +461,8 @@ func (c *GitCommand) GetLog() string { } // Ignore adds a file to the gitignore for the repo -func (c *GitCommand) Ignore(filename string) { - if _, err := c.OSCommand.RunDirectCommand("echo '" + filename + "' >> .gitignore"); err != nil { - panic(err) - } +func (c *GitCommand) Ignore(filename string) error { + return c.OSCommand.AppendLineToFile(".gitignore", filename) } // Show shows the diff of a commit diff --git a/pkg/commands/os.go b/pkg/commands/os.go index b72585e44..9756d619d 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -174,3 +174,14 @@ func (c *OSCommand) Unquote(message string) string { message = strings.Replace(message, `"`, "", -1) return message } + +func (C *OSCommand) AppendLineToFile(filename, line string) error { + f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + return err + } + defer f.Close() + + _, err = f.WriteString("\n" + line) + return err +} diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 596eb80cc..d614cf5ef 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -142,7 +142,9 @@ func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { if file.Tracked { return gui.createErrorPanel(g, gui.Tr.SLocalize("CantIgnoreTrackFiles")) } - gui.GitCommand.Ignore(file.Name) + if err := gui.GitCommand.Ignore(file.Name); err != nil { + return gui.createErrorPanel(g, err.Error()) + } return gui.refreshFiles(g) } |