Skip to content

Commit e346a2c

Browse files
committed
add support for manually piping in diffs
1 parent 93dda0b commit e346a2c

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,25 @@ git-hound [<opts>] sniff [<commit>]
3333
```
3434

3535
### Commit
36+
Sniff changes before committing.
37+
3638
```bash
3739
# Scan changes since last commit and pass to git-commit when clean
3840
git hound commit …
3941
```
4042

4143
### Sniff
44+
You can optionally pass a commit hash or manually pipe a diff for the Hound to sniff.
45+
4246
```bash
4347
# Scan changes since last commit
4448
git hound sniff HEAD
4549

4650
# Scan entire codebase
4751
git hound sniff
52+
53+
# Sniff entire repo history
54+
git log -p | git hound sniff
4855
```
4956

5057
## Option flags

main.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import (
88
"flag"
99
"fmt"
1010
"github.com/fatih/color"
11+
"io/ioutil"
1112
"os"
1213
"sourcegraph.com/sourcegraph/go-diff/diff"
1314
)
1415

1516
var (
16-
version = "0.6.0"
17+
version = "0.6.1"
1718
showVersion = flag.Bool("v", false, "Show version")
1819
noColor = flag.Bool("no-color", false, "Disable color output")
1920
config = flag.String("config", ".githound.yml", "Hound config file")
@@ -57,14 +58,22 @@ func main() {
5758
out, _ = git.Exec("diff", "-U0", "--staged")
5859
runnable = true
5960
case "sniff":
60-
commit := flag.Arg(1)
61-
if commit == "" {
62-
// NOTE: This let's us get a diff containing the entire history of the repo
63-
// by utilizing a magic commit hash. In reality, it's not magical,
64-
// it's simply the result of sha1("tree 0\0").
65-
commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
61+
stat, _ := os.Stdin.Stat()
62+
63+
// Check if anything was piped to STDIN
64+
if (stat.Mode() & os.ModeCharDevice) == 0 {
65+
stdin, _ := ioutil.ReadAll(os.Stdin)
66+
out = string(stdin)
67+
} else {
68+
commit := flag.Arg(1)
69+
if commit == "" {
70+
// NOTE: This let's us get a diff containing the entire repo codebase by
71+
// utilizing a magic commit hash. In reality, it's not magical,
72+
// it's simply the result of sha1("tree 0\0").
73+
commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
74+
}
75+
out, _ = git.Exec("diff", commit, "--staged")
6676
}
67-
out, _ = git.Exec("diff", commit, "--staged")
6877
default:
6978
fmt.Print("Usage:\n git-hound commit [...]\n git-hound sniff [commit]\n")
7079
os.Exit(0)

0 commit comments

Comments
 (0)