Skip to content

Commit c970c5e

Browse files
authored
License Checker: Don't check out the override branch if its the same … (#44)
1 parent 578bf92 commit c970c5e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

internal/repo/license.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package repo
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"log"
78
"os"
@@ -66,11 +67,21 @@ func (c *Content) UpdateLicense(repoName string, cfg *config.Config) error {
6667
log.Printf("Error loading config for %s: %v\n", repoName, err)
6768
}
6869

70+
headRef, err := r.Head()
71+
if err != nil {
72+
return fmt.Errorf("error getting head ref for %s: %w", repoName, err)
73+
}
74+
headRefName := headRef.Name()
75+
if !headRefName.IsBranch() {
76+
return errors.New("HEAD ref is not a branch")
77+
}
78+
defaultBranch := headRefName.Short()
79+
6980
// If we are targeting a different branch with PRs, then our base also needs to start from that branch
70-
if repoConfig.PrTargetBranch != nil {
81+
if repoConfig.PrTargetBranch != nil && *repoConfig.PrTargetBranch != defaultBranch {
7182
err = c.checkoutBranch(r, w, *repoConfig.PrTargetBranch)
7283
if err != nil {
73-
return err
84+
return fmt.Errorf("error checking out branch %s: %w", *repoConfig.PrTargetBranch, err)
7485
}
7586
}
7687

0 commit comments

Comments
 (0)