(dirtyMsg string)
| 123 | } |
| 124 | |
| 125 | func cleanupMsg(dirtyMsg string) string { |
| 126 | // commit msg cleanup in git is configurable: https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---cleanupltmodegt |
| 127 | // For now we do a combination of the "scissors" behavior and the "strip" behavior |
| 128 | // * remove the scissors line and everything below |
| 129 | // * strip leading and trailing empty lines |
| 130 | // * strip commentary (lines stating with commentChar '#') |
| 131 | // * strip trailing whitespace |
| 132 | // * collapse consecutive empty lines |
| 133 | // TODO: check via "git config --get" if any of those two hardcoded constants was reconfigured |
| 134 | // TODO: find out if commit messages on windows actually |
| 135 | |
| 136 | gitCommentChar := "#" |
| 137 | scissors := gitCommentChar + " ------------------------ >8 ------------------------" |
| 138 | |
| 139 | cleanMsg := "" |
| 140 | lastLine := "" |
| 141 | for _, line := range strings.Split(dirtyMsg, "\n") { |
| 142 | if line == scissors { |
| 143 | // remove everything below scissors (including the scissors line) |
| 144 | break |
| 145 | } |
| 146 | if strings.HasPrefix(line, gitCommentChar) { |
| 147 | // strip commentary |
| 148 | continue |
| 149 | } |
| 150 | line = trimRightSpace(line) |
| 151 | // strip trailing whitespace |
| 152 | if lastLine == "" && line == "" { |
| 153 | // strip leading empty lines |
| 154 | // collapse consecutive empty lines |
| 155 | continue |
| 156 | } |
| 157 | if cleanMsg == "" { |
| 158 | cleanMsg = line |
| 159 | } else { |
| 160 | cleanMsg += "\n" + line |
| 161 | } |
| 162 | lastLine = line |
| 163 | } |
| 164 | if lastLine == "" { |
| 165 | // strip trailing empty line |
| 166 | cleanMsg = strings.TrimSuffix(cleanMsg, "\n") |
| 167 | } |
| 168 | return cleanMsg |
| 169 | } |
| 170 | |
| 171 | func readStdInPipe() (string, error) { |
| 172 | stat, err := os.Stdin.Stat() |
no test coverage detected