Skip to content

Commit

Permalink
add support for manually piping in diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jan 5, 2017
1 parent 93dda0b commit e346a2c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,25 @@ git-hound [<opts>] sniff [<commit>]
```

### Commit
Sniff changes before committing.

```bash
# Scan changes since last commit and pass to git-commit when clean
git hound commit …
```

### Sniff
You can optionally pass a commit hash or manually pipe a diff for the Hound to sniff.

```bash
# Scan changes since last commit
git hound sniff HEAD

# Scan entire codebase
git hound sniff

# Sniff entire repo history
git log -p | git hound sniff
```

## Option flags
Expand Down
25 changes: 17 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"flag"
"fmt"
"github.com/fatih/color"
"io/ioutil"
"os"
"sourcegraph.com/sourcegraph/go-diff/diff"
)

var (
version = "0.6.0"
version = "0.6.1"
showVersion = flag.Bool("v", false, "Show version")
noColor = flag.Bool("no-color", false, "Disable color output")
config = flag.String("config", ".githound.yml", "Hound config file")
Expand Down Expand Up @@ -57,14 +58,22 @@ func main() {
out, _ = git.Exec("diff", "-U0", "--staged")
runnable = true
case "sniff":
commit := flag.Arg(1)
if commit == "" {
// NOTE: This let's us get a diff containing the entire history of the repo
// by utilizing a magic commit hash. In reality, it's not magical,
// it's simply the result of sha1("tree 0\0").
commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
stat, _ := os.Stdin.Stat()

// Check if anything was piped to STDIN
if (stat.Mode() & os.ModeCharDevice) == 0 {
stdin, _ := ioutil.ReadAll(os.Stdin)
out = string(stdin)
} else {
commit := flag.Arg(1)
if commit == "" {
// NOTE: This let's us get a diff containing the entire repo codebase by
// utilizing a magic commit hash. In reality, it's not magical,
// it's simply the result of sha1("tree 0\0").
commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
}
out, _ = git.Exec("diff", commit, "--staged")
}
out, _ = git.Exec("diff", commit, "--staged")
default:
fmt.Print("Usage:\n git-hound commit [...]\n git-hound sniff [commit]\n")
os.Exit(0)
Expand Down

0 comments on commit e346a2c

Please sign in to comment.