@@ -8,12 +8,13 @@ import (
8
8
"flag"
9
9
"fmt"
10
10
"github.com/fatih/color"
11
+ "io/ioutil"
11
12
"os"
12
13
"sourcegraph.com/sourcegraph/go-diff/diff"
13
14
)
14
15
15
16
var (
16
- version = "0.6.0 "
17
+ version = "0.6.1 "
17
18
showVersion = flag .Bool ("v" , false , "Show version" )
18
19
noColor = flag .Bool ("no-color" , false , "Disable color output" )
19
20
config = flag .String ("config" , ".githound.yml" , "Hound config file" )
@@ -57,14 +58,22 @@ func main() {
57
58
out , _ = git .Exec ("diff" , "-U0" , "--staged" )
58
59
runnable = true
59
60
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" )
66
76
}
67
- out , _ = git .Exec ("diff" , commit , "--staged" )
68
77
default :
69
78
fmt .Print ("Usage:\n git-hound commit [...]\n git-hound sniff [commit]\n " )
70
79
os .Exit (0 )
0 commit comments