diff --git a/cmd/init.go b/cmd/init.go deleted file mode 100644 index bf875e5..0000000 --- a/cmd/init.go +++ /dev/null @@ -1,39 +0,0 @@ -package cmd - -import ( - "log" - - "github.com/notnmeyer/daylog-cli/internal/daylog" - "github.com/spf13/cobra" -) - -var initCmd = &cobra.Command{ - Use: "init", - Short: "Creare a Git repository for your project.", - Long: "Creare a Git repository for your project.", - Run: func(cmd *cobra.Command, args []string) { - dl, err := daylog.New(args, config.Project) - if err != nil { - log.Fatal(err) - } - - err = dl.InitGitRepo() - if err != nil { - log.Fatal(err) - } - }, -} - -func init() { - rootCmd.AddCommand(initCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // initCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // initCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") -} diff --git a/internal/daylog/daylog.go b/internal/daylog/daylog.go index b237472..b7bdc43 100644 --- a/internal/daylog/daylog.go +++ b/internal/daylog/daylog.go @@ -11,7 +11,6 @@ import ( "github.com/adrg/xdg" "github.com/markusmobius/go-dateparser" "github.com/notnmeyer/daylog-cli/internal/editor" - "github.com/notnmeyer/daylog-cli/internal/git" "github.com/notnmeyer/daylog-cli/internal/output-formatter" ) @@ -71,14 +70,6 @@ func (d *DayLog) Append(content string) error { return err } - if d.gitEnabled() { - msg := fmt.Sprintf("update log for %d/%d/%d\n", d.Date.Year(), int(d.Date.Month()), d.Date.Day()) - output, err := git.AddAndCommit(d.ProjectPath, d.Path, msg) - if err != nil { - return fmt.Errorf("%s: %s", err, output.Stderr.String()) - } - } - return nil } @@ -92,14 +83,6 @@ func (d *DayLog) Edit() error { return err } - if d.gitEnabled() { - msg := fmt.Sprintf("update log for %d/%d/%d\n", d.Date.Year(), int(d.Date.Month()), d.Date.Day()) - output, err := git.AddAndCommit(d.ProjectPath, d.Path, msg) - if err != nil { - return fmt.Errorf("%s: %s", err, output.Stderr.String()) - } - } - return nil } @@ -117,30 +100,6 @@ func (d *DayLog) Show(format string) (string, error) { return contents, nil } -func (d *DayLog) InitGitRepo() error { - // check if a repo exists for the project - if exists, err := git.RepoExists(d.ProjectPath); exists { - if err != nil { - return err - } - return fmt.Errorf("%s already appears to be a git repo\n", d.ProjectPath) - } - - // init a new repo - output, err := git.Init(d.ProjectPath) - if err != nil { - return fmt.Errorf("%s: %s", err, output.Stderr.String()) - } - fmt.Println(output.Stdout.String()) - - return nil -} - -func (d *DayLog) gitEnabled() bool { - exists, _ := git.RepoExists(d.ProjectPath) - return exists -} - // returns the complete path to log file func logPath(path string, year, month, day int) (string, error) { path, err := createDir( diff --git a/internal/file/file.go b/internal/file/file.go index 8ebff2b..2276df9 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -32,7 +32,7 @@ func (LogProvider) GetLogs(projectPath string) ([]string, error) { return err } - if path == projectPath || info.Name() == ".git" { + if path == projectPath { return nil } diff --git a/internal/git/git.go b/internal/git/git.go deleted file mode 100644 index 9e40784..0000000 --- a/internal/git/git.go +++ /dev/null @@ -1,88 +0,0 @@ -package git - -import ( - "bytes" - "fmt" - "os" - "os/exec" - "path/filepath" -) - -type CmdOutput struct { - Stdout bytes.Buffer - Stderr bytes.Buffer -} - -// returns true if dit contains a git repo -func RepoExists(dir string) (bool, error) { - gitDir := filepath.Join(dir, ".git") - - info, err := os.Stat(gitDir) - switch { - case os.IsNotExist(err): - return false, nil - case err != nil: - return false, err - case !info.IsDir(): - return false, fmt.Errorf("%s is not a directory\n", gitDir) - } - - return true, nil -} - -func Init(dir string) (*CmdOutput, error) { - output, err := run(dir, "init") - if err != nil { - return output, err - } - - return output, nil -} - -func Add(dir, pattern string) (*CmdOutput, error) { - output, err := run(dir, "add", pattern) - if err != nil { - return output, err - } - - return output, nil -} - -func Commit(dir, msg string) (*CmdOutput, error) { - output, err := run(dir, "commit", "-m", msg) - if err != nil { - return output, err - } - - return output, nil -} - -func AddAndCommit(dir, pattern, msg string) (*CmdOutput, error) { - output, err := Add(dir, pattern) - if err != nil { - return output, err - } - - output, err = Commit(dir, msg) - if err != nil { - return output, err - } - - return output, nil -} - -// exec a git command -func run(path string, args ...string) (*CmdOutput, error) { - args = append([]string{"-C", path}, args...) - cmd := exec.Command("git", args...) - - var output CmdOutput - cmd.Stdout = &output.Stdout - cmd.Stderr = &output.Stderr - - if err := cmd.Run(); err != nil { - return &output, err - } - - return &output, nil -}