Skip to content

Commit d042e3f

Browse files
committed
fix goDiff zero case
1 parent dcbf3d9 commit d042e3f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

cmd/diff-cov/diff-cov.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424

2525
func fetch() error {
2626
out, err := exec.Command(
27-
"git", "fetch", "--all",
27+
"git", "fetch", "origin", "master:refs/remotes/origin/master",
2828
).CombinedOutput()
2929
if err != nil {
3030
fmt.Println(string(out))
@@ -42,11 +42,11 @@ func diff() ([]byte, error) {
4242
_ = f.Close()
4343

4444
output := fmt.Sprintf("--output=%s", f.Name())
45-
45+
target := fmt.Sprintf("%s..HEAD", flagTargetBranch)
4646
out, err := exec.Command(
4747
"git", "diff",
4848
"--ignore-all-space", "--ignore-blank-lines",
49-
"--no-color", "--no-ext-diff", "-U0", output, flagTargetBranch,
49+
"--no-color", "--no-ext-diff", "-U0", output, target,
5050
).CombinedOutput()
5151
if err != nil {
5252
fmt.Println(string(out))
@@ -183,7 +183,10 @@ func main() {
183183
}
184184
}
185185
}
186-
difCov := float64(goTestedDiff) / float64(goDiff) * 100
186+
difCov := 0.0
187+
if goDiff > 0 {
188+
difCov = float64(goTestedDiff) / float64(goDiff) * 100
189+
}
187190
fmt.Printf("%d/%d = %.2f%%\n", goTestedDiff, goDiff, difCov)
188191
if goDiff > flagMinimumLine && difCov < flagMinimumCov {
189192
os.Exit(1)

0 commit comments

Comments
 (0)