Skip to content

Commit

Permalink
client/init: copy .gitignore to .tsuruignore
Browse files Browse the repository at this point in the history
  • Loading branch information
arxdsilva authored and andrestc committed Apr 9, 2018
1 parent ede7b0f commit 1eef728
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tsuru/client/init.go
Expand Up @@ -2,6 +2,8 @@ package client

import (
"fmt"
"io"
"io/ioutil"
"os"

"github.com/tsuru/tsuru/cmd"
Expand Down Expand Up @@ -45,5 +47,33 @@ func (i *Init) Run(context *cmd.Context, client *cmd.Client) error {
}
msg := fmt.Sprintf("Initialized Tsuru sample files: `Procfile`, `.tsuruignore` and `tsuru.yaml`, for more info please refer to the docs: docs.tsuru.io\n")
context.Stdout.Write([]byte(msg))
return nil
return copyGitIgnore()
}

func copyGitIgnore() error {
in, err := os.Open(".gitignore")
if err != nil {
dotGit := []byte(".git\n")
return ioutil.WriteFile(".tsuruignore", dotGit, 0644)
}
defer func() {
if errC := in.Close(); errC != nil {
err = errC
}
}()
out, err := os.OpenFile(".tsuruignore", os.O_APPEND|os.O_WRONLY, os.ModeAppend)
if err != nil {
return err
}
defer func() {
if errC := out.Close(); errC != nil {
err = errC
}
}()
_, err = io.Copy(out, in)
if err != nil {
return err
}
_, err = out.WriteString("\n.git\n")
return err
}

0 comments on commit 1eef728

Please sign in to comment.