File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,11 @@ func setGitConf(hookDir string, isGlobal bool) error {
64
64
}
65
65
66
66
func getCommitMsg (fileInput string ) (string , error ) {
67
- commitMsg := readStdIn ()
67
+ commitMsg , err := readStdInPipe ()
68
+ if err != nil {
69
+ return "" , err
70
+ }
71
+
68
72
if commitMsg != "" {
69
73
return commitMsg , nil
70
74
}
@@ -81,12 +85,23 @@ func getCommitMsg(fileInput string) (string, error) {
81
85
return string (inBytes ), nil
82
86
}
83
87
84
- func readStdIn () string {
88
+ func readStdInPipe () (string , error ) {
89
+ stat , err := os .Stdin .Stat ()
90
+ if err != nil {
91
+ return "" , err
92
+ }
93
+
94
+ // user input from terminal
95
+ if (stat .Mode () & os .ModeCharDevice ) != 0 {
96
+ // not handling this case
97
+ return "" , nil
98
+ }
99
+
100
+ // user input from stdin pipe
85
101
readBytes , err := io .ReadAll (os .Stdin )
86
102
if err != nil {
87
- // TODO: handle error?
88
- return ""
103
+ return "" , err
89
104
}
90
105
s := string (readBytes )
91
- return strings .TrimSpace (s )
106
+ return strings .TrimSpace (s ), nil
92
107
}
You can’t perform that action at this time.
0 commit comments