Skip to content

Commit

Permalink
fix(cli): abort if no files staged
Browse files Browse the repository at this point in the history
  • Loading branch information
SKalt committed Nov 11, 2020
1 parent 3ec2b00 commit 242498c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
13 changes: 13 additions & 0 deletions cmd/cli.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"bytes"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -64,6 +65,18 @@ func mainMode(cmd *cobra.Command, args []string) {
cfg := config.Lookup(config.Init())
commitParams := getGitCommitCmd(cmd)
dryRun, _ := cmd.Flags().GetBool("dry-run")
if !dryRun {
buf := &bytes.Buffer{}
process := exec.Command("git", "diff", "--name-only", "--cached")
process.Stdout = buf
err := process.Run()
if err != nil {
log.Fatal(err)
}
if buf.String() == "" {
log.Fatal("No files staged")
}
}

cc := &parser.CC{}
message, _ := cmd.Flags().GetString("message")
Expand Down
13 changes: 9 additions & 4 deletions pkg/config/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ func getGitVar(var_name string) (string, error) {
}
}

func GetEditor() string {
editor := os.Getenv("EDITOR")
if editor != "" {
return editor
}
return "vi"
}

// search GIT_EDITOR, then fall back to $EDITOR
func GetGitEditor() string {
editor, err := getGitVar("GIT_EDITOR") // TODO: shell-split the string
if err != nil {
editor = os.Getenv("EDITOR")
if editor == "" {
log.Fatal(fmt.Errorf("unable to look up `git var GIT_EDITOR` or `$EDITOR`"))
}
return GetEditor()
}
return editor
}
Expand Down

0 comments on commit 242498c

Please # to comment.